Overview
The Dashboard API provides functions for fetching global cryptocurrency market statistics, including total market cap, trading volume, and market dominance metrics. It integrates with the CoinGecko/global endpoint.
File location: src/api/dashboard/dashboardApi.js
Configuration
The Dashboard API uses the shared axios client configured with:- Base URL: CoinGecko API v3 (
https://api.coingecko.com/api/v3) - Timeout: 10 seconds (configurable via
VITE_API_TIMEOUT) - Authentication: Optional CoinGecko Pro API key via
x-cg-pro-api-keyheader - Caching: 5-minute TTL with in-flight request deduplication
Functions
getGlobalStats
Fetches global cryptocurrency market statistics with automatic caching.Signature
Parameters
This function takes no parameters.Returns
Global market statistics from CoinGecko
Total market capitalization by currency (e.g.,
{ usd: 2500000000000 })24-hour trading volume by currency
Market dominance percentages by cryptocurrency (e.g.,
{ btc: 45.2, eth: 18.3 })24-hour market cap change percentage in USD
Number of active cryptocurrencies tracked
Number of active markets
Error Handling
status- HTTP status code (0 if network error)message- Error message from API or generic messagedata- Raw error response dataoriginal- Original axios error object
Caching Behavior
ThegetGlobalStats function implements intelligent caching:
- Cache TTL: 5 minutes (
GLOBAL_STATS_TTL_MS = 5 * 60 * 1000) - In-flight deduplication: Multiple concurrent calls share the same request
- Cache invalidation: Automatic after TTL expires or on error
API Endpoint
CoinGecko Endpoint:GET /global
Documentation: https://docs.coingecko.com/reference/global
Environment Variables
CoinGecko API base URL
Request timeout in milliseconds
Optional CoinGecko Pro API key for higher rate limits
