getCoinMarketChartRanged method
Get historical market data include price, market cap and 24h volume within a range of timestamp (granularity auto).
id
sets coin id.
vsCurrency
sets the target currency of market data
(usd, eur, jpy, etc.).
from
sets FROM date.
to
sets TO date.
Query path: /coins/{id}/market_chart/range
Implementation
Future<CoinGeckoResult<List<MarketChartData>>> getCoinMarketChartRanged({
required String id,
required String vsCurrency,
required DateTime from,
required DateTime to,
}) async {
final response = await _client.dio.get(
'/coins/$id/market_chart/range',
queryParameters: {
'vs_currency': vsCurrency,
'from': from.millisecondsSinceEpoch ~/ 1000,
'to': to.millisecondsSinceEpoch ~/ 1000,
},
);
if (response.statusCode == 200) {
final list = Helpers.parseMarketChartData(response.data);
return CoinGeckoResult(list);
} else {
return CoinGeckoResult(
[],
errorCode: response.statusCode ?? null,
errorMessage: '${response.statusMessage} - ${response.data.toString()}',
isError: true,
);
}
}