CoinMarketCap Python API Wrapper
Project description
Python-CoinMarketCap API Wrapper
This 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 official API documentation
- For the pro version, get an API Key on the Developper Portal
- Be sure to replace the API Key in sample code with your own.
Installation
Via pip
- pip install python-coinmarketcap
/!\ Don't confuse this with the coinmarketcap package.
Example
from coinmarketcapapi import CoinMarketCapAPI
cmc = CoinMarketCapAPI()
rep = cmc.cryptocurrency_info(symbol='BTC') # See methods below
print(rep.data) # Whole repsonse payload
print(rep.data["BTC"]["logo"]) # Some data in response
print(rep.credit_count) # API credits
print(rep.total_elapsed) # Request time in ms
# ...
Wrapper References
CoinMarketCapAPI
Synopsis
CoinMarketCapAPI(api_key=None, [debug=False, logger=None, sandbox=False, version='v1'])
debug
: set verbosity.sandbox
: In case of default sandbox API key changes, see Issue #1.logger
: you can give a custom logger.version
: set the version in the URL, for futures version.
Methods
You have to pass to the following methods the parameters detailed in the official documentation.
Methods and documentation | Endpoint (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/latest |
Additionnal Parameters
api_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.
Example
Assuming you want to get informations about bitcoin. First, read the documentation of the corresponding cryptocurrency_info endpoint.
- You can pass the
symbol
parameter like :cmc.cryptocurrency_info(symbol='BTC')
- or with the
slug
parameter :cmc.cryptocurrency_info(slug='bitcoin')
You can switch easly in the sandbox mode without giving an API key or by setting it to None
:
cmc = CoinMarketCapAPI() # You are in sandbox environnement
You can enable a debuging mode, just set debug
to True
to 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) a specific version of an endpoint by given the api_version
keyword argument directly to a method:
cmc.cryptocurrency_listings_latest(..., api_version="v1.1")
See also
Response
Synopsis
You get results of the API in a Response
instance.
Property
Corresponding to standards 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.
Example
r = cmc.cryptocurrency_info(symbol='BTC')
print(repr(r.status))
print(repr(r.data))
print(repr(r.credit_count))
CoinMarketCapAPIError
Synopsis
If API returns an error, CoinMarketCapAPI
will raise a CoinMarketCapAPIError
.
Property
rep
(Response | None): will give you aResponse
instance orNone
if request failed for an other reason than a server error.
Example
from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError
cmc = CoinMarketCapAPI('{YOUR_API_KEY}') # Pro environnement
# cmc = CoinMarketCapAPI() # Sandbox environnement
try:
r = cmc.cryptocurrency_info(symbol='BTC')
except CoinMarketCapAPIError as e:
r = e.rep
print(repr(r.error))
print(repr(r.status))
print(repr(r.data))
See this project on
Some reading about the wrapper
- CoinMarketCap API Python Tutorial (2022), Leo Smigel, analyzingalpha.com
- A fairly comprehensive tutorial on how the API works and who uses this package.
- CoinMarketCap API - An Introductory Guide, Igor Radovanovic, algotrading101.com
- A short guide that gives you an overview of the API and provides examples of its uses.
ChangeLog
- 4 nov 2022: Version 0.5
- Remove an unfortunate debug that could display text unnecessarily during an error.
- Yanked version 0.4
- 4 nov 2022: Version 0.4
- Adding new endpoints (Aug 18/Sep 19):
- /v1/content/posts/top
- /v1/content/posts/latest
- /v1/content/posts/comments
- /v1/content/latest
- /v1/tools/postman
- This last one will clearly be useful to extend the wrapper according to the received schemes.
- Fix
api_key
default to Sandbox mode. - Fix the logger, Issue#4 from AlverGan.
- Fix install_requires, requests was missing.
- Changing the default API version to
v2
for 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-conversion
- On 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.
- Adding new endpoints (Aug 18/Sep 19):
- 31 aug 2021: Version 0.3
- Adding 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-losers
- PEP 8 style
- Adding
api_version
keyword argument to all endpoints to change on-the-fly the api version to use.
- Adding new endpoints (Aug 17):
- 8 sept 2020: Version 0.2
- Adding missing endpoints
- Fixing sandbox mode (see Issue #1)
- Adding
deflate, gzip
encoding to receive data fast and efficiently. - Documentation: adding usefull links
- 6 apr 2019: Version 0.1
Give me a coffee
BTC: 39aosiow4nsUvYVA2kP1hZPNZ7ZbJ6ouKr
ETH: 0x45d940FDA3F1Ce91cA7CB478af72170bb6560201
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-coinmarketcap-0.5.tar.gz
.
File metadata
- Download URL: python-coinmarketcap-0.5.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc93759b23a8bad366d1f4f3decb593fdd7451bd90b80db708a6e9108aa220b |
|
MD5 | 484fb7e3e038e72db676a4b6f2482782 |
|
BLAKE2b-256 | ffdf3bb65054660d96606fa68fafe5cf053a3af97a490fc15d5caa71ea2d95f8 |
File details
Details for the file python_coinmarketcap-0.5-py3-none-any.whl
.
File metadata
- Download URL: python_coinmarketcap-0.5-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ed71c168a92b60292ae5c5c59df77d4d6e5f9b3ae724a4a4ad43e93c6bee427 |
|
MD5 | 6b927ae79b9b5263d8978e6fb5a6f044 |
|
BLAKE2b-256 | 9b6b3514dab6bcc949a1b77f08a003d6166e150dd6796d7cfb5a359ed8489212 |