listTokenPrices method
Get current price of tokens (using contract addresses) for a given platform in any other currency that you need.
id
sets the id of the platform issuing tokens.
contractAddresses
sets the contract addresses of tokens.
vsCurrencies
sets vs currencies of coins.
includeMarketCap
sets whether to include market capitalization.
Default is false.
include24hVol
sets whether to include volume in 24 hours.
Default is false.
include24hChange
sets whether to include change in 24 hours.
Default is false.
includeLastUpdatedAt
sets whether to include last updated date.
Default is false.
Query path: /simple/token_price/{id}
Implementation
Future<CoinGeckoResult<List<PriceInfo>>> listTokenPrices({
required String id,
required List<String> contractAddresses,
required List<String> vsCurrencies,
bool includeMarketCap = false,
bool include24hVol = false,
bool include24hChange = false,
bool includeLastUpdatedAt = false,
}) async {
final response = await _client.dio.get(
'/simple/token_price/$id',
queryParameters: {
'contract_addresses': contractAddresses.join(','),
'vs_currencies': vsCurrencies.join(','),
'include_market_cap': includeMarketCap,
'include_24hr_vol': include24hVol,
'include_24hr_change': include24hChange,
'include_last_updated_at': includeLastUpdatedAt
},
);
if (response.statusCode == 200) {
List<PriceInfo> priceInfo = [];
final map = Convert.toMapN<String, dynamic>(response.data);
if (map != null) {
map.forEach((key, value) {
priceInfo.add(PriceInfo.fromJson(key, value));
});
}
return CoinGeckoResult(priceInfo);
} else {
return CoinGeckoResult(
[],
errorMessage: response.data.toString(),
errorCode: response.statusCode ?? null,
isError: true,
);
}
}