getMarketIndex method

Future<CoinGeckoResult<MarketIndex?>> getMarketIndex({
  1. required String marketId,
  2. required String indexId,
})

Get market index by market id and index id.

marketId sets the market id.

indexId sets the index id.

Query: /indexes/{market_id}/{id}

Implementation

Future<CoinGeckoResult<MarketIndex?>> getMarketIndex({
  required String marketId,
  required String indexId,
}) async {
  final response = await _dio.get(
    '/indexes/$marketId/$indexId',
  );
  if (response.statusCode == 200) {
    final data = MarketIndex.fromJson(response.data);
    return CoinGeckoResult(data);
  } else {
    return CoinGeckoResult(
      null,
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}