The way you can go about fetching more recent trade data via the API endpoint is by iterating
Since /api/v3/trades only has limit and symbol available - you will need to use /api/v3/historicalTrades which adds an extra parameter, fromId.
In order to get all trades up to the current time, you should start by setting the last orderID available from yesterday’s data CSV as the fromId parameter. Then on the next iteration, have the fromId be set to the last orderID that was returned from the previous iteration (usually previousFromId + 1000 due to the 1000 max limit).
For an endpoint like /api/v3/aggTrades which has the ability to specify a startTime and endTime, the process is slightly easier:
Choose limit=N to be the maximum number of orders you are comfortable processing in one batch.
Using startTime=A&limit=N, get the first batch of orders starting at the desired starting point.
Process order list from the response. Once time > B, you’re done.
If you’re not done, note the orderId of the last order in the response.
Make the next query with orderId=${lastOrderId + 1}&limit=N.
Just make sure you implement proper rate limiting. Also in the future, you may want to use Websockets instead and just store each trade as it happens: Binance API Documentation
Using this websocket means you’d always have up-to-date trade data and wouldn’t need to go back in time to pull old trades.
Actually i just want to create a tick based chart. So i need old tick trades for ploting the chart after i reach ‘NOW’ i will connect to socket to keep ploting candles.
So what do you think would be the best method for this?
No problem mate. In my personal opinion the best way to do this would be to store the trades in a database. I would initially subscribe to the websocket as soon as possible and have logic which writes each trade that’s received into the database. Then I’d setup the script which fetches older trades via the REST API and write the trades into the same database table in the same format (eg. timestamp, order_id, etc…). The database would be setup using orderId as a primary key to prevent duplicates. In the code I’d put a check that once the historical trades catch up with the first trades saved from the websocket (eg. it encounters an orderID which is already in the database or timestamp > than already stored trades) then the REST API script would stop which would just leave the websocket running.
There are a few ways to go about this but that’s just what I would do if I were in your situation. Hope that helps you get started.