Advertisement
overvolt

Cabinato trading x Molteni - modalità spot

Dec 6th, 2021
2,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. import time
  2. import ccxt
  3. import RPi.GPIO as GPIO
  4.  
  5.  
  6. exchange = ccxt.binance({
  7.         'apiKey': '',
  8.         'secret': '',
  9.         'enableRateLimit': True,
  10. })
  11.  
  12. def inizializza():
  13.     exchange.load_markets()
  14.     GPIO.setwarnings(False)
  15.     GPIO.setmode(GPIO.BOARD)
  16.     GPIO.setup(31, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  17.     GPIO.setup(33, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  18.     GPIO.setup(35, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  19.     GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  20.  
  21.  
  22. def cento_dollari_di(cosa):
  23.     return str(round(10/float(exchange.fetchTicker(cosa+'/USDT')['last']),6))
  24.  
  25.  
  26. def compra(cosa,quanto):
  27.     print("Starei comprando " + cosa + '/USDT')
  28.     try:
  29.         exchange.createMarketBuyOrder(cosa+'/USDT', quanto)
  30.     except:
  31.         print("errore")
  32.  
  33. def vendi(cosa,quanto):
  34.     print("Starei vendendo " + cosa + '/USDT')
  35.     try:
  36.         exchange.createMarketSellOrder(cosa+'/USDT', quanto)
  37.  
  38.  
  39.  
  40. inizializza()
  41.  
  42. while True:
  43.     if GPIO.input(31) == GPIO.LOW:
  44.         compra('BTC', cento_dollari_di('BTC'))
  45.         time.sleep(0.1)
  46.         while GPIO.input(31) == GPIO.LOW:
  47.             time.sleep(0.1)
  48.         time.sleep(0.5)
  49.    
  50.     if GPIO.input(33) == GPIO.LOW:
  51.         compra('ETH', cento_dollari_di('ETH'))
  52.         time.sleep(0.1)
  53.         while GPIO.input(33) == GPIO.LOW:
  54.             time.sleep(0.1)
  55.         time.sleep(0.5)
  56.    
  57.     if GPIO.input(35) == GPIO.LOW:
  58.         vendi('BTC', cento_dollari_di('BTC'))
  59.         time.sleep(0.1)
  60.         while GPIO.input(35) == GPIO.LOW:
  61.             time.sleep(0.1)
  62.         time.sleep(0.5)
  63.    
  64.     if GPIO.input(37) == GPIO.LOW:
  65.         vendi('ETH', cento_dollari_di('ETH'))
  66.         time.sleep(0.1)
  67.         while GPIO.input(37) == GPIO.LOW:
  68.             time.sleep(0.1)
  69.     time.sleep(0.5)
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement