WebSocket User Stream doesn't send any data on TestNet

I use WebSocket User Stream to monitor order execution on Binance Futures account and it works great. Hovewer, I have a problem to get this data for Binance Futures TestNet.

Here is the example, how I connect to TestNet:

I can get a listenKey for TestNet with API Keys provided on testnet binancefuture com:

https://testnet.binancefuture.com/dapi/v1/listenKey

Then I connect to the WebSocket by this Url:
wss://dstream.binancefuture.com/ws/[listenKey]

The connection is established, but no commands are coming when I work with testnet.binancefuture.com

Any ideas, why it doesn’t work?

Hi mate,

I have just tested and can confirm that the User Data Stream is working as expected for me on the Testnet. Make sure that you are in fact creating the listen key via the correct CM Futures Testnet endpoint (/dapi/v1/listenKey). Perhaps it would be useful if you posted the code you’re executing so we can identify any potential issues. Just to confirm, when you’re subscribed to the User Data Stream and make orders on the Testnet, you aren’t receiving any events?

I am having the same issue. I am trying to develop a c++ client . This is the procedure I follow.

  1. First I make a request from my main websocket stream which I use for placing order on the testnet . Binance API Documentation
  2. I get a listen key from above.
  3. Now I start a new connection (websocket) to wss://stream.binancefuture.com::9443/ws/.
  4. i am unable to establish connection here . I send my apikey as well while establishing the connection.

But i get no response .

can someone help

I’ve been having the same problem. I tried just using

websocat -v --ping-interval 30 'wss://stream.binancefuture.com/ws/[listenKey]'

as well to eliminate my code path as a potential problem source with no luck.

@jonte - have you gotten this to work on the FAPI (as well as in your example the DAPI)?

FWIW, I’m retrieving the listenKey successfully from

POST https://testnet.binancefuture.com/fapi/v1/listenKey

Hey, thank you for the suggestion. I tried to get listenKey and then use websocat to check my code workability. And I found a strange thing. I tested 2 scenarios:

  1. Production Coin-M Futures:
  • I got listenKey here: https://dapi.binance.com/dapi/v1/listenKey with my ApiKey & ApiSecret
  • I launch this command in parallel with my App: websocat -v --ping-interval 30 'wss://dstream.binance.com/ws/{listenKey}'
  • I go to my Binance Account → Derivatives → Coin-M Futures and placed an order
  • I see ORDER_TRADE_UPDATE in my App and websocat - everything is working as acpected
  1. TestNet Coin-M Futures:
  • I got listenKey here: https://testnet.binancefuture.com/dapi/v1/listenKey with ApiKey & ApiSecret mentioned on Api Key tab on Mock Trading, I thing I can post them here as they are not private: [ApiKey: 034d609ca9c064a79f574eb4fc1b02959cb386a0b8b21ed91507b965941de161, ApiSecret: cb5e378cadd127a7b8052d06f377e87f6cada57e8915c4b946668affa4e05087]
  • I launch this command in parallel with my App: websocat -v --ping-interval 30 'wss://dstream.binancefuture.com/ws/{listenKey}'
  • I switched to Mock Trading from my Binance Account and placed an mock-order
  • I don’t see any events in my App and I see only ping/pong events with websocat - connection is established, no events

So it seems to me the problem is not related to the my code, but in the way I interact with TestNet.
I see 2 different ways how I can interact with https://testnet.binancefuture.com:

  1. Login with my Binance Account, go to Derivatives → Coin-M Futures, then select My Account → Mock Trading
  2. Go to https://testnet.binancefuture.com directly and login via it - at this point I was not able to login with my Binance Account - I got an error “Email or password error.”, so I registered as a new user (with the same email but different password) - system was verified my email, but still I cannot login - when I press Log In and do Captcha verification, I always get error “Email or password error.”

What is you way to interact with TestNet?

@litebox The binance mainnet user and the binance testnet user are two completely different users. Try login at https://testnet.binancefuture.com/ and once logged in, look at the tabs below, one that says API. There you will have the apiKey and the secretKey of the testnet. Try again as you were doing but with that data. On the other hand, it seems to me that the secretKey is not necessary for the listenKey, only the apiKey

See if it works for you, request the listenKey at https://testnet.binancefuture.com and when streaming use wss://stream.binancefuture.com/ws . This worked for me.

Hi @Ramiro_Deploy - I requested the listenKey from via:

POST https://testnet.binancefuture.com/fapi/v1/listenKey

It returns the following:

{
  "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}

Then I connect to the socket with:

websocat -v --ping-interval 30 'wss://stream.binancefuture.com/ws/pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1'

And I don’t receive any meaningful responses except the ping/pong traffic.

Also, I noticed no matter what listenKey I use it never returns any responses. In other words, even “dummykey” it doesn’t reject with an error.

Hi, please try running the following Python code and then making some trades/actions on the Coin-Margin Futures Testnet and see if that works:

#!/usr/bin/env python

import time
import logging
from binance.lib.utils import config_logging
from binance.um_futures import UMFutures
from binance.websocket.cm_futures.websocket_client import CMFuturesWebsocketClient

config_logging(logging, logging.DEBUG)


def message_handler(message):
    print(message)


api_key = "<your_futures_testnet_api_key>"
client = UMFutures(api_key, base_url="https://testnet.binancefuture.com")
response = client.new_listen_key()

logging.info("Listen key : {}".format(response["listenKey"]))

ws_client = CMFuturesWebsocketClient(stream_url="wss://dstream.binancefuture.com")
ws_client.start()

ws_client.user_data(
    listen_key=response["listenKey"],
    id=1,
    callback=message_handler,
)

time.sleep(30)

logging.debug("closing ws connection")
ws_client.stop()

Note: you need to run pip install binance-futures-connector first

wss://stream.binancefuture.com is for Usd-M Futures, I’m trying to connect to Coin-M Futures with wss://dstream.binancefuture.com

@jonte I’m sorry that I took advantage of the occasion, could you share a sample of how an open order query could be made using that python connector and websocket. thank you so much!

@Ramiro_Deploy Hi, please see my response to your other thread about this. In short there’s currently no way to directly query a specific Futures order via the Websocket. You should use the REST API to query specific open orders/positions.

1 Like

Thanks @jonte - I figured out the problem. Somehow the listenKey was getting mangled and the WS endpoint doesn’t throw any errors when the listenKey is invalid, so it made diagnosing the problem very difficult.

As @bradford suggested, we have to create separate user for TestNet, also I would add you probably have to use another email - in my case whey I tried to register on TestNet with the same email I use on Binance - I was able to do that, but I wasn’t able to login with this user at all.

So I created new user, passed Quiz on Futures, copied new ApiKey to my App and… Got the error when I try to get listenKey :face_with_raised_eyebrow:

https://testnet.binancefuture.com/dapi/v1/listenKey

{"code":-2015,"msg":"Invalid API-key, IP, or permissions for action, request ip: my-ip-address"}

Have no idea why it happens… I pass correct ApiKey from the Api Key Tab. Do I need to somehow whitelist my IP Address fro the TestNet or something? Also, my TestNet User has label “Regular User - Unverified”, do I need to do any extra validation process? I validated my email when I create this test user.

I’m facing the same issue. I see the same API/Secret key pair on both: 28596.7 | BTCUSDT USDⓈ-Margined Perpetual | Binance Futures & 28597.4 | BTCUSD COIN-Margined Perpetual | Binance Futures.
Everything works fine for USDT APIS (/fapi/), but none of the COIN APIs (/dapi/) that require authentication work. I’m getting the same error.

@tfx_utk Did you try to connect to Real Binance User? I didn’t success with TestNet UserStream, but fortunately everything is working on Production - good way to test you connection code anyway. Also, I found TestNet has problems from time to time, so if you don’t connect today - try tomorrow :smiley: