简体   繁体   English

如何使用 websocket python-binance 获得未结订单?

[英]How to get open orders with websocket python-binance?

I want to get the status of my orders instantly.我想立即获得我的订单状态。 I reviewed the documents below, but I could not see how to get my open orders with websocket.我查看了下面的文件,但我看不到如何使用 websocket 获得我的未结订单。

https://python-binance.readthedocs.io/en/latest/websockets.html https://python-binance.readthedocs.io/en/latest/websockets.html

https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams

I can get my open orders as seen on this link, but I want to do it with websocket.我可以在这个链接上看到我的未结订单,但我想用 websocket 来做。

orders = client.get_open_orders(symbol='BNBBTC')订单 = client.get_open_orders(symbol='BNBBTC')

https://python-binance.readthedocs.io/en/latest/account.html#id6 https://python-binance.readthedocs.io/en/latest/account.html#id6

It is not a substitute for websocket but I fixed the problem with setInterval.它不能替代 websocket,但我用 setInterval 解决了这个问题。

Backend side app.py后端app.py

@app.route('/allOrders')
@cross_origin(supports_credentials=True)
def allOrders():
    openOrders = getAllOrders("LITBUSD")
    return jsonify(openOrders) 

def getAllOrders(symbol):
    try:
        openOrders =  client.get_all_orders(symbol=symbol)
    except requests.exceptions.ConnectTimeout:
        print("timeout")
        pass 
    return openOrders

js side chart.js js端chart.js

setInterval(function(){ 
    fetch('http://localhost:5000/allOrders')
    .then((r) => r.json())
    .then((response) => {
        console.log(response)       
    })
 }, 3000);

I add the reference in index.html like this.我像这样在 index.html 中添加参考。

 <script src="{{url_for('static', filename='chart.js')}}"></script>

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

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