Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from binance.client import Client
  2. from time import sleep
  3. import csv
  4. client = Client('HnvnieJ3pett4jvv0Xag3K7wn3UlHhjHtWJrKAtOGa7CHkohk5w4JvChPsej5A92', '7JOHLUiltxt1fd4gdjMFQzvOT2bFSHgbJqKiQP4kwGIC3Ex0sNlx0WIvwKOeqwg6')
  5.  
  6. coinprice = 0 #get the current price from the API
  7. setprice = 0 #init the setprice
  8. usd = 0 #init wallet
  9. coins = 1 #init coint start amount
  10. sold = 0 # flag to indicate if coins are bought or sold
  11. pers = float(1)  # the % used to set the setprice val
  12.  
  13. # get starting prices
  14. ticket_at_current_moment = client.get_orderbook_ticker(symbol='ETHUSDT')
  15. coinprice = (float(ticket_at_current_moment['bidPrice']) + float(ticket_at_current_moment['askPrice'])) / 2
  16. setprice = coinprice - (coinprice / 100) * (pers / 2)
  17.  
  18.  
  19. # declare array for each price
  20. export_array = [[round(coinprice,8),round(setprice,8)]]
  21.  
  22. while(1):
  23.     sleep(0.05)
  24.    
  25.     ticket_at_current_moment = client.get_orderbook_ticker(symbol='ETHUSDT')
  26.     coinprice = (float(ticket_at_current_moment['bidPrice']) + float(ticket_at_current_moment['askPrice'])) / 2
  27.    
  28.     print(coinprice)
  29.    
  30.     if setprice > coinprice :
  31.         if setprice - coinprice > (setprice/100)*pers :
  32.             setprice = setprice - (setprice/100)*(pers/2)
  33.             print('DROP IN SET PRICE')
  34.            
  35.     if setprice < coinprice :
  36.         if coinprice - setprice > (coinprice/100) * pers :
  37.             setprice = coinprice - (coinprice/100) * (pers/2)
  38.             print('INCREASE SET PRICE')
  39.            
  40.     print(setprice)
  41.     export_array.append([round(coinprice,8),round(setprice,8)])
  42.    
  43.     if coinprice < setprice and sold == 0 :
  44.         sold = 1
  45.         usd = coins*coinprice
  46.         coins = 0
  47.         print('SOLD AT %f' % (coinprice))
  48.    
  49.    
  50.     if coinprice > setprice and sold == 1 :   #buy back
  51.         sold = 0
  52.         coins = usd/coinprice
  53.         usd = 0
  54.         print('BOUGHT AT %f' % (coinprice))
  55.  
  56.     print('BALANCE COINS: %f AND USD: %f' % (coins, usd))
  57.     print('-----------------')
  58.    
  59.     if len(export_array) > 500 :
  60.         break
  61.  
  62.        
  63. with open("export.csv", "wb") as file:
  64.     writer = csv.writer(file)
  65.     writer.writerows(export_array)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement