Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Traceback (most recent call last):
- File "C:Python34yobit_update.py", line 168, in <module>
- main()
- File "C:Python34yobit_update.py", line 159, in main
- datas = pairFinder(table)
- File "C:Python34yobit_update.py", line 62, in pairFinder
- tickerInfo(key)
- File "C:Python34yobit_update.py", line 85, in tickerInfo
- data = response.json()
- File "C:Python34libsite-packagesrequestsmodels.py", line 894, in json
- return complexjson.loads(self.text, **kwargs)
- File "C:Python34libjson__init__.py", line 318, in loads
- return _default_decoder.decode(s)
- File "C:Python34libjsondecoder.py", line 343, in decode
- obj, end = self.raw_decode(s, idx=_w(s, 0).end())
- File "C:Python34libjsondecoder.py", line 361, in raw_decode
- raise ValueError(errmsg("Expecting value", s, err.value)) from None
- ValueError: Expecting value: line 1 column 1 (char 0)
- #pip install xlsxwriter
- #pip install prettytable
- #pip install requests
- import xlsxwriter
- from prettytable import PrettyTable
- from requests import get
- pair = ''
- last = 0
- highestBid = 0
- lowestAsk = 0
- volume24H = 0
- smallPChange = 0
- largePChange = 0
- smalltolargePChange = 0
- smallAsk = 0
- largeAsk = 0
- smallBuy = 0
- largeBuy = 0
- myBuy = 0
- myPChange= 0
- myAsk = 0
- def fileSaving(datas):
- # Creates the xlsx file
- workbook = xlsxwriter.Workbook('cryptoInfo.xlsx')
- worksheet = workbook.add_worksheet()
- # Creates the headers on file
- 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',
- 'Small % Inc':'K1', 'Large Buy':'L1', 'Large Ask':'M1', 'Large % Inc':'N1', 'Small to Large % Inc':'O1'}
- bold = workbook.add_format({'bold':True})
- for header in headers.keys():
- worksheet.write(headers[header], header, bold)
- # Adds the data to the file
- for row in range(1, len(datas) -1):
- for col in range(0,15):
- worksheet.write(row, col, datas[row][col])
- workbook.close()
- def pairFinder(table):
- datas = []
- # Requests data from Yobit's API
- response = get('https://yobit.net/api/3/info')
- data = response.json()
- # Iterates through the data for the pair names
- print('Gathering Data For All: ' + str(len(data['pairs'].keys())) + ' Pairs.'
- + ' Please Wait A Moment..')
- i = 0
- for key in data['pairs'].keys():
- # Comment print below if you dont want screen spamming with this info
- base = key.split('_')
- if base[1] == 'btc':
- print('Gathering Data Of: ' + key)
- # Gets pair name and sends it through to get searched.
- # Then stores it in variable and creates a table from the data
- tickerInfo(key)
- depthInfo(key)
- # Adds a row to the screen table
- data = [key, last, highestBid, lowestAsk, volume24H, myBuy, myAsk, myPChange, smallBuy, smallAsk,
- smallPChange, largeBuy, largeAsk, largePChange, smalltolargePChange]
- datas.append(data)
- # Expands the standard form
- for value in range(1, len(data) -1):
- if 'e' in str(data[value]):
- data[value] = '{0:.8f}'.format(data[value])
- table.add_row(data)
- return datas
- def tickerInfo(pair):
- # Creates local variables
- global volume24H, last, highestBid, lowestAsk
- # Requests data from Yobit's API
- response = get('https://yobit.net/api/3/ticker/' + pair)
- data = response.json()
- # Assigns wanted data to its variables
- volume24H = data[pair]['vol']
- last = data[pair]['last']
- highestBid = data[pair]['buy']
- lowestAsk = data[pair]['sell']
- def depthInfo(pair):
- global myBuy, myAsk, myPChange, smallAsk, largeAsk, smallPChange, largePChange, smalltolargePChange, smallBuy, largeBuy, lowestAsk
- # Requests data from Yobit's API
- response = get('https://yobit.net/api/3/depth/' + pair)
- data = response.json()
- # Assigns wanted data to its variables
- try:
- myBuy = 0.005
- smallBuy = 0.05
- largeBuy = 0.15
- # Sets the Ask price
- y = 0
- for x in range(0, len(data[pair]['asks']) -1):
- y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
- if y >= myBuy:
- myAsk = data[pair]['asks'][x][0]
- break
- y = 0
- for x in range(0, len(data[pair]['asks']) -1):
- y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
- if y >= smallBuy:
- smallAsk = data[pair]['asks'][x][0]
- break
- y = 0
- for x in range(0, len(data[pair]['asks']) -1):
- y = y + (data[pair]['asks'][x][0] * data[pair]['asks'][x][1])
- if y >= largeBuy:
- largeAsk = data[pair]['asks'][x][0]
- break
- # Sets the percentage change from inital asking price, (((new - old)/old) * 100)
- myPChange = ((myAsk - lowestAsk) / lowestAsk) * 100
- smallPChange = ((smallAsk - lowestAsk) / lowestAsk) * 100
- largePChange = ((largeAsk - lowestAsk) / lowestAsk) * 100
- smalltolargePChange = ((largeAsk - smallAsk) / smallAsk) * 100
- print(smalltolargePChange)
- # Change random_pair! to a pair you want to alter/change
- #if pair == 'random_pair!':
- # Add the code you want,
- # smallBuy = (data[pair]['bids'][0][0] * YOUR EDIT VALUE)
- # smallBuy = VALUE
- # largeBuy = (data[pair]['bids'][(len(data[pair]['bids']) - 1)][0] *
- # YOUR VALUE)
- # largeBuy = VALUE
- # If you want to change multiple values of different pairs just copy the
- # if statement again and change random_pair to the other pair
- #smallBuy = 0.12
- #largeBuy = 0.22
- except:
- pass
- def main():
- # Creates table headers
- table = PrettyTable(['Pairs', 'Last', 'Bid', 'Ask', 'Volume', 'My Buy',
- 'My Ask', 'My % Inc', 'Small Buy',
- 'Small Ask', 'Small % Inc', 'Large Buy', 'Large Ask',
- 'Large % Inc', 'Small to Large % Inc'])
- # Starts the data gathering
- datas = pairFinder(table)
- print(table)
- ans = input("Would you like to save this file?")
- if 'yes' == ans.lower() or 'y' == ans.lower():
- fileSaving(datas)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement