我想立即了解我的订单状态。我查看了下面的文档,但我看不到如何使用 websocket 获取我的未结订单。
https://python-binance.readthedocs.io/en/latest/websockets.html
https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams
我可以在这个链接上看到我的未结订单,但我想用 websocket 来做。
orders = client.get_open_orders(symbol='BNBBTC')
https://python-binance.readthedocs.io/en/latest/account.html#id6
答案 0 :(得分:0)
它不能替代 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 侧图.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>