简体   繁体   English

当我的订单被执行时,如何从 Binance API 收到消息

[英]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.如果此买单已成交,那么我开多头 position,我想立即创建另一个订单。

So basically, I want to get a message from the Binance server when my order event is filled.所以基本上,当我的订单事件完成时,我想从 Binance 服务器获得一条消息。

Is there any function to do so?有没有function可以这样做?

I am using WebSocket via the python-binance library, so it would be perfect if there is that functionality in the python-binance library.我正在通过 python-binance 库使用 WebSocket,所以如果 python-binance 库中有该功能就完美了。

Thank you.谢谢你。

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)

Binance does not currently offer notifications when orders are created, canceled, or fulfilled through API.当通过 API 创建、取消或履行订单时,币安目前不提供通知。

You can do it through user streams.您可以通过用户流来做到这一点。 Below pointer may help you下面的指针可以帮助你

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

You can check this repo in github https://github.com/PiyushDixit96/binance-spot-order-notification-heroku您可以在 github https://github.com/PiyushDixit96/binance-spot-order-notification-heroku中查看此仓库

view code and use it.查看代码并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM