Saving user data to database

I have decided to accumulate most of my questions & answers to them from telegram chat. It should be helpful for others too, or so I hope.

Quick descriptions of scope: I want to save all the trades & orders data (historical & new) from my user on Binance to Mongo database.
Historical are already saved.

My first idea was that there is some API like ‘all orders for Date’, but you must sending a symbol is required. I guess this is because most users have thousandth of orders per day.

I have tried querying and /apidocs/spot/en/#all-orders-user_data , but having more than 100 active symbols (e.g. ones user use) to check I was quickly going through my API limits.

Now I am going for websockets which are better use for this, namely /apidocs/spot/en/#user-data-streams

If we check the payload on order update /apidocs/spot/en/#payload-order-update it seems that all is there, but I have yet to test it.

Hopefully tomorrow, after tests, I will update this post.

Here are some questions:

  1. Is my idea right? Is there a better way to do it?
  2. Will I get all the info from that socket - all that is returned in #all-orders-user_data and all that is returned in #account-trade-list-user_data?
  3. Additionally I want to get the same info for futures (fapi) with - will it work too? Why in seven hells the payload structure is different?

I will gladly dive into discussion,

P.S. sorry for cut links - I can’t add more than two in a post.

  1. Yes, capturing this data live from the WebSocket is the correct way to do it.
  2. Yes, but it will come in a different format. The ExecutionReports will give you the info you need to track order status and trades.
  3. Yes, the same strategy should work for Futures. The Futures API and streams are customized to handle more advanced products and instruments compared to spot trading, so the structure will be different.

Hello everybody!

Thanks for answers. As @Ninjor have suggested - everything is working great for Spot stuff.
Yet for Futures I can’t catch any info.
I have tested it with two API key pairs - one with enabled Futures (as far as I understand that is redundant and used to allow API calls that create / modify orders) and one I use for Spot which has only read flag.

I both cases the result was the same - I can’t catch any signals. My listen key is created and being listened two (I use exactly same code as for spot websocket), but nothing pops up.
Additionally I have checked with primary key (read only one) answers from fapi/v1/openOrders and I see the data there.

To create / listen to socket I use paths from official docs: - /fapi/v1/listenKey
As an additional info - I use with few modifications I am pushing there soon.

I suggest using a lower lever tool instead of a SDK/library to troubleshoot this. Are you able to get data from your listenKey when using a websocket reader tool like the “Simple WebSocket Client” ( or websocat?

Will try with WebSocket Client.

Thanks again, Ninj0r!
The link to the stream was incorrect.

1 Like