listCoinMarkets method
List all supported coins price, market cap, volume, and market related data.
vsCurrency
sets the target currency of market data
(usd, eur, jpy, etc.).
coinIds
sets the ids of the coins (cryptocurrency symbols).
category
filters by coin category.
order
sorts results by field. Use CoinMarketsOrder enumeration
as values. Default is CoinMarketsOrder.marketCapDescending
itemsPerPage
sets total results per page. Default is 100.
page
sets page through results. Default is 1.
sparkline
sets whether sparkline in 7 days should be included.
Default is false.
priceChangePercentageIntervals
sets the intervals
at which the price change percentage should be included.
Use PriceChangeInterval enumeration as values.
Query path: /coins/markets
Implementation
Future<CoinGeckoResult<List<Market>>> listCoinMarkets({
required String vsCurrency,
List<String> coinIds = const [],
String category = 'all',
String order = CoinMarketsOrder.marketCapDescending,
int itemsPerPage = 100,
int page = 1,
bool sparkline = false,
List<String> priceChangePercentageIntervals = const [],
}) async {
final Map<String, dynamic> queryParameters = {
'vs_currency': vsCurrency,
'order': order,
'per_page': itemsPerPage,
'page': page,
'sparkline': sparkline,
};
if (category != 'all') {
queryParameters['category'] = category;
}
if (coinIds.isNotEmpty) {
queryParameters['ids'] = coinIds.join(',');
}
if (priceChangePercentageIntervals.isNotEmpty) {
queryParameters['price_change_percentage'] =
priceChangePercentageIntervals.join(',');
}
final response = await _client.dio.get(
'/coins/markets',
queryParameters: queryParameters,
);
if (response.statusCode == 200) {
final list = Convert.toListN(response.data);
final List<Market> marketList = list != null
? list.map((element) => Market.fromJson(element)).toList()
: [];
return CoinGeckoResult(marketList);
} else {
return CoinGeckoResult(
[],
errorCode: response.statusCode ?? null,
errorMessage: '${response.statusMessage} - ${response.data.toString()}',
isError: true,
);
}
}