Package: python-coinmarketcap
Python-CoinMarketCap API WrapperThis is a non-official (but working) Python package to wrap the CoinMarketCap API. With this you can monitor and watch the crypto market.Read the officialAPI documentationFor the pro version, get an API Key on theDevelopper PortalBe sure to replace the API Key in sample code with your own.InstallationVia pippip installpython-coinmarketcap/!\Don't confuse this with the coinmarketcap package.ExamplefromcoinmarketcapapiimportCoinMarketCapAPIcmc=CoinMarketCapAPI()rep=cmc.cryptocurrency_info(symbol='BTC')# See methods belowprint(rep.data)# Whole repsonse payloadprint(rep.data["BTC"]["logo"])# Some data in responseprint(rep.credit_count)# API creditsprint(rep.total_elapsed)# Request time in ms# ...Wrapper ReferencesCoinMarketCapAPISynopsisCoinMarketCapAPI(api_key=None, [debug=False, logger=None, sandbox=False, version='v1'])debug: set verbosity.sandbox: In case of default sandbox API key changes, seeIssue #1.logger: you can give a custom logger.version: set the version in the URL, for futures version.MethodsYou have to pass to the following methods the parameters detailed in theofficial documentation.Methods and documentationEndpoint (version)📄cryptocurrency_map/cryptocurrency/map📄cryptocurrency_info/cryptocurrency/info (v2)📄cryptocurrency_listings_latest/cryptocurrency/listings/latest📄cryptocurrency_listings_historical/cryptocurrency/listings/historical📄cryptocurrency_quotes_latest/cryptocurrency/quotes/latest (v2)📄cryptocurrency_quotes_historical/cryptocurrency/quotes/historical (v2)📄cryptocurrency_marketpairs_latest/cryptocurrency/market-pairs/latest (v2)📄cryptocurrency_ohlcv_latest/cryptocurrency/ohlcv/latest (v2)📄cryptocurrency_ohlcv_historical/cryptocurrency/ohlcv/historical (v2)📄cryptocurrency_priceperformancestats_latest/cryptocurrency/price-performance-stats/latest (v2)📄cryptocurrency_categories/cryptocurrency/categories📄cryptocurrency_category/cryptocurrency/category📄cryptocurrency_airdrops/cryptocurrency/airdrops📄cryptocurrency_airdrop/cryptocurrency/airdrop📄cryptocurrency_trending_latest/cryptocurrency/trending/latest📄cryptocurrency_trending_mostvisited/cryptocurrency/trending/most-visited📄cryptocurrency_trending_gainerslosers/cryptocurrency/trending/gainers-losers📄exchange_map/exchange/map📄exchange_info/exchange/info📄exchange_listings_latest/exchange/listings/latest📄exchange_listings_historical/exchange/listings/historical📄exchange_quotes_latest/exchange/quotes/latest📄exchange_quotes_historical/exchange/quotes/historical📄exchange_marketpairs_latest/exchange/market-pairs/latest📄globalmetrics_quotes_latest/global-metrics/quotes/latest📄globalmetrics_quotes_historical/global-metrics/quotes/historical📄tools_priceconversion/tools/price-conversion (v2)📄tools_postman/tools/postman📄blockchain_statistics_latest/blockchain/statistics/latest📄fiat_map/fiat/map📄partners_flipsidecrypto_fcas_listings_latest/partners/flipside-crypto/fcas/listings/latest📄partners_flipsidecrypto_fcas_quotes_latest/partners/flipside-crypto/fcas/quotes/latest📄key_info/key/info📄content_posts_top/content/posts/top📄content_posts_latest/content/posts/latest📄content_posts_comments/content/posts/comments📄content_latest/content/latestAdditionnal Parametersapi_version(str): if given, will fetch the given version of the endpoint (default is equal to the given version in the CoinMarketCapAPI instance wich is actuallyv1). As mentioned in the list above, some endpoints are "v2" by default.ExampleAssuming you want to get informations about bitcoin. First, read thedocumentationof the correspondingcryptocurrency_infoendpoint.You can pass thesymbolparameter like :cmc.cryptocurrency_info(symbol='BTC')or with theslugparameter :cmc.cryptocurrency_info(slug='bitcoin')You can switch easly in thesandbox modewithout giving an API key or by setting it toNone:cmc = CoinMarketCapAPI() # You are in sandbox environnementYou can enable adebuging mode, just setdebugtoTrueto main class:cmc=CoinMarketCapAPI(debug=True)cmc.cryptocurrency_info(symbol='BTC')This will produce this output :2019-04-06 16:03:04,716 root         DEBUG    GET SANDBOX 'v1/cryptocurrency/info'
PARAMETERS: {'symbol': 'BTC'}
2019-04-06 16:03:05,004 root         DEBUG    RESPONSE: 288ms OK: {u'BTC': {u'category': u'coin', u'name': u'Bitcoin', u'tags': [u'mineable'], u'symbol': u'BTC', u'id': 1, [...]}Optionnaly, you can pass (on-the-fly) aspecific versionof an endpoint by given theapi_versionkeyword argument directly to a method:cmc.cryptocurrency_listings_latest(...,api_version="v1.1")See alsoQuick Start GuideResponseSynopsisYou get results of the API in aResponseinstance.PropertyCorresponding tostandards and conventions:data(dict): will give you the result.status(dict): the status object always included for both successful calls and failures.credit_count(int): the number of credits this call utilized.elapsed(int):  the number of milliseconds it took to process the request to the server.total_elapsed(int): the total number of milliseconds it took to process the request.timesamp(str): current time on the server when the call was executed.error_code(str | None): In case of an error has been raised, this property will give you the status error code.error_message(str | None): In case of an error has been raised, this property will give details about error.error(bool): True if an error has been raised.Exampler=cmc.cryptocurrency_info(symbol='BTC')print(repr(r.status))print(repr(r.data))print(repr(r.credit_count))CoinMarketCapAPIErrorSynopsisIf API returns an error,CoinMarketCapAPIwill raise aCoinMarketCapAPIError.Propertyrep(Response | None): will give you aResponseinstance orNoneif request failed for an other reason than a server error.ExamplefromcoinmarketcapapiimportCoinMarketCapAPI,CoinMarketCapAPIErrorcmc=CoinMarketCapAPI('{YOUR_API_KEY}')# Pro environnement# cmc = CoinMarketCapAPI() # Sandbox environnementtry:r=cmc.cryptocurrency_info(symbol='BTC')exceptCoinMarketCapAPIErrorase:r=e.repprint(repr(r.error))print(repr(r.status))print(repr(r.data))See this project onPyPiGithubSome reading about the wrapperCoinMarketCap API Python Tutorial (2022), Leo Smigel,analyzingalpha.comA fairly comprehensive tutorial on how the API works and who uses this package.CoinMarketCap API - An Introductory Guide, Igor Radovanovic,algotrading101.comA short guide that gives you an overview of the API and provides examples of its uses.ChangeLog4 nov 2022: Version 0.5Remove an unfortunate debug that could display text unnecessarily during an error.Yanked version 0.44 nov 2022: Version 0.4Adding new endpoints (Aug 18/Sep 19):/v1/content/posts/top/v1/content/posts/latest/v1/content/posts/comments/v1/content/latest/v1/tools/postmanThis last one will clearly be useful to extend the wrapper according to the received schemes.Fixapi_keydefault to Sandbox mode.Fix the logger,Issue#4from AlverGan.Fix install_requires, requests was missing.Changing the default API version tov2for some endpoints :/v2/cryptocurrency/info/v2/cryptocurrency/quotes/latest/v2/cryptocurrency/quotes/historical/v2/cryptocurrency/market-pairs/latest/v2/cryptocurrency/ohlcv/latest/v2/cryptocurrency/ohlcv/historical/v2/cryptocurrency/price-performance-stats/latest/v2/tools/price-conversionOn the Readme:Adding new methods references.Modification of the methods table to improve readability.Some grammatical corrections in README (Thanks to@tactipus!).Small changes and removal of some unnecessary spaces in the example codes.Adding reading references about the API and the package (Thanks to their respective authors !).Adding docstring to classes.31 aug 2021: Version 0.3Adding new endpoints (Aug 17):/v1/cryptocurrency/categories/v1/cryptocurrency/category/v1/cryptocurrency/airdrops/v1/cryptocurrency/airdrop/v1/cryptocurrency/trending/latest/v1/cryptocurrency/trending/most-visited/v1/cryptocurrency/trending/gainers-losersPEP 8 styleAddingapi_versionkeyword argument to all endpoints to change on-the-fly the api version to use.8 sept 2020: Version 0.2Adding missing endpointsFixing sandbox mode (seeIssue #1)Addingdeflate, gzipencoding to receive data fast and efficiently.Documentation: adding usefull links6 apr 2019: Version 0.1Give me a coffeeBTC: 39aosiow4nsUvYVA2kP1hZPNZ7ZbJ6ouKr
  ETH: 0x45d940FDA3F1Ce91cA7CB478af72170bb6560201