如何正确检查Binance订单的订单状态

Wan*_*rif 2 python api python-requests binance

我正在尝试创建一个销售订单,然后不断检查它是否已履行,但在循环中进行一两次迭代后,它显示订单状态为已填写,而订单实际上尚未填写,或者有时显示订单不存在。

我的代码有什么问题或者有更好的方法吗?


# 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(".")
Run Code Online (Sandbox Code Playgroud)

我orderId也尝试使用 usingclient.get_order(symbol=pair,orderId=orderId)但它仍然做同样的事情。

Aas*_*pra 7

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(".")
Run Code Online (Sandbox Code Playgroud)

更好的方法是使用 Python 中的内置线程模块创建另一个线程。