Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binance.client import Client
- from time import sleep
- import csv
- client = Client('HnvnieJ3pett4jvv0Xag3K7wn3UlHhjHtWJrKAtOGa7CHkohk5w4JvChPsej5A92', '7JOHLUiltxt1fd4gdjMFQzvOT2bFSHgbJqKiQP4kwGIC3Ex0sNlx0WIvwKOeqwg6')
- coinprice = 0 #get the current price from the API
- setprice = 0 #init the setprice
- usd = 0 #init wallet
- coins = 1 #init coint start amount
- sold = 0 # flag to indicate if coins are bought or sold
- pers = float(1) # the % used to set the setprice val
- # get starting prices
- ticket_at_current_moment = client.get_orderbook_ticker(symbol='ETHUSDT')
- coinprice = (float(ticket_at_current_moment['bidPrice']) + float(ticket_at_current_moment['askPrice'])) / 2
- setprice = coinprice - (coinprice / 100) * (pers / 2)
- # declare array for each price
- export_array = [[round(coinprice,8),round(setprice,8)]]
- while(1):
- sleep(0.05)
- ticket_at_current_moment = client.get_orderbook_ticker(symbol='ETHUSDT')
- coinprice = (float(ticket_at_current_moment['bidPrice']) + float(ticket_at_current_moment['askPrice'])) / 2
- print(coinprice)
- if setprice > coinprice :
- if setprice - coinprice > (setprice/100)*pers :
- setprice = setprice - (setprice/100)*(pers/2)
- print('DROP IN SET PRICE')
- if setprice < coinprice :
- if coinprice - setprice > (coinprice/100) * pers :
- setprice = coinprice - (coinprice/100) * (pers/2)
- print('INCREASE SET PRICE')
- print(setprice)
- export_array.append([round(coinprice,8),round(setprice,8)])
- if coinprice < setprice and sold == 0 :
- sold = 1
- usd = coins*coinprice
- coins = 0
- print('SOLD AT %f' % (coinprice))
- if coinprice > setprice and sold == 1 : #buy back
- sold = 0
- coins = usd/coinprice
- usd = 0
- print('BOUGHT AT %f' % (coinprice))
- print('BALANCE COINS: %f AND USD: %f' % (coins, usd))
- print('-----------------')
- if len(export_array) > 500 :
- break
- with open("export.csv", "wb") as file:
- writer = csv.writer(file)
- writer.writerows(export_array)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement