I was able to get my wallet asset info using the endpoint /sapi/v3/asset/getUserAsset and I putted in a loop to get frequent updates. However, the response time is very slow (1000ms) and not real-time.
I looked at the user data stream in the API documentation, and it seems there’s a way to get a real-time stream for the assets data, same as with the following market data streams:
wss://stream.binance.com:9443/ws/btcusdt@depth
wss://stream.binance.com:9443/ws/btcusdt@bookTicker
Any idea how can I subscribe to the user asset data?
In order to receive updates through websocket regarding assets updates (balance changes), you can create a listenKey via https://binance-docs.github.io/apidocs/spot/en/#user-data-streams and subscribe to it.
I managed to create a listenkey which expires every 60 minutes and it has to be update by sending a PING message every 30 min, as per the documentation. However, what I’m struggling with here is not the listen key rather what is the data stream URL for user asset data. For instance: wss://stream.binance.com:9443/ws/btcusdt@depth is used to subscribe to the market depth data in real-time.
As mentioned in the my prev message, the listenKey stream is already the URL to get your account’s assets data update in real-time. You can test it using the Spot Testnet https://testnet.binance.vision/.