简体   繁体   中英

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.

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

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.

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

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

It is not a substitute for websocket but I fixed the problem with setInterval.

Backend side 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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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