Overview
The Market API provides functions for fetching cryptocurrency market data, including top coins by market cap, price information, and historical performance charts. It integrates with CoinGecko’s/coins/markets and /coins/{id}/market_chart endpoints.
File location: src/api/market/marketApi.js
Configuration
The Market API uses the shared axios client with:- Base URL: CoinGecko API v3 (
https://api.coingecko.com/api/v3) - Timeout: 10 seconds
- Authentication: Optional CoinGecko Pro API key
- Caching: 5-minute TTL per unique request with Map-based cache
Functions
getTopMarketCoins
Fetches top cryptocurrencies by market cap with configurable filtering, sorting, and pagination.Signature
Parameters
Target currency for market data (e.g.,
usd, eur, btc)Sort order. Options:
market_cap_desc- Market cap descending (default)market_cap_asc- Market cap ascendingvolume_desc- Volume descendingvolume_asc- Volume ascendingid_desc- ID descendingid_asc- ID ascending
Number of results per page (1-250)
Page number for pagination
Include 7-day sparkline price data
Price change percentage timeframes (e.g.,
24h, 7d, 24h,7d,30d)Returns
Array of coin market data objects
Coin identifier (e.g.,
bitcoin, ethereum)Coin symbol (e.g.,
btc, eth)Coin name (e.g.,
Bitcoin, Ethereum)URL to coin image/logo
Current price in target currency
Market capitalization in target currency
Market cap rank (1 = highest)
24-hour trading volume
24-hour price change percentage
7-day price change percentage (if requested)
7-day price sparkline data
Array of price points for sparkline chart
Circulating supply of the coin
Total supply of the coin
Maximum supply (null if unlimited)
Example Response
getCoinPerformanceChart
Fetches historical price data for a specific cryptocurrency to generate performance charts.Signature
Parameters
Coin identifier (e.g.,
bitcoin, ethereum, solana)Target currency for price data
Number of days of historical data. Options:
1,7,14,30,90,180,365max- All available data
Returns
Example Response
Caching Behavior
Both functions use Map-based caching with intelligent deduplication:- Cache TTL: 5 minutes (
MARKET_CACHE_TTL_MS = 5 * 60 * 1000) - Cache key: JSON stringified request parameters
- In-flight deduplication: Same requests share the same promise
- Cache invalidation: Automatic on TTL expiry or request error
API Endpoints
Top Market Coins
CoinGecko Endpoint:GET /coins/markets
Query Parameters:
vs_currency- Target currencyorder- Sort orderper_page- Results per pagepage- Page numbersparkline- Include sparklineprice_change_percentage- Change timeframes
Performance Chart
CoinGecko Endpoint:GET /coins/{id}/market_chart
Path Parameters:
{id}- Coin identifier
vs_currency- Target currencydays- Number of days
Error Handling
src/api/axios.js:35-46.