Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. Traceback (most recent call last):
  2. File "C:Python34yobit_update.py", line 168, in <module>
  3. main()
  4. File "C:Python34yobit_update.py", line 159, in main
  5. datas = pairFinder(table)
  6. File "C:Python34yobit_update.py", line 62, in pairFinder
  7. tickerInfo(key)
  8. File "C:Python34yobit_update.py", line 85, in tickerInfo
  9. data = response.json()
  10. File "C:Python34libsite-packagesrequestsmodels.py", line 894, in json
  11. return complexjson.loads(self.text, **kwargs)
  12. File "C:Python34libjson__init__.py", line 318, in loads
  13. return _default_decoder.decode(s)
  14. File "C:Python34libjsondecoder.py", line 343, in decode
  15. obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  16. File "C:Python34libjsondecoder.py", line 361, in raw_decode
  17. raise ValueError(errmsg("Expecting value", s, err.value)) from None
  18. ValueError: Expecting value: line 1 column 1 (char 0)
  19.  
  20. #pip install xlsxwriter
  21. #pip install prettytable
  22. #pip install requests
  23. import xlsxwriter
  24. from prettytable import PrettyTable
  25. from requests import get
  26.  
  27.  
  28. pair = ''
  29. last = 0
  30. highestBid = 0
  31. lowestAsk = 0
  32. volume24H = 0
  33. smallPChange = 0
  34. largePChange = 0
  35. smalltolargePChange = 0
  36. smallAsk = 0
  37. largeAsk = 0
  38. smallBuy = 0
  39. largeBuy = 0
  40. myBuy = 0
  41. myPChange= 0
  42. myAsk = 0
  43.  
  44. def fileSaving(datas):
  45. # Creates the xlsx file
  46. workbook = xlsxwriter.Workbook('cryptoInfo.xlsx')
  47. worksheet = workbook.add_worksheet()
  48.  
  49. # Creates the headers on file
  50. headers = {'Pair':'A1', 'Last':'B1', 'Bid':'C1', 'Ask':'D1', 'Volume':'E1', 'My Buy':'F1', 'My Ask':'G1', 'My % Increase':'H1', 'Small Buy':'I1', 'Small Ask':'J1',
  51. 'Small % Inc':'K1', 'Large Buy':'L1', 'Large Ask':'M1', 'Large % Inc':'N1', 'Small to Large % Inc':'O1'}
  52. bold = workbook.add_format({'bold':True})
  53. for header in headers.keys():
  54. worksheet.write(headers[header], header, bold)
  55.  
  56. # Adds the data to the file
  57. for row in range(1, len(datas) -1):
  58. for col in range(0,15):
  59. worksheet.write(row, col, datas[row][col])
  60.  
  61. workbook.close()
  62.  
  63. def pairFinder(table):
  64. datas = []
  65. # Requests data from Yobit's API
  66. response = get('https://yobit.net/api/3/info')
  67. data = response.json()
  68.  
  69. # Iterates through the data for the pair names
  70. print('Gathering Data For All: ' + str(len(data['pairs'].keys())) + ' Pairs.'
  71. + ' Please Wait A Moment..')
  72. i = 0
  73. for key in data['pairs'].keys():
  74. # Comment print below if you dont want screen spamming with this info
  75. base = key.split('_')
  76. if base[1] == 'btc':
  77. print('Gathering Data Of: ' + key)
  78.  
  79. # Gets pair name and sends it through to get searched.
  80. # Then stores it in variable and creates a table from the data
  81. tickerInfo(key)
  82. depthInfo(key)
  83.  
  84. # Adds a row to the screen table
  85. data = [key, last, highestBid, lowestAsk, volume24H, myBuy, myAsk, myPChange, smallBuy, smallAsk,
  86. smallPChange, largeBuy, largeAsk, largePChange, smalltolargePChange]
  87. datas.append(data)
  88.  
  89. # Expands the standard form
  90. for value in range(1, len(data) -1):
  91. if 'e' in str(data[value]):
  92. data[value] = '{0:.8f}'.format(data[value])
  93.  
  94. table.add_row(data)
  95. return datas
  96.  
  97.  
  98. def tickerInfo(pair):
  99. # Creates local variables
  100. global volume24H, last, highestBid, lowestAsk
  101.  
  102. # Requests data from Yobit's API
  103. response = get('https://yobit.net/api/3/ticker/' + pair)
  104. data = response.json()
  105.  
  106. # Assigns wanted data to its variables
  107. volume24H = data[pair]['vol']
  108. last = data[pair]['last']
  109. highestBid = data[pair]['buy']
  110. lowestAsk = data[pair]['sell']
  111.  
  112. def depthInfo(pair):
  113. global myBuy, myAsk, myPChange, smallAsk, largeAsk, smallPChange, largePChange, smalltolargePChange, smallBuy, largeBuy, lowestAsk
  114.  
  115. # Requests data from Yobit's API
  116. response = get('https://yobit.net/api/3/depth/' + pair)
  117. data = response.json()
  118.  
  119. # Assigns wanted data to its variables
  120. try:
  121. myBuy = 0.005
  122. smallBuy = 0.05
  123. largeBuy = 0.15
  124.  
  125. # Sets the Ask price
  126. y = 0
  127. for x in range(0, len(data[pair]['asks']) -1):
  128. y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
  129. if y >= myBuy:
  130. myAsk = data[pair]['asks'][x][0]
  131. break
  132. y = 0
  133. for x in range(0, len(data[pair]['asks']) -1):
  134. y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
  135. if y >= smallBuy:
  136. smallAsk = data[pair]['asks'][x][0]
  137. break
  138. y = 0
  139. for x in range(0, len(data[pair]['asks']) -1):
  140. y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
  141. if y >= largeBuy:
  142. largeAsk = data[pair]['asks'][x][0]
  143. break
  144.  
  145. # Sets the percentage change from inital asking price, (((new - old)/old) * 100)
  146. myPChange = ((myAsk - lowestAsk) / lowestAsk) * 100
  147. smallPChange = ((smallAsk - lowestAsk) / lowestAsk) * 100
  148. largePChange = ((largeAsk - lowestAsk) / lowestAsk) * 100
  149. smalltolargePChange = ((largeAsk - smallAsk) / smallAsk) * 100
  150. print(smalltolargePChange)
  151.  
  152.  
  153.  
  154. # Change random_pair! to a pair you want to alter/change
  155. #if pair == 'random_pair!':
  156. # Add the code you want,
  157. # smallBuy = (data[pair]['bids'][0][0] * YOUR EDIT VALUE)
  158. # smallBuy = VALUE
  159.  
  160. # largeBuy = (data[pair]['bids'][(len(data[pair]['bids']) - 1)][0] *
  161. # YOUR VALUE)
  162. # largeBuy = VALUE
  163.  
  164. # If you want to change multiple values of different pairs just copy the
  165. # if statement again and change random_pair to the other pair
  166. #smallBuy = 0.12
  167. #largeBuy = 0.22
  168. except:
  169. pass
  170.  
  171. def main():
  172. # Creates table headers
  173. table = PrettyTable(['Pairs', 'Last', 'Bid', 'Ask', 'Volume', 'My Buy',
  174. 'My Ask', 'My % Inc', 'Small Buy',
  175. 'Small Ask', 'Small % Inc', 'Large Buy', 'Large Ask',
  176. 'Large % Inc', 'Small to Large % Inc'])
  177. # Starts the data gathering
  178. datas = pairFinder(table)
  179. print(table)
  180.  
  181. ans = input("Would you like to save this file?")
  182. if 'yes' == ans.lower() or 'y' == ans.lower():
  183. fileSaving(datas)
  184.  
  185.  
  186. if __name__ == '__main__':
  187. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement