Skip to main content

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 monitoring and watch the crypto market.

Downloads


Installation

Via pip

  • pip install python-coinmarketcap

/!\ Don't confound with the coinmarketcap package.

Example

  from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError

  cmc = CoinMarketCapAPI('{YOUR_API_KEY}')

  r = cmc.cryptocurrency_info(symbol='BTC')

  do_something(r.data)

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 following methods the parameters detailled in the official documentation.

Methods and documentation Description Endpoint
(doc) cryptocurrency_map CoinMarketCap ID map /cryptocurrency/map
(doc) cryptocurrency_info Metadata /cryptocurrency/info
(doc) cryptocurrency_listings_latest Latest listings /cryptocurrency/listings/latest
(doc) cryptocurrency_listings_historical Historical listings /cryptocurrency/listings/historical
(doc) cryptocurrency_quotes_latest Latest quotes /cryptocurrency/quotes/latest
(doc) cryptocurrency_quotes_historical Historical quotes /cryptocurrency/quotes/historical
(doc) cryptocurrency_marketpairs_latest Latest market pairs /cryptocurrency/market-pairs/latest
(doc) cryptocurrency_ohlcv_latest Latest OHLCV /cryptocurrency/ohlcv/latest
(doc) cryptocurrency_ohlcv_historical Historical OHLCV /cryptocurrency/ohlcv/historical
(doc) cryptocurrency_priceperformancestats_latest Price performance Stats /cryptocurrency/price-performance-stats/latest
(doc) cryptocurrency_categories Categories /cryptocurrency/categories
(doc) cryptocurrency_category Category /cryptocurrency/category
(doc) cryptocurrency_airdrops Airdrops /cryptocurrency/airdrops
(doc) cryptocurrency_airdrop Airdrop /cryptocurrency/airdrop
(doc) cryptocurrency_trending_latest Trending Latest /cryptocurrency/trending/latest
(doc) cryptocurrency_trending_mostvisited Trending Most Visited /cryptocurrency/trending/most-visited
(doc) cryptocurrency_trending_gainerslosers Trending Gainers & Losers /cryptocurrency/trending/gainers-losers
(doc) exchange_map CoinMarketCap ID map /exchange/map
(doc) exchange_info Metadata /exchange/info
(doc) exchange_listings_latest Latest listings /exchange/listings/latest
(doc) exchange_listings_historical Historical listings /exchange/listings/historical
(doc) exchange_quotes_latest Latest quotes /exchange/quotes/latest
(doc) exchange_quotes_historical Historical quotes /exchange/quotes/historical
(doc) exchange_marketpairs_latest Latest market pairs /exchange/market-pairs/latest
(doc) globalmetrics_quotes_latest Latest global metrics /global-metrics/quotes/latest
(doc) globalmetrics_quotes_historical Historical global metrics /global-metrics/quotes/historical
(doc) tools_priceconversion Price conversion tool /tools/price-conversion
(doc) blockchain_statistics_latest Latest statistics /blockchain/statistics/latest
(doc) fiat_map CoinMarketCap ID map /fiat/map
(doc) partners_flipsidecrypto_fcas_listings_latest List all available FCAS scores /partners/flipside-crypto/fcas/listings/latest
(doc) partners_flipsidecrypto_fcas_quotes_latest Request specific FCAS scores /partners/flipside-crypto/fcas/quotes/latest
(doc) key_info Key Info /key/info

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 actually v1).

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 a Response instance or None 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

ToDo

  • Add Cryptocurrency Abstraction
  • Add Exchange Abstraction
  • Add GlobalMetrics Abstraction
  • Add Tools Abstraction

ChangeLog

  • 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.
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-coinmarketcap-0.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distributions

python_coinmarketcap-0.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

python_coinmarketcap-0.3-py2.7.egg (11.8 kB view details)

Uploaded Egg

python_coinmarketcap-0.3-py2-none-any.whl (8.5 kB view details)

Uploaded Python 2

File details

Details for the file python-coinmarketcap-0.3.tar.gz.

File metadata

  • Download URL: python-coinmarketcap-0.3.tar.gz
  • Upload date:
  • Size: 8.5 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

Hashes for python-coinmarketcap-0.3.tar.gz
Algorithm Hash digest
SHA256 e99e74e4dbed742e02739d136035e1092723298db01584f839e81747919d552e
MD5 4c22a36a475d43e8094e4b01771fde21
BLAKE2b-256 77aff6afa598de73478f6a49cc00c1db7d199510286c10c9961ffa3f196487bd

See more details on using hashes here.

File details

Details for the file python_coinmarketcap-0.3-py3-none-any.whl.

File metadata

  • Download URL: python_coinmarketcap-0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 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

Hashes for python_coinmarketcap-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ecf721eaad54d64fe6c9a3d1895ca7a5670b84d154ab0d4e15445025aa4dd60
MD5 c2b1da38dfe2bc4e5904ce07eac736a9
BLAKE2b-256 523fb2d389576b1e58b778861a46315c05b8d7e4ec444c95caf456c9f7e50db0

See more details on using hashes here.

File details

Details for the file python_coinmarketcap-0.3-py2.7.egg.

File metadata

  • Download URL: python_coinmarketcap-0.3-py2.7.egg
  • Upload date:
  • Size: 11.8 kB
  • Tags: Egg
  • 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

Hashes for python_coinmarketcap-0.3-py2.7.egg
Algorithm Hash digest
SHA256 c332886791fb9d9a490b1ce3e31012254401c30453e0c0cb23f9e467f9ae2261
MD5 a257050243c291e7c8ba3aa9c7484eef
BLAKE2b-256 6ff73f7c3dd598983b2019bb55970f10fe10d01d4b4115e257e6d79e1cd1c841

See more details on using hashes here.

File details

Details for the file python_coinmarketcap-0.3-py2-none-any.whl.

File metadata

  • Download URL: python_coinmarketcap-0.3-py2-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 2
  • 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

Hashes for python_coinmarketcap-0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 afd5dfc527f3790d180a0faf098e5e216c3347c2e2dabb0fb39b973adc020e50
MD5 9ce87e56b78ae29a79d9edba2df53a53
BLAKE2b-256 6a36301ea66ee12e505011707df71f063a6ed5a8321d65cea32d82c3c43c28e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page