getExchangeTickers method

Future<CoinGeckoResult<List<Ticker>>> getExchangeTickers({
  1. required String id,
  2. List<String> coinIds = const [],
  3. int? page,
  4. bool depth = false,
  5. String order = TickersOrder.trustScoreDescending,
})

Get exchange tickers (paginated, 100 tickers per page).

id sets the exchange id.

coinIds filters tickers by coin identifiers.

page sets page through results.

includeExchangeLogo sets whether to include exchange logo. Default is false.

depth sets whether to include 2% orderbook depth. Default is false.

order sets tickers order. Use TickersOrder enumeration as values. Default is TickersOrder.trustScoreDescending.

Query: /exchanges/{id}/tickers

Implementation

Future<CoinGeckoResult<List<Ticker>>> getExchangeTickers({
  required String id,
  List<String> coinIds = const [],
  int? page,
  bool includeExchangeLogo = false,
  bool depth = false,
  String order = TickersOrder.trustScoreDescending,
}) async {
  final Map<String, dynamic> queryParameters = {
    'include_exchange_logo': includeExchangeLogo,
    'depth': depth,
    'order': order,
  };
  if (coinIds.isNotEmpty) {
    queryParameters['coin_ids'] = coinIds.join(',');
  }
  if (page is int) {
    queryParameters['page'] = page;
  }
  final response = await _dio.get(
    '/exchanges/$id/tickers',
    queryParameters: queryParameters,
  );
  if (response.statusCode == 200) {
    final list = Convert.toListN(response.data['tickers']);
    if (list != null) {
      final tickerList = list.map((e) => Ticker.fromJson(e)).toList();
      return CoinGeckoResult(tickerList);
    } else {
      return CoinGeckoResult([]);
    }
  } else {
    return CoinGeckoResult(
      [],
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}