getExchangeVolumeChartData method

Future<CoinGeckoResult<List<ExchangeVolumeData>>> getExchangeVolumeChartData({
  1. required String id,
  2. required int days,
})

Get volume_chart data for a given exchange.

id sets the exchange id.

days indicates in how many days to include information.

Query: /exchanges/{id}/volume_chart

Implementation

Future<CoinGeckoResult<List<ExchangeVolumeData>>> getExchangeVolumeChartData({
  required String id,
  required int days,
}) async {
  final response = await _dio.get(
    '/exchanges/$id/volume_chart',
    queryParameters: {
      'days': days,
    },
  );
  if (response.statusCode == 200) {
    final list = Convert.toListN(response.data);
    if (list != null) {
      var volumeList =
          list.map((e) => ExchangeVolumeData.fromArray(e)).toList();
      volumeList.removeWhere((e) => e.date.millisecondsSinceEpoch == 0);
      return CoinGeckoResult(volumeList);
    } else {
      return CoinGeckoResult([]);
    }
  } else {
    return CoinGeckoResult(
      [],
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}