Get today trade data tick

Hello, i want to get the trades (i need the ticks, every trade happened) data from this endpoint: /api/v3/trades
but it has maximum 1000 limit.

Actually i can get the every different days trade data as CSV file from here: Binance Data Collection

But the problem is, it doesnt provide me today’s trades. I have to wait until 03:00 am.

So i need trade data from yesterday 03:00 am to NOW.

Is it possible or not, if possible how can i get it?

Thank you so much.

Hi,

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:

  1. Choose limit=N to be the maximum number of orders you are comfortable processing in one batch.
  2. Using startTime=A&limit=N, get the first batch of orders starting at the desired starting point.
  3. Process order list from the response. Once time > B, you’re done.
  4. If you’re not done, note the orderId of the last order in the response.
  5. Make the next query with orderId=${lastOrderId + 1}&limit=N.
  6. Go to step 3.

I hope that helps.

1 Like

oh thank you so much, that will be to many requests then.

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.

1 Like

Thank you so much for your answers.

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?

@jonte love respect

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.

Thank you so much <3