[Websocket] No order filled event received, but only account update using futures testnet

Hi,

I’m currently developing a connector for futures.

To test my implementation I’m using the testnet, I can successfully make API calls and get responses.

I’m currently implementing the websocket part and I’m facing an issue with orders data streams.

I’m using the following endpoints https://testnet.binancefuture.com and wss://stream.binancefuture.com/ws

When placing a limit order I can see the event ORDER_TRADE_UPDATE being triggered with order_status = ‘NEW’, however, when the order is filled, I don’t receive any other event with order_status = ‘FILLED’. I do receive the ACCOUNT_UPDATE event.

Example here:

[05-23-2022_19-09-21] [MESSAGE] {"e":"ORDER_TRADE_UPDATE","T":1653325761146,"E":1653325761149,"o":{"s":"BTCUSDT","c":"4s5ZxCWqZDs6b1SVP0cK4R","S":"SELL","o":"LIMIT","f":"GTC","q":"0.010","p":"30107.70","ap":"0","sp":"0","x":"NEW","X":"NEW","i":3041760179,"l":"0","z":"0","L":"0","T":1653325761146,"t":0,"b":"0","a":"608.30390","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"LIMIT","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}
[05-23-2022_19-09-27] [MESSAGE] {"e":"ACCOUNT_UPDATE","T":1653325766936,"E":1653325766939,"a":{"B":[{"a":"USDT","wb":"2967.60205574","cw":"2967.60205574","bc":"0"}],"P":[{"s":"BTCUSDT","pa":"-0.010","ep":"30107.70000","cr":"-48.55449996","up":"-0.06003087","mt":"cross","iw":"0","ps":"BOTH","ma":"USDT"}],"m":"ORDER"}}

If I try a market order, I have the same result, as I can see ORDER_TRADE_UPDATE with order_status = ‘NEW’ but I never see either ORDER_TRADE_UPDATE event with order_status = FILLED.

Example here:

[05-23-2022_19-28-10] [MESSAGE] {"e":"ORDER_TRADE_UPDATE","T":1653326889990,"E":1653326889993,"o":{"s":"BTCUSDT","c":"jrJIKjkL6GaQ1ZpvcOk1hj","S":"BUY","o":"MARKET","f":"GTC","q":"0.010","p":"0","ap":"0","sp":"0","x":"NEW","X":"NEW","i":3041763941,"l":"0","z":"0","L":"0","T":1653326889990,"t":0,"b":"0","a":"0","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"MARKET","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}
[05-23-2022_19-28-10] [MESSAGE] {"e":"ACCOUNT_UPDATE","T":1653326889990,"E":1653326889993,"a":{"B":[{"a":"USDT","wb":"2957.27333734","cw":"2957.27333734","bc":"0"}],"P":[{"s":"BTCUSDT","pa":"0.010","ep":"30103.60000","cr":"-55.02949996","up":"0.01464680","mt":"cross","iw":"0","ps":"BOTH","ma":"USDT"}],"m":"ORDER"}}

If I manually close my position I can see the ACCOUNT_UPDATE event being triggered.

Does anybody already faced similar issues with data streams using the testnet endpoint ?

Thanks in advance for your support.

I had a try, and no problem to get the order udpates.



{"e":"ORDER_TRADE_UPDATE","T":1653349722447,"E":1653349722450,"o":{"s":"BNBUSDT","c":"LlD5woZkF6OcRQdKUvgndj","S":"BUY","o":"MARKET","f":"GTC","q":"1","p":"0","ap":"0","sp":"0","x":"NEW","X":"NEW","i":260702979,"l":"0","z":"0","L":"0","T":1653349722447,"t":0,"b":"0","a":"0","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"MARKET","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}
{"e":"ACCOUNT_UPDATE","T":1653349722447,"E":1653349722450,"a":{"B":[{"a":"USDT","wb":"2999.87296400","cw":"15883.18007262","bc":"0"}],"P":[{"s":"BNBUSDT","pa":"1","ep":"317.59000","cr":"39.24630000","up":"-0.15472890","mt":"cross","iw":"0","ps":"BOTH","ma":"USDT"}],"m":"ORDER"}}
{"e":"ORDER_TRADE_UPDATE","T":1653349722447,"E":1653349722450,"o":{"s":"BNBUSDT","c":"LlD5woZkF6OcRQdKUvgndj","S":"BUY","o":"MARKET","f":"GTC","q":"1","p":"0","ap":"317.59000","sp":"0","x":"TRADE","X":"FILLED","i":260702979,"l":"1","z":"1","L":"317.590","n":"0.12703600","N":"USDT","T":1653349722447,"t":36665998,"b":"0","a":"0","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"MARKET","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}

please check if there is any issue in your script receiving user data stream.

Thanks for your answer.

Since you had no problem receiving messages, I checked my code and went back to a really simple implementation of the receiving function thread.

If I have an infinite loop with a blocking recv I indeed receive all the messages as expected.

def __on_user_data(self):
    while True:
        message = self.__user_data_websocket.recv()
        log(f"[MESSAGE] {message}")

However, if I use a timed out select on the websocket I always miss the ORDER_TRADE_UPDATE with order_status = FILLED

def __on_user_data(self):
    while not self.__user_data_thread.is_stopped():
        has_data = select.select([self.__user_data_websocket], [], [], 1)
        if has_data[0]:
            message = self.__user_data_websocket.recv()
            log(f"[MESSAGE] {message}")

So the issue seems to come from the fact that I’m using passive waiting with select.

I’m using a custom Thread class to be able to stop the thread by sending a stop event with threading.Event(), in case of disconnection, unsubscribing, etc…

The issue is that if I don’t use select the thread would lock indefinitely on recv and I wouldn’t be able to stop it.

So I think I should either try to solve the issue with select not being triggered on the third message or I should configure the websocket in order to have a non-blocking recv.

What do you think ?

you may have a try with this library and script.