How do I get all historical trades for a symbol in batches of 100 elements?

I’m working on pulling off the historical trades for the accountants. How do I get all historical trades for a symbol in batches of 100 elements?

I found two endpoints /api/v3/myTrades and /api/v3/allOrders. The former one seems to be getting the trades for a specific account and symbol. The latter gets all account orders; active, canceled, or filled.

var userTrades1 = await _restClient.SpotApi.Trading.GetUserTradesAsync("TRXUSDT", fromId: 0, limit: 50);

var fromId = start.Data.Last().OrderId + 1;

var userTrades2 = await _restClient.SpotApi.Trading.GetUserTradesAsync("TRXUSDT", fromId: fromId, limit: 50);

I use Binance.Net. Look at the snippet above, the last order id in userTrades1 is 155806 and fromId is set to 155806 + 1. The first element in userTrades2 has order id 49976538. I expect to get the data sequentially in batches of 100 elements (limit: 100).

How do I get all historical trades for a symbol in batches of 100 elements?

You can use the /api/v3/allOrders endpoint to get all orders associated with a symbol in batches of 100 elements. You can set the limit parameter to 100 and the symbol parameter to the symbol you are interested in. This endpoint will return all the orders associated with that symbol, including active, canceled, and filled orders.
You can also set optional parameters such as startTime, endTime, and recvWindow to further filter the results.

// Get all orders associated with a symbol in batches of 100 elements
var orders = await _restClient.SpotApi.Trading.GetAllOrdersAsync("TRXUSDT", limit: 100);

// Loop through the results and get the next batch of orders
while (orders.Data.Count == 100)
{
    var fromId = orders.Data.Last().OrderId;
    orders = await _restClient.SpotApi.Trading.GetAllOrdersAsync("TRXUSDT", limit: 100, fromId: fromId);
}