Iwan
Iwan

Reputation: 31

Binance API: How to get an Order ID in binance using python

In order to cancel an order in binance I need an orderID.

How can I place an order and automatically receive an order ID back.

I am sending an order this way

def order_sell():
        client.create_order(
        symbol='XRPBNB',
        side=SIDE_SELL,
        type=ORDER_TYPE_LIMIT,
        timeInForce=TIME_IN_FORCE_GTC,
        newClientOrderId=1,
        quantity=30,
        price= 0.001895)

order_sell()

Order is placed correctly but I am not getting nothing in return. How can I receive and write down the response?

Without orderID i cannot cancel it later instantly and I asking binance API for all orders list to retrieve Id, but I belive it can be done in a proper way.

I am a beginner and would be grateful for answer for beginner.

Upvotes: 1

Views: 1367

Answers (1)

Iwan
Iwan

Reputation: 31

I figured out what was wrong. The correct code should look more less like this:

def order_sell():
    global order_Sell_ID
    order_sell=client.create_order(
                                    symbol='XRPBNB',
                                    side=SIDE_SELL,
                                    type=ORDER_TYPE_LIMIT,
                                    timeInForce=TIME_IN_FORCE_GTC,
                                    quantity=30,
                                    price= xxxx )
    
    order_Sell_ID=order_sell['orderId']
    print(order_sell)
    print("Order ID: " + str(order_Sell_ID))

Upvotes: 1

Related Questions