getBtcExchangeRates method

Future<CoinGeckoResult<Map<String, ExchangeRate>>> getBtcExchangeRates()

Get BTC-to-Currency exchange rates.

Query path: /exchange_rates

Returns a Future that completes with a CoinGeckoResult containing a map of ExchangeRate objects.

Implementation

Future<CoinGeckoResult<Map<String, ExchangeRate>>>
    getBtcExchangeRates() async {
  final response = await _client.dio.get(
    '/exchange_rates',
  );
  if (response.statusCode == 200) {
    final responseMap = Convert.toMapN(response.data['rates']) ?? {};
    final map = responseMap.map((key, value) =>
        MapEntry(key.toString(), ExchangeRate.fromJson(value)));
    return CoinGeckoResult(map);
  } else {
    return CoinGeckoResult(
      {},
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}