As it is being said in the docs a single listenKey is valid for 24 hours. When the listenKey used for the user data stream turns expired the exchange sends ‘listenKeyExpired’ message and closes the websocket (in case of Futures).
I was thinking I can create several API keys, so when I create a listenKey using different API keys each of them would be valid for 24 hours. So for example I can generate a first listenKey using API key X at time 00:00 and a second listenKey using API key Y at time 12:00. So when the first listenKey would get expired in 24 hours the second listenKey will still be valid.
The problem is that when I’m creating listenKeys using different API keys I receive the same listenKey all the time. Am I right that the listenKey will get expired after 24h since first call to POST /fapi/v1/listenKey?
Suppose I’m trading 24/7 with no delays so want to receive a flow of USER_DATA messages and market data (using wss://fstream-auth.binance.com) with no interrupts. How one would achieve this?
The problem is that when I’m creating listenKeys using different API keys I receive the same listenKey all the time.
Listen keys are bound to the account holder of the API Key, not the API Key. Therefore, generating listen keys using two API Keys of the same account will produce the same listen key.
Am I right that the listenKey will get expired after 24h since first call to POST /fapi/v1/listenKey?
If a listen key is already active on the account of the API Key, the POST /fapi/v1/listenKey will return the active listen key and extended it’s validity for the next 60 mintues. However, it is suggested to use the PUT /fapi/v1/listenKey if you intend on extending the validity of a listen key.
Suppose I’m trading 24/7 with no delays so want to receive a flow of USER_DATA messages and market data (using wss://fstream-auth.binance.com) with no interrupts. How one would achieve this?
Extend the validity of the listen key every 30 minutes using the PUT endpoint mentioned previously.
Are you saying that in case I will send PUT /fapi/v1/listenKey every 30 minutes the listenKey will be valid forever and websocket connection using that key will not terminate in 24 hours?
The Listen Key will continue to remain valid however the websocket connection will still disconnect every 24hrs, there is no way around this.
To avoid losing data using the connection reset, open another connection in parallel to the initial connection and switch consumption. Keep track of the update Id to avoid duplicate updates, and once you receive a valid update from the new connection you may close the old one.