我有以下代码来检查Binance Exchange中的比特币价格走势:
import keys
import datetime
from time import sleep
from binance.client import Client
import certifi
import urllib3
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
client = Client(keys.APIKey, keys.SecretKey)
# client = Client(keys.APIKey, keys.SecretKey, {"verify": True, "timeout": 20})
# client.get_all_orders(symbol='BTCUSDT', requests_params={'timeout': 5})
symbol= 'BTCUSDT'
quantity= '0.003'
order= False
while order==False:
BTC= client.get_historical_klines(symbol=symbol, interval='30m',
start_str="1 hour ago UTC")
if (float(BTC[-1][4])-float(BTC[-2][4]))>500:
print ('Buyyy')
client.order_market_buy(symbol= symbol, quantity= quantity)
order= True
elif (float(BTC[-1][4])-float(BTC[-2][4]))<-500:
print ('Sellll')
client.order_market_buy(symbol= symbol , quantity= quantity)
order= True
else:
print ('Do nothing')
sleep(10)
但是我收到此错误消息:
文件“ xxx \ trading.py”,第30行,在 如果len(float(BTC [-1] [4])-float(BTC [-2] [4]))> 500:
IndexError:列表索引超出范围
我不明白如何检查两个时间段($ 500)之间的波动会返回此错误?
在这种情况下,我也看不到如何使用len()。
答案 0 :(得分:0)
找到了,谢谢@benja d!
我不得不改变:
start_str="1 hour ago UTC")
到
start_str="1 day ago UTC")