簡體   English   中英

如何使用 websocket python-binance 獲得未結訂單?

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

我想立即獲得我的訂單狀態。 我查看了下面的文件,但我看不到如何使用 websocket 獲得我的未結訂單。

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

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

我可以在這個鏈接上看到我的未結訂單,但我想用 websocket 來做。

訂單 = client.get_open_orders(symbol='BNBBTC')

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

它不能替代 websocket,但我用 setInterval 解決了這個問題。

后端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端chart.js

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

我像這樣在 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