historicalTrades method
Will get a specific symbol's historical trades using /historicalTrades
endpoint.
If limit
is provided, will modify the max number of trades returned. (defaults to 100)
API Key required : yes
Query weight : 5
Returns a list of BinanceTrade containing all returned data when request is a success.
Throws a BinanceApiError if an error occurs.
Implementation
Future<List<BinanceTrade>> historicalTrades({
String baseUri = defaultUri,
required String symbol,
int limit = 100,
int? fromId,
}) async {
Map<String, String> params = {'symbol': symbol, 'limit': '$limit'};
if (fromId != null) {
params['fromId'] = '$fromId';
}
final historicalTrades = await sendRequest(
baseUri,
historicalTradesPath,
queryParameters: params,
withKey: true,
);
if (historicalTrades is List) {
return List<BinanceTrade>.from(
historicalTrades.map((t) => BinanceTrade.fromJson(t)),
);
} else {
throw const BinanceApiError(-1, 'unexpected trades format');
}
}