ts-coinmarketcap is a modern, lightweight, and fully-typed TypeScript client for the CoinMarketCap API.
npm install ts-coinmarketcapInstall using your favorite package manager
pnpm
pnpm install ts-coinmarketcapyarn
yarn add ts-coinmarketcapimport { CoinMarketCap } from 'ts-coinmarketcap';
// If you are using a Pro API endpoint, you need to provide an API key.
const client = new CoinMarketCap({ apiKey: 'YOUR_PRO_API_KEY' });
try {
const response = await client.v2.quotes.getQuotesLatest({ symbol: 'BTC' });
// The key for the data object is the cryptocurrency's CoinMarketCap ID.
// Bitcoin's ID is 1.
const btcData = response.data['1'];
if (btcData && btcData.quote['USD']) {
console.log(
`The current price of Bitcoin is: $${btcData.quote['USD'].price.toFixed(2)}`
);
} else {
console.log('Could not retrieve Bitcoin price data.');
}
} catch (error) {
console.error('Error fetching Bitcoin price:', error);
}Some endpoints do not require an API key.
import { CoinMarketCap } from 'ts-coinmarketcap';
const client = new CoinMarketCap();
try {
const listings = await client.v3.cryptocurrency.getListing({ limit: 5 });
console.log('Top 5 Cryptocurrencies:');
listings.data.cryptoCurrencyList.forEach((crypto) => {
console.log(`${crypto.cmcRank}. ${crypto.name} (${crypto.symbol})`);
});
} catch (error) {
console.error('Error fetching listings:', error);
}All response types from the API are exported and can be imported directly. This is useful for annotating your variables and function signatures. The types are organized by API version.
// Example: V1 Types
import type { ListingsLatestResponse } from 'ts-coinmarketcap/types/v1';
// Example: V2 Types
import type { CryptocurrencyQuote, QuotesLatestResponse } from 'ts-coinmarketcap/types/v2';
// Example: V3 Types
import type { GetCryptocurrencyListingResponse } from 'ts-coinmarketcap/types/v3';This library supports both Pro and Public API endpoints, organized by version.
V1 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v1.blockchain |
latestStatistics |
GET |
/v1/blockchain/statistics/latest |
Pro |
v1.community |
getTrendingTokens |
GET |
/v1/community/trending/token |
Pro |
v1.community |
getTrendingTopics |
GET |
/v1/community/trending/topic |
Pro |
v1.content |
getContentLatest |
GET |
/v1/content/latest |
Pro |
v1.content |
getPostComments |
GET |
/v1/content/posts/comments |
Pro |
v1.content |
getLatestPosts |
GET |
/v1/content/posts/latest |
Pro |
v1.content |
getTopPosts |
GET |
/v1/content/posts/top |
Pro |
v1.cryptocurrency |
getAirdrops |
GET |
/v1/cryptocurrency/airdrops |
Pro |
v1.cryptocurrency |
getAirdrop |
GET |
/v1/cryptocurrency/airdrop |
Pro |
v1.cryptocurrency |
getCategory |
GET |
/v1/cryptocurrency/category |
Pro |
v1.cryptocurrency |
getCategories |
GET |
/v1/cryptocurrency/categories |
Pro |
v1.cryptocurrency |
getCryptocurrencyMap |
GET |
/v1/cryptocurrency/map |
Pro |
v1.cryptocurrency |
getHistoricalListings |
GET |
/v1/cryptocurrency/listings/historical |
Pro |
v1.cryptocurrency |
getNewListings |
GET |
/v1/cryptocurrency/listings/new |
Pro |
v1.cryptocurrency |
getListingsLatest |
GET |
/v1/cryptocurrency/listings/latest |
Pro |
v1.cryptocurrency |
getTrendingGainersLosers |
GET |
/v1/cryptocurrency/trending/gainers-losers |
Pro |
v1.cryptocurrency |
getTrendingLatest |
GET |
/v1/cryptocurrency/trending/latest |
Pro |
v1.cryptocurrency |
getTrendingMostVisited |
GET |
/v1/cryptocurrency/trending/most-visited |
Pro |
v1.exchange |
getInfo |
GET |
/v1/exchange/info |
Pro |
v1.exchange |
getMap |
GET |
/v1/exchange/map |
Pro |
v1.exchange |
getListingsLatest |
GET |
/v1/exchange/listings/latest |
Pro |
v1.exchange |
getMarketPairsLatest |
GET |
/v1/exchange/market-pairs/latest |
Pro |
v1.exchange |
getQuotesHistorical |
GET |
/v1/exchange/quotes/historical |
Pro |
v1.exchange |
getQuotesLatest |
GET |
/v1/exchange/quotes/latest |
Pro |
v1.fiat |
getMap |
GET |
/v1/fiat/map |
Pro |
v1.globalMetrics |
getQuotesHistorical |
GET |
/v1/global-metrics/quotes/historical |
Pro |
v1.globalMetrics |
getQuotesLatest |
GET |
/v1/global-metrics/quotes/latest |
Pro |
V2 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v2.cryptocurrency |
getInfo |
GET |
/v2/cryptocurrency/info |
Pro |
v2.marketPairs |
getMarketPairsLatest |
GET |
/v2/cryptocurrency/market-pairs/latest |
Pro |
v2.ohlcv |
getOHLCVLatest |
GET |
/v2/cryptocurrency/ohlcv/latest |
Pro |
v2.ohlcv |
getOHLCVHistorical |
GET |
/v2/cryptocurrency/ohlcv/historical |
Pro |
v2.pricePerformance |
getPricePerformanceStatsLatest |
GET |
/v2/cryptocurrency/price-performance-stats/latest |
Pro |
v2.quotes |
getQuotesLatest |
GET |
/v2/cryptocurrency/quotes/latest |
Pro |
v2.quotes |
getQuotesHistorical |
GET |
/v2/cryptocurrency/quotes/historical |
Pro |
v2.tools |
getPriceConversion |
GET |
/v2/tools/price-conversion |
Pro |
V3 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v3.chart |
getAnnotations |
GET |
/data-api/v3/chart-annotation |
Public |
v3.chatbot |
getFixedQuestions |
GET |
/chatbot/v3/question/fixed-question |
Public |
v3.cmc100Index |
getHistorical |
GET |
/v3/index/cmc100-historical |
Pro |
v3.cmc100Index |
getLatest |
GET |
/v3/index/cmc100-latest |
Pro |
v3.cryptoPurchase |
getPurchaseChannels |
GET |
/data-api/v3/cryptocurrency/purchase/channel |
Public |
v3.cryptoPurchase |
getPurchaseFlags |
POST |
/data-api/v3/cryptocurrency/purchase/flag |
Public |
v3.cryptocurrency |
getListing |
GET |
/data-api/v3/cryptocurrency/listing |
Public |
v3.cryptocurrency |
getDetailLite |
GET |
/data-api/v3/cryptocurrency/detail/lite |
Public |
v3.exchange |
getPairInfo |
GET |
/data-api/v3/cryptocurrency/web/exchange-pair-info |
Public |
v3.exchange |
getMarketPairsLatest |
GET |
/data-api/v3/exchange/market-pairs/latest |
Public |
v3.fearAndGreed |
getFearAndGreedHistorical |
GET |
/data-api/v3/fear-and-greed/historical |
Public |
v3.fearAndGreed |
getFearAndGreedLatest |
GET |
/data-api/v3/fear-and-greed/latest |
Public |
v3.market |
getPairs |
GET |
/data-api/v3/cryptocurrency/market-pairs/latest |
Public |
v3.news |
getTldrList |
POST |
/content/v3/news-tldr/list |
Public |
v3.news |
getNews |
GET |
/aggr/v3/news/cdp |
Public |
V3.1 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v3.1.cryptocurrency |
getHistorical |
GET |
/data-api/v3.1/cryptocurrency/historical |
Public |
V3.3 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v3.3 |
getDetailChart |
GET |
/data-api/v3.3/cryptocurrency/detail/chart |
Public |
V4 Endpoints
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
v4.dex |
getListingsInfo |
GET |
/v4/dex/listings/info |
Pro |
v4.dex |
getListingsQuotes |
GET |
/v4/dex/listings/quotes |
Pro |
v4.dex |
getNetworksList |
GET |
/v4/dex/networks/list |
Pro |
v4.dex.pairs |
getOHLCVHistorical |
GET |
/v4/dex/pairs/ohlcv/historical |
Pro |
v4.dex.pairs |
getOHLCVLatest |
GET |
/v4/dex/pairs/ohlcv/latest |
Pro |
v4.dex.pairs |
getQuotesLatest |
GET |
/v4/dex/pairs/quotes/latest |
Pro |
v4.dex.pairs |
getTradesLatest |
GET |
/v4/dex/pairs/trade/latest |
Pro |
v4.dex.spotPairs |
getLatest |
GET |
/v4/dex/spot-pairs/latest |
Pro |
Web Endpoints
These endpoints scrape data directly from the CoinMarketCap website or their S3 buckets.
| Service | Method Name | HTTP Method | Endpoint | API Type |
|---|---|---|---|---|
web |
getWebSearchData |
GET |
https://s3.coinmarketcap.com/generated/core/crypto/web-search.json |
Public |
web |
getWhitepaperSummary |
GET |
https://s3.coinmarketcap.com/whitepaper/summaries/{slug}/{language}.json |
Public |
web |
getWhitepaperCoins |
GET |
https://s3.coinmarketcap.com/whitepaper/summaries/coins.json |
Public |
web |
getAboutSection |
GET |
https://coinmarketcap.com/currencies/{slug}/ |
Public |
web |
getAcademyArticle |
GET |
https://coinmarketcap.com/academy/article/{slug} |
Public |
web |
getGlossaryTerm |
GET |
https://coinmarketcap.com/academy/glossary/{slug} |
Public |
web |
getExchanges |
GET |
https://s3.coinmarketcap.com/generated/core/exchange/exchanges.json |
Public |
For all configuration options, please see the API docs.
The official CoinMarketCap API documentation is available at https://coinmarketcap.com/api/documentation/v1/. To get an API key, visit https://coinmarketcap.com/api/.
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub
Thanks again for your support, it is much appreciated! π
MIT Β© Shahrad Elahi and contributors.
We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with CoinMarketCap, or any of its subsidiaries or its affiliates. The official CoinMarketCap website can be found at https://coinmarketcap.com/.
The name CoinMarketCap as well as related names, marks, emblems and images are registered trademarks of their respective owners.