CoinMarketCapDotNet is a C# wrapper for the CoinMarketCap API, providing convenient access to cryptocurrency market data.
See MIGRATION-V1-TO-V2.md for the full v1 → v2 migration guide.
You can install CoinMarketCapDotNet via NuGet Package Manager or by using the .NET CLI:
Search for CoinMarketCapDotNet in the NuGet Package Manager UI or run the following command in the Package Manager Console:
Install-Package CoinMarketCapDotNet
Run the following command in your project directory:
dotnet add package CoinMarketCapDotNet
Run the following command:
NuGet\Install-Package CoinMarketCapDotNet
v2 multi-targets netstandard2.0 and net8.0. On .NET 8 the package has zero runtime dependencies; on netstandard2.0 it brings only System.Text.Json 8.x.
using CoinMarketCapDotNet.Api;
var api = new CoinMarketCapAPI("YOUR_API_KEY");
var data = await api.Cryptocurrency.GetMapAsync();To use sandbox mode:
var api = new CoinMarketCapAPI("YOUR_API_KEY", useSandbox: true);using CoinMarketCapDotNet.Api;
using CoinMarketCapDotNet.Configuration;
var api = new CoinMarketCapAPI(new CoinMarketCapOptions
{
ApiKey = "YOUR_API_KEY",
UseSandbox = false,
Timeout = TimeSpan.FromSeconds(30)
});
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var data = await api.Cryptocurrency.GetMapAsync(cancellationToken: cts.Token);using CoinMarketCapDotNet.Models.Exceptions;
try
{
var data = await api.Cryptocurrency.GetMapAsync();
}
catch (CoinMarketCapRateLimitException) { /* back off */ }
catch (CoinMarketCapAuthException) { /* check your API key */ }
catch (CoinMarketCapException ex)
{
// Catch-all preserves ex.StatusCode, ex.ErrorCode, ex.CmcErrorMessage
}The wrapper does not build in a retry policy — the right behavior varies by consumer. If you want automatic retries (e.g. exponential backoff on 429 and 5xx), layer a DelegatingHandler onto your HttpClient before injecting it. The cleanest way is Polly via Microsoft.Extensions.Http.Polly:
using CoinMarketCapDotNet.Api;
using CoinMarketCapDotNet.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http;
using Polly;
using Polly.Extensions.Http;
var services = new ServiceCollection();
services.AddHttpClient("CoinMarketCap")
.AddPolicyHandler(HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(r => (int)r.StatusCode == 429)
.WaitAndRetryAsync(3, retry => TimeSpan.FromSeconds(Math.Pow(2, retry))));
services.AddSingleton<CoinMarketCapAPI>(sp =>
{
var factory = sp.GetRequiredService<IHttpClientFactory>();
return new CoinMarketCapAPI(
new CoinMarketCapOptions { ApiKey = "YOUR_API_KEY" },
factory.CreateClient("CoinMarketCap"));
});You can layer any DelegatingHandler this way — Polly is not a dependency of the wrapper itself.
- CryptocurrencyEndpoint: Endpoints related to cryptocurrencies.
- FiatEndpoint: Endpoints related to fiat currencies.
- ExchangeEndpoint: Endpoints related to exchanges.
- GlobalMetricsEndpoint: Endpoints related to global market metrics.
- ToolsEndpoint: Miscellaneous tools and utilities.
- BlockchainEndpoint: Endpoints related to blockchain statistics.
- KeyEndpoint: Endpoints related to API keys.
- ContentEndpoint: Endpoints related to content (news, articles, etc.).
- CommunityEndpoint: Endpoints related to the community.
- FearAndGreedEndpoint: CoinMarketCap Fear & Greed Index (added in v2.1.0).
- IndexEndpoint: CMC 100 and CMC 20 market indices (added in v2.1.0).
- DexEndpoint: DEX data — tokens, pairs, platforms, holders, K-line OHLCV (added across v2.2.0–v2.4.0). Has nested sub-endpoints:
Token,Pairs,Platform,Kline,Holders.
- GetAirdropAsync: Retrieves airdrop details asynchronously.
- GetAirdropsAsync: Retrieves a list of airdrops asynchronously.
- GetCategoriesAsync: Retrieves a list of cryptocurrency categories asynchronously.
- GetCategoryAsync: Retrieves category details asynchronously.
- GetMapAsync: Retrieves a mapping of all cryptocurrencies to unique CoinMarketCap IDs asynchronously.
- GetInfoAsync: Retrieves cryptocurrency information asynchronously.
- GetListingLatestAsync: Retrieves the latest cryptocurrency listings asynchronously.
- GetListingHistoricalAsync: Retrieves historical cryptocurrency listings asynchronously.
- GetListingNewAsync: Retrieves new cryptocurrency listings asynchronously.
- GetTrendingGainersLosersAsync: Retrieves trending gainers and losers asynchronously.
- GetTrendingLatestAsync: Retrieves the latest trending cryptocurrencies asynchronously.
- GetTrendingMostVisitedAsync: Retrieves the most visited trending cryptocurrencies asynchronously.
- GetMarketPairsLatestAsync: Retrieves the latest cryptocurrency market pairs asynchronously.
- GetOHLCVLatestAsync: Retrieves the latest cryptocurrency OHLCV (Open, High, Low, Close, Volume) data asynchronously.
- GetOHCLVHistoricalAsync: Retrieves historical cryptocurrency OHLCV (Open, High, Low, Close, Volume) data asynchronously.
- GetPricePerformanceStatsLatestAsync: Retrieves the latest cryptocurrency price performance statistics asynchronously.
- GetQuotesHistoricalV2Async: Retrieves historical cryptocurrency quotes using V2 endpoint asynchronously.
- GetQuotesLatestAsync: Retrieves the latest cryptocurrency quotes asynchronously.
- GetQuotesHistoricalV3Async: Retrieves historical cryptocurrency quotes using V3 endpoint asynchronously.
- GetQuotesLatestV3Async: Retrieves the latest cryptocurrency quotes using V3 endpoint asynchronously (v2.1.0).
- GetListingLatestV3Async: Retrieves the latest cryptocurrency listings using V3 endpoint asynchronously (v2.1.0).
- GetMapAsync: Retrieves a mapping of all fiat currencies to unique CoinMarketCap IDs asynchronously.
- GetAssetsAsync: Retrieves a list of exchange assets asynchronously.
- GetInfoAsync: Retrieves exchange information asynchronously.
- GetMapAsync: Retrieves a mapping of all exchanges to unique CoinMarketCap IDs asynchronously.
- GetListingLatestAsync: Retrieves the latest exchange listings asynchronously.
- GetMarketPairsAsync: Retrieves exchange market pairs asynchronously.
- GetQuotesHistoricalAsync: Retrieves historical exchange quotes asynchronously.
- GetQuotesLatestAsync: Retrieves the latest exchange quotes asynchronously.
- GetQuotesHistoricalAsync: Retrieves historical global market metrics quotes asynchronously.
- GetQuotesLatestAsync: Retrieves the latest global market metrics quotes asynchronously.
- GetPriceConversionAsync: Retrieves price conversion data asynchronously.
- GetStatisticsLatestAsync: Retrieves the latest blockchain statistics data asynchronously.
- GetKeyInfoAsync: Retrieves API key details and usage stats asynchronously.
- GetContentLatestAsync: Retrieves the latest crypto-related posts from the CMC Community asynchronously.
- GetPostCommentsAsync: Retrieves comments of a CMC Community post asynchronously.
- GetPostLatestAsync: Retrieves the latest crypto-related posts from the CMC Community asynchronously.
- GetPostTopAsync: Retrieves the top crypto-related posts from the CMC Community asynchronously.
- GetTrendingTokenAsync: Retrieves the latest trending tokens from the CMC Community asynchronously.
- GetTrendingTopicAsync: Retrieves the latest trending topics from the CMC Community asynchronously.
- GetLatestAsync: Retrieves the latest CoinMarketCap Fear & Greed Index value with classification asynchronously.
- GetHistoricalAsync: Retrieves historical Fear & Greed Index values asynchronously.
- GetCmc100LatestAsync: Retrieves the latest CMC 100 Index value with its constituent weights asynchronously.
- GetCmc100HistoricalAsync: Retrieves historical CMC 100 Index values at the requested interval asynchronously.
- GetCmc20LatestAsync: Retrieves the latest CMC 20 Index value with its constituent weights asynchronously.
- GetCmc20HistoricalAsync: Retrieves historical CMC 20 Index values at the requested interval asynchronously.
27 DEX endpoints across 5 nested sub-groups. Access them via api.Dex.<SubGroup>.<Method>Async(...).
⚠️ Unverified endpoints. Live integration testing for v2.5.1 was done on a CoinMarketCap Standard-tier key, which does not grant access to every DEX endpoint. The endpoints below were confirmed working end-to-end against the live API:Dex.Pairs.GetSpotPairsLatestAsync,Dex.Pairs.GetQuotesLatestAsync,Dex.Platform.GetListAsync,Dex.Platform.GetDetailAsync. The remaining DEX endpoints either returned403 Forbidden(plan-gated —Dex.Token.GetTrendingAsync,GetNewListAsync,GetMemeListAsync,GetGainerLoserAsync) or a persistenterror_code: 500 "The system is busy"response on this tier (which CMC appears to use in place of403for some plan-gated endpoints:Dex.Token.GetTokenAsync,GetPriceAsync,GetPoolsAsync,GetLiquidityAsync,GetTransactionsAsync,GetSecurityAsync,SearchAsync,GetLiquidityChangeAsync, allDex.Kline.*, and the GET-basedDex.Holders.*methods). Their wrapper code follows the documented request contract and the unit tests cover URL shape and parameters, but their response-body deserialization has not been exercised against a real response. If you are on a Professional or Enterprise plan and hit shape mismatches, please open an issue with the raw response body so we can align the models.
Token-level DEX data. Mix of POST and GET.
- GetTrendingAsync (POST): Trending DEX tokens, filterable by network.
- BatchQueryAsync (POST): Multi-token query in one request.
- BatchPriceAsync (POST): Multi-token price query.
- GetNewListAsync (POST): Newly launched DEX tokens.
- GetMemeListAsync (POST): DEX meme tokens.
- GetGainerLoserAsync (POST): Top DEX gainers and losers.
- GetTokenAsync: Detailed information for a specific token.
- GetPriceAsync: Current price for a specific token.
- GetPoolsAsync: All liquidity pools for a token.
- GetLiquidityAsync: Current liquidity snapshot.
- GetTransactionsAsync: Recent swap/trade history.
- GetSecurityAsync: Security audit summary (honeypot detection, buy/sell taxes).
- SearchAsync: Search DEX tokens by keyword.
- GetLiquidityChangeAsync: Liquidity change history.
DEX trading pair data.
- GetSpotPairsLatestAsync: Latest active DEX spot pairs.
- GetQuotesLatestAsync: Latest market quotes for a specific trading pair.
Blockchain network metadata.
- GetListAsync: List of all DEX-supported blockchain platforms.
- GetDetailAsync: Detailed metadata for a specific platform (chain ID, explorer URL, supported DEXs).
DEX OHLCV chart data.
- GetPointsAsync: K-line price points (timestamp + price + volume).
- GetCandlesAsync: K-line OHLCV candles with trader count.
Wallet distribution and holder classification.
- GetListAsync (POST): Paginated holder list with classification, balance, P/L.
- GetDetailAsync (POST): Detailed info for a specific wallet address.
- GetTrendListAsync: Holder metrics trend over time (count + top-N holding ratios).
- GetTagCountAsync: Holder counts grouped by wallet tags (whale, KOL, smart money, bot, etc.).
- GetCountAsync: Total holder count for a token.
For example, to get the cryptocurrency map:
var data = await api.Cryptocurrency.GetMapAsync(); // Retrieves a mapping of all cryptocurrencies to unique CoinMarketCap IDs.Enum Extensions:
.GetEnumMemberValue(): Example:
CurrencyEnum currency = CurrencyEnum.EUR;
string enumMemberValue = currency.GetEnumMemberValue(); // Should return "USD" you can use this to fetch USD from endpoints.
.GetId(): Example:
CurrencyEnum currency = CurrencyEnum.USD;
int id = currency.GetId(); // You should get the cmc equivalent of EUR id.
.GetSymbol(): Example:
CurrencyEnum currency = CurrencyEnum.TRY; // You should get "TRY"
string symbol = currency.GetSymbol();
.GetCurrencyIds(): Example:
string symbols = "USD,EUR,TRY";
List<int> ids = symbols.GetCurrencyIds(); // Returns the symbol strings as a id list to be used in endpoints.
.GetAllIds(): Example:
List<int> allIds = EnumExtensions.GetAllIds<CategoryEnum>(); // Will return all the ids of a given enum
.GetAllSymbols(): Example:
List<string> enumMemberValues = EnumExtensions.GetAllSymbols<CurrencyEnum>(); // Will return all the symbols of a given enum
Refer to the CoinMarketCap API documentation for more information on available endpoints and their usage.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
MIT License
Bug-fix release hardening the v2.x endpoints against live CoinMarketCap responses. Most users should upgrade.
Breaking changes (all in code paths that were broken in v2.5.0, so existing consumers were seeing runtime errors regardless):
Cryptocurrency.GetListingLatestV3Asyncnow returnsResponseList<LatestV3Data>(wasResponseList<LatestData>). The v3 endpoint returnsquoteas an array, not the V1/V2 dictionary, so a V3-specific model was needed.Cryptocurrency.GetQuotesLatestV3Asyncnow returnsResponseList<QuotesLatestV3Data>(wasResponseList<QuotesLatestData>), for the same reason.Dex.Pairs.GetSpotPairsLatestAsyncnow requires eitherdexIdordexSlug— the CMC endpoint rejects requests without one of these. The method signature now exposes both optional parameters and throwsArgumentExceptionif neither is provided.Dex.Pairs.GetQuotesLatestAsyncparameter renamed frompairAddresstocontractAddressand the wire parameter frompair_addresstocontract_addressto match the live API contract.Models.Dex.Pairs.Common.DexPairDatarewritten to match the actual v4 response schema —base_asset_*/quote_asset_*naming, nestedquotearray via newDexPairQuoteEntry, and correct field names likecontract_addressandlast_updated. The old field names (pair_address,base_token_*,price_usd, etc.) never matched live data; code that read those properties was always gettingnull.
Fixes:
- V3
quotedeserialization (fixesJsonException: could not be converted to Dictionary<String, QuoteData>. Path: $.data[0].quote).QuoteDatagained five optional V3-only fields:Id,Symbol,CexVolume24h,DexVolume24h,MintedMarketCap. They are null on V1/V2 responses. - Fear & Greed historical timestamps (fixes
JsonException: not in a supported DateTime format). CMC returns Unix epoch seconds as a string for this endpoint; a newUnixTimestampDateTimeConverterhandles it and also tolerates ISO-8601. - Numeric
is_active(fixesJsonException: Cannot get the value of a token type 'Number' as a boolean. Path: $.data[0].is_active). Applied toCryptocurrency.Map.MapData.IsActiveandExchange.Map.ExchangeMapData.IsActivevia a newNumericBoolConverterthat acceptstrue/false,0/1, or"0"/"1"/"true"/"false". ResponseList<T>.Datano longer throws when the server returns"data": null. A newNullTolerantListConvertercollapses it to an empty list so callers can safely iterateresult.Datawithout a null check.HandleResponseAsyncnow recognises the pattern CoinMarketCap's v4 DEX endpoints use of returning HTTP 200 with a non-zeroerror_codein the response body and nodatafield. The wrapper now throws a typedCoinMarketCapException(BadRequest / Auth / RateLimit / Server depending on the in-body code) instead of letting a confusingJsonExceptionleak out.
Tests:
- Added 32 integration tests covering the v2.1 and later endpoints (Fear & Greed, CMC 100 / CMC 20 indices, V3 cryptocurrency listings and quotes, and all 25 DEX methods). Tests read the API key from the
CMC_API_KEYenvironment variable at construction time with the old placeholder still honoured as a fallback. - Replaced 36 stale
Assert.ThrowsAsync<Exception>calls withAssert.ThrowsAnyAsync<Exception>.Assert.ThrowsAsyncmatches the exact exception type; the v2.0 release started throwing typedCoinMarketCapXExceptionsubclasses, so these assertions had been failing against the live API since v2.0.
See the v2.2.0–v2.4.0 DEX section above for the known DEX endpoint coverage caveat on non-Professional/Enterprise keys.
- Added
ICoinMarketCapAPIinterface for DI and test-double scenarios.CoinMarketCapAPIimplements it. Additive — consumers using the concrete type continue to work unchanged. - Updated README endpoint reference tables to cover every method added since v2.0.0 (Fear & Greed, CMC Index, v3 cryptocurrency methods, and the entire DEX section with its 5 sub-groups).
- Added a Retries and rate-limit backoff section to the README showing how to layer Polly onto an injected
HttpClient. - Added XML documentation comments to all
CoinMarketCapOptionsproperties. - Fixed the
Acceptsrequest header typo (now correctlyAccept). No behavioral change — CoinMarketCap's servers ignored the previous header, but the corrected name is standards-compliant. - Gitignored local build artifacts (
/artifacts/,build_output.txt,bash.exe.stackdump).
- Added the final DEX sub-group:
api.Dex.Holders.*(5 endpoints).GetListAsync(POST) — paginated holder list with classification, balance, P/L.GetDetailAsync(POST) — detailed info for a specific wallet address.GetTrendListAsync(GET) — holder metrics over time (count + top-N holding ratios).GetTagCountAsync(GET) — holder counts grouped by wallet tags (whale, KOL, smart money, bot, etc.).GetCountAsync(GET) — total holder count.
- Tier 3 complete: The DEX category is now fully wrapped.
api.Dex.{Token,Pairs,Platform,Kline,Holders}together cover all 22 CMC DEX endpoints shipped across v2.2.0 → v2.4.0. - Fully additive release — no breaking changes from v2.3.0.
- Expanded the DEX endpoint group with three new sub-groups:
api.Dex.Pairs.*(2 endpoints) —GetSpotPairsLatestAsync,GetQuotesLatestAsyncfor DEX trading pair data.api.Dex.Platform.*(2 endpoints) —GetListAsync,GetDetailAsyncfor blockchain network metadata.api.Dex.Kline.*(2 endpoints) —GetPointsAsync,GetCandlesAsyncfor DEX OHLCV chart data.
- Fully additive release — no breaking changes from v2.2.0.
- DEX Holders endpoints are deferred to v2.4.0.
- Added DEX endpoint group with Token sub-group: 14 new methods under
api.Dex.Token.*(trending, batch query, batch price, new list, meme list, gainer/loser, token detail, price, pools, liquidity, transactions, security, search, liquidity change). - Added public
PostDataAsync<T>(endpoint, body, cancellationToken)transport method onCoinMarketCapAPIfor POST endpoints. - Refactored shared response handling into a private
HandleResponseAsync<T>helper used by bothGetDataAsyncandPostDataAsync. No behavior changes for existing GET endpoints. - Fully additive release — no breaking changes from v2.1.0.
- DEX Pairs, Holders, Platform, and K-line endpoints are deferred to v2.3.0 / v2.4.0.
- Added Fear and Greed Index endpoint group:
api.FearAndGreed.GetLatestAsync(),api.FearAndGreed.GetHistoricalAsync(...). - Added CMC Index endpoint group with CMC 100 and CMC 20 latest + historical:
api.Index.GetCmc100LatestAsync(),api.Index.GetCmc100HistoricalAsync(...),api.Index.GetCmc20LatestAsync(),api.Index.GetCmc20HistoricalAsync(...). - Added v3 cryptocurrency methods:
GetQuotesLatestV3AsyncandGetListingLatestV3Async. The existing v1/v2 methods are unchanged. - Fully additive release — no breaking changes from v2.0.0.
- Multi-targets
netstandard2.0andnet8.0. - Migrated to
System.Text.Json— zero runtime dependencies on .NET 8. - Typed exception hierarchy under
CoinMarketCapDotNet.Models.Exceptions. CancellationTokenon every async method.- Options-pattern configuration via
CoinMarketCapOptions. - Injectable
HttpClientforIHttpClientFactory/ DI scenarios. - Nullable reference types enabled throughout.
- See MIGRATION-V1-TO-V2.md for upgrade instructions.
For older v1.x release notes, see the GitHub Releases page.
Sandbox results are kind of different than the live ones. Tests that pass when the sandbox is true don't pass on live mode and cause serialization issues. The endpoints are tested on sandbox results. Not all endpoints are available for the free tier.
Unless CoinMarketCap provides an enterprise key I won't be able to make sure everything is on point. Please create an issue if you encounter a problem.
On top of that, the API Docs Response Schema is not always the same as the response we get. I will be sticking with the response schema for now.
If this library saves you time, a tip in USDT (TRC20, on Tron) is appreciated:
TGgenJpoPvTFsd61hCUquyM4yQ9mAmD9hc
