WaniXArif
WaniXArif

Reputation: 53

How to check the order status of a binance order properly

I'm trying to create a sell order and then continuously checking if it has been fulfilled or not but after like one or two iterations in the loop it shows order status as filled whereas the order hasn't been filled actually or sometimes it says order does not exist.

Is there anything wrong with my code or is there a better way to do it?


# 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(".")

I tried using the orderId as well by using client.get_order(symbol=pair,orderId=orderId) but it still does the same thing.

Upvotes: 2

Views: 10619

Answers (1)

Aashish Peepra
Aashish Peepra

Reputation: 196

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(".")

A better way to do this is to create another Thread using built-in threading module in Python.

Upvotes: 8

Related Questions