Using the Websocket to check a Futures order's status? I know the orderId of the trade.

I am using Python and with this code managed to continuously get price data via the Websocket:

import websocket
import json

SOCKET = "wss://stream.binance.us:9443/ws/btcusdt@bookTicker"



def on_open(ws):
    print("opened connection to Binance streams")


def on_close(ws):
    print("closed connection to Binance streams")


def on_message(ws, message):
    print("message received from Binance streams")
    json_message = json.loads(message)
    b = json_message['b']
    a = json_message['a']
    print(a,b)
   
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, 
on_message=on_message)
ws.run_forever()

Now I’m wondering if there is a way to continuously get an order status via the Websocket. The order is on Futures trading, and I know its orderId.

Can this be done by simply changing the link at " SOCKET = … " or is the process more complicated. Is it even possible at all?

Thanks in advance!

Turns out what I was trying to do is possible by subscribing to User Data Streams:
https://binance-docs.github.io/apidocs/futures/en/#user-data-streams

This means that the link under " SOCKET = " has to be this one:

“wss://fstream.binance.com/ws/YourListenKey”

Getting the listen key varies from implementation to implementation, but in python-binance which I’m using it is done like this:

YourListenKey = client.future_stream_get_listen_key()

This function is defined as:

def futures_stream_get_listen_key(self):
    res = self._request_futures_api('post', 'listenKey', signed=False, data={})
    return res['listenKey']

This stream doesn’t just check an order’s status, but notifies of any changes on the Futures account. See the link above for possible responses. By parsing through the response data and modifying the code it is possible to check if a certain order’s status is changed.

1 Like