getCoinOHLC method

Future<CoinGeckoResult<List<OHLCInfo>>> getCoinOHLC({
  1. required String id,
  2. required String vsCurrency,
  3. int? days,
})

Get coin's OHLC.

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.

Query: /coins/{id}/ohlc

Implementation

Future<CoinGeckoResult<List<OHLCInfo>>> getCoinOHLC({
  required String id,
  required String vsCurrency,
  int? days,
}) async {
  final Map<String, dynamic> queryParameters = {
    'vs_currency': vsCurrency,
    'days': days is int ? days : 'max',
  };
  final response = await _dio.get(
    '/coins/$id/ohlc',
    queryParameters: queryParameters,
  );
  if (response.statusCode == 200) {
    final data = Convert.toList(response.data, []);
    final list = data.map((e) => OHLCInfo.fromArray(e)).toList();
    return CoinGeckoResult(list);
  } else {
    return CoinGeckoResult(
      [],
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}