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:
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?
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:
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
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:
Login with my Binance Account, go to Derivatives â Coin-M Futures, then select My Account â Mock Trading
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.â
@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.
@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.
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
{"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.
@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