Sangwoo Kim
Sangwoo Kim

Reputation: 61

How can I get a message from Binance API when my order is filled

I created a limit buy order.

If this buy order is filled so I open the long position, I want to create another order immediately.

So basically, I want to get a message from the Binance server when my order event is filled.

Is there any function to do so?

I am using WebSocket via the python-binance library, so it would be perfect if there is that functionality in the python-binance library.

Thank you.

Upvotes: 5

Views: 6875

Answers (2)

You can do it by checking the order status. Below code will do the trick.

# Post a new sell order
params = {
    'symbol': 'BTCUSDT',
    'side': 'SELL',
    'type': 'LIMIT',
    'timeInForce': 'GTC',
    'quantity': 0.001,
    'price': sell_price
}

sell_response = spot_client.new_order(**params)
oid = sell_response['orderId']

loop_sell = True
while (loop_sell):
    order_check = spot_client.get_order("BTCUSDT", orderId=oid)
    order_status = order_check['status']
    if order_status == "FILLED":
        print("Sell Order Filled")
        break
    time.sleep(10)

Upvotes: 1

vijy
vijy

Reputation: 19

Binance does not currently offer notifications when orders are created, canceled, or fulfilled through API.

You can do it through user streams. Below pointer may help you

https://dev.binance.vision/t/new-order-notification/2261

Upvotes: 0

Related Questions