Viable way to get trade history via REST API?

I would like to automatically calculate my profits (spot trading), like once every month (or maybe once a week if neccessary). Therefore I implemented a “get my trades” REST API call for more than 10 exchanges, all working fine.

Now I’m at binance and I found this endpoint https://binance-docs.github.io/apidocs/spot/en/#account-trade-list-user_data
But… 1) It costs 5 weight and the symbol is required. and 2) It can only return a max timeframe of 24 hours ?!. This makes it very useless sadly =( No other exchange has this strange limitation.
If I wanted to get my trades for all pairs traded at binance (lets assume they are round about ~800 pairs) for the past 1 month, I would need a weight of 120.000 (if I calculated correctly), so I would need 100 minutes of doing API calls (without being able to continue trading via API in the meantime).
Of course this is only true if a single call per day for each pair is sufficent, this is really sick.

So, why is there this strange limitation that only a timeframe of 24 hours is possible? No other exchange in the world needs this limitation. So is it possible to lift this limitation? It would be even better of course, if the pair would not be required, but I guess the infrastructure from binance is not good enough for this, because of so many pairs?

Of course I know I can instead download csv files. But since I’m trading at so many exchanges, I really hate downloading csv files manually. I would like to automate this process.
Websocket is also no solution, because it means I need a 100% uptime to catch all trades, which is very unlikely.

I just noticed, while the timeframe startTime to endTime can only be 24 hours, I still get up to 1000 entries per response, even if they were not done within 24 hours, if I use “fromID” parameter to hangle from id to id.
It will still take very long, but it is something…

Using the “fromID” parameter of course only works, if I know any ID.
If I don’t know if or when I made any trade at any pair, it will take literally forever to ask this via API, since I need to go in 24 hour steps for every single pair every single day until I find an ID. And if there simply was no trade it will need 365 API calls for a timeframe of 1 year for every single pair.

So yes, it is simply impossible to get trades via API, even, or especially when there were only very few trades.

This is what I’d do -

  1. Find out what day you started to trade
  2. Use that day as start/end time to get your first batch of trade
  3. Get the last trade and use that ID+1 as your next fromId
  4. Then iterate until you get all trades on that symbol (no start/end time only specify fromId)
1 Like

thank you very much.
Yes, if you already know when you traded which pair, everything is ok. But what if you don’t? For example all those tax reporting websites dont know anything and csv+api import are not compatible (according to “cointracking.info”). And there are alot more problems with binance which makes it impossible to properly record all trading acitivties at binance (also according to cointracking.info). Binance should really focus on this…

Not only the tax reporting websites, I also don’t know which pairs I traded when.
Is it really not possible that binance improves on this, so to allow any timeframe? All other exchanges I know (at least 10) do it like this. And if the response would include too many entries, they use pagination or similar mechanics.

Right now the only possible way is to download complete csv (in 3 months steps, which also takes ages…) and try to make it compatible to API and then do the 800+ Api calls at the end of each day.

1 Like

Have you @Serpens66 solved somehow the problem with the pairs? I’ve also found that api/v3/myTrades, but still the problem how to find out the complete list of symbols.

You mentioned downloading CSVs, maybe that might be automated also? It’s pretty easy to parse CSV, store new symbols. But using something like Selenium for this task is quite clumsy.

Yes I found a workaround, but binance still should improve on this and eg. use pagination system like every other exchange… (instead they double the cost of myTrades call -.-).
The workaround is to only use the “fromId” param, not the start/endtime. With fromId you will alawys get up to 1000 trades, regardless if they are within (3months/24hours) or not. And because the trade-ids are integers, you can simply do a call for every pair with fromId=0 . This way you can find out if there are any trades on a pair or not, so 1 call per pair will be enough to find out.
It will still take quite long the first time doing this, but if you then remember the newest tradeId/try to remember on which pairs you trade, it is functional.

1 Like

Ok, got it, you can iterate all the trades. But it’s still unclear to me how to find out the pairs (~ SYMBOL).

use the exchangeInfo GET call, that is not a problem.

Yes, it’s not a problem to make a loop. But there is currently 1430 pairs. It’s a big waste of time. So it’s mainly mental problem :smiley: as this is really costly.

Also so far I didn’t need to fight with limits, so now I’ll need to throttle the calls probably.

Ok, found this one Fetch all account orders Looks like waste of time :frowning: