user_socket() not working?

Connected to testnet using the user_socket() stream, but it doesn’t get any messages. In order to test it, I create a limit order, but I don’t receive any messages when the order is filled.

Here is the code:

        ts = bm.user_socket()
        async with ts as tscm:
            while True:
                print('start websocket')
                res = await tscm.recv()
                print('User data socket!!')
                print(res)

Socket seems to be correctly established, since listen key is returned in ts var:

<binance.streams.KeepAliveWebsocket object at 0x00000169D26213C0>

What could be the problem? Is testnet supported?

testnet websocket server has different base url: wss://testnet.binance.vision
Please make sure it’s connected to it.

1 Like

Yes, it’s connected to testnet. In fact, I’m currently using other websockets, like ticker_socket() and kline_socket() and have no problem with any of them. In addition, this user_socket() gets a KeepAliveWebsocket object, as I posted.

Has this user_socket() some kind of problem with testnet? Is it a problem regarding python-binance? Is difficult to test it on mainnet, since it requires an account change or a placed order…

Ok, I tested my code on mainnet and it works properly. It returns an event when I create a new order, and also when I cancel it.

Based on that, can we confirm that this websocket is not working on testnet?

The testnet’s user data stream is working fine.

You can test on terminal with:

websocat -v “wss://testnet.binance.vision/ws/<your_testnet_accounts_listen_key>”

And then send a New Order through for example Postman:

POST https://testnet.binance.vision/api/v3/order?symbol=BNBUSDT&side=SELL&type=MARKET&quantity=1&timestamp=xxx&signature=xxx

Finally, the terminal will update you executionReport events

1 Like