Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import ccxt
- import RPi.GPIO as GPIO
- exchange = ccxt.binance({
- 'apiKey': '',
- 'secret': '',
- 'enableRateLimit': True,
- })
- def inizializza():
- exchange.load_markets()
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(31, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(33, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(35, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- def cento_dollari_di(cosa):
- return str(round(10/float(exchange.fetchTicker(cosa+'/USDT')['last']),6))
- def compra(cosa,quanto):
- print("Starei comprando " + cosa + '/USDT')
- try:
- exchange.createMarketBuyOrder(cosa+'/USDT', quanto)
- except:
- print("errore")
- def vendi(cosa,quanto):
- print("Starei vendendo " + cosa + '/USDT')
- try:
- exchange.createMarketSellOrder(cosa+'/USDT', quanto)
- inizializza()
- while True:
- if GPIO.input(31) == GPIO.LOW:
- compra('BTC', cento_dollari_di('BTC'))
- time.sleep(0.1)
- while GPIO.input(31) == GPIO.LOW:
- time.sleep(0.1)
- time.sleep(0.5)
- if GPIO.input(33) == GPIO.LOW:
- compra('ETH', cento_dollari_di('ETH'))
- time.sleep(0.1)
- while GPIO.input(33) == GPIO.LOW:
- time.sleep(0.1)
- time.sleep(0.5)
- if GPIO.input(35) == GPIO.LOW:
- vendi('BTC', cento_dollari_di('BTC'))
- time.sleep(0.1)
- while GPIO.input(35) == GPIO.LOW:
- time.sleep(0.1)
- time.sleep(0.5)
- if GPIO.input(37) == GPIO.LOW:
- vendi('ETH', cento_dollari_di('ETH'))
- time.sleep(0.1)
- while GPIO.input(37) == GPIO.LOW:
- time.sleep(0.1)
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement