getContractMarketChart method

Future<CoinGeckoResult<List<MarketChartData>>> getContractMarketChart({
  1. required String id,
  2. required String contractAddress,
  3. required String vsCurrency,
  4. int? days,
})

Get historical market data including price, market cap, and 24h volume (granularity auto) from a contract address.

id sets the id of the platform issuing tokens.

contractAddress is token's contract address.

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.

Query path: /coins/{id}/contract/{contract_address}/market_chart

Implementation

Future<CoinGeckoResult<List<MarketChartData>>> getContractMarketChart({
  required String id,
  required String contractAddress,
  required String vsCurrency,
  int? days,
}) async {
  final Map<String, dynamic> queryParameters = {
    'vs_currency': vsCurrency,
    'days': days is int ? days : 'max',
  };
  final response = await _client.dio.get(
    '/coins/$id/contract/$contractAddress/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,
    );
  }
}