getCoinMarketChart method
Get historical market data include price, market cap and 24h volume (granularity auto).
id
sets coin id.
vsCurrency
sets the target currency of market data
(usd, eur, jpy, etc.).
days
indicates in how many days to include information.
If the parameter is not specified, the maximum possible number of days is assumed.
interval
sets data interval. Use CoinMarketChartInterval
enumeration as values.
Query path: /coins/{id}/market_chart
Implementation
Future<CoinGeckoResult<List<MarketChartData>>> getCoinMarketChart({
required String id,
required String vsCurrency,
int? days,
String? interval,
}) async {
final Map<String, dynamic> queryParameters = {
'vs_currency': vsCurrency,
'days': days is int ? days : 'max',
};
if (interval is String) {
queryParameters['interval'] = interval;
}
final response = await _client.dio.get(
'/coins/$id/market_chart',
queryParameters: queryParameters,
);
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,
);
}
}