I'd like to get my code to print/notify when the price is low and have the statement print once unless it reaches the higher range again. Then I want it to print when it is low again.
If it is very low, I want it to print that it is very low and have this only occur once unless if it reaches the higher range. Then I want it to print again when it is very low.
import requests
import json
import time
buybtc = range(37000, 40000)
sellbtc = range(45000, 50000)
def btc_function():
url = 'https://api.gdax.com/products/BTC-USD/trades'
res = requests.get(url)
json_res = json.loads(res.text)
price = int(float(json_res[0]['price']) // 1) # Convert from str to float to int (to match the range value)
print('---------------------')
print('bitcoin = ', price)
print('actual = ', json_res[0]['price'])
print(' ')
if price in buybtc:
print('Low')
print('---------------------')
print(' ')
#print buy coin here (only print this statement once!)
elif price in sellbtc:
print('Too High!')
print('---------------------')
print(' ')
#print Do not buy more until low (only print this statement once until it reaches low again!)
else:
if int(float(json_res[0]['price']) // 1) < 37000:
print('Lower than low')
#print Buy more here! (will only buy more once until it reaches high price, then it will
print this again)
else:
print('Awaiting... ')
print('---------------------')
print(' ')
while True:
btc_function()
time.sleep(5)
I'm assuming a for loop or while loop is needed?
Aucun commentaire:
Enregistrer un commentaire