getCoinHistory method

Future<CoinGeckoResult<CoinHistory?>> getCoinHistory({
  1. required String id,
  2. required DateTime date,
  3. bool localization = true,
})

Get historical data (name, price, market, stats) at a given date for a coin.

id sets coin id.

date sets the date of data snapshot.

localization sets whether to include all localized languages in response. Default is true.

Query path: /coins/{id}/history

Implementation

Future<CoinGeckoResult<CoinHistory?>> getCoinHistory({
  required String id,
  required DateTime date,
  bool localization = true,
}) async {
  final dateFormatted = DateFormat('dd-MM-yyyy').format(date);
  final response = await _client.dio.get(
    '/coins/$id/history',
    queryParameters: {
      'date': dateFormatted,
      'localization': localization,
    },
  );
  if (response.statusCode == 200) {
    return CoinGeckoResult(CoinHistory.fromJson(response.data));
  } else {
    return CoinGeckoResult(
      null,
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}