4

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.

Sangwoo Kim
  • 51
  • 1
  • 4
  • Yes there is a way to do this. Read the Binance web-socket documentation carefully at https://github.com/binance-us/binance-official-api-docs/blob/master/user-data-stream.md . – JimmyNJ Dec 01 '21 at 21:47
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 03 '21 at 09:13

2 Answers2

1

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)
  • I think this is not scalable, if you are planning to handle more than one order or multiple api keys, there is rate limit – yogesh cl Jan 27 '23 at 14:13
0

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

vijy
  • 19
  • 5