[英]How to check the order status of a binance order properly
我正在尝试创建一个卖单,然后不断检查它是否已被履行,但在循环中的一两次迭代之后,它显示订单状态为已履行,而订单实际上尚未履行,或者有时它说订单不存在。
我的代码有什么问题还是有更好的方法?
# SELL
try:
#LIMITSELL
client.order_limit_sell(symbol=pair,quantity=quantity,price=sellPrice)
orderId=client.get_all_orders(symbol=pair,limit=1)[0]['orderId']
print('Sell order placed at {}\n'.format(sellPrice))
while True:
openOrders = client.get_all_orders(symbol=pair,limit=1)[0]
if openOrders['status']=='FILLED':
print("Sold: {} at {}".format(quantity,sellPrice))
exit(0)
print(".")
我也尝试通过使用client.get_order(symbol=pair,orderId=orderId)
来使用orderId
,但它仍然做同样的事情。
order = client.order_limit_sell(symbol=pair,quantity=quantity,price=sellPrice)
orderId = order["orderId"]
print('Sell order placed at {}\n'.format(sellPrice))
while True:
currentOrder = client.get_order(symbol=pair,orderId=orderId)
if currentOrder['status']=='FILLED':
print("Sold: {} at {}".format(quantity,sellPrice))
break
print(".")
更好的方法是使用 Python 中的内置线程模块创建另一个线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.