Skip to main content

Coverage Python Version License

CoinMarketCap

A Python implementation of CoinMarketCap's V1 API.

Installing

python3 -m pip install CoinMarketCapAPI

Authentication

Keys can be loaded given directly to the module or from a file in $HOME/.coinmarketcap.json, with the following syntax.

{
  "sandbox": "API_KEY",
  "production": "API_KEY"
}

Or as OS environment variables.

export COINMARKETCAP_SANDBOX="API_KEY"
export COINMARKETCAP_PRODUCTION="API_KEY"

It's highly recommended to test your application with the sandbox environment. You need a different API key when using the sandbox environment, you can get one from here.

Examples

Init client with an API Key.

from coinmarketcap import Client

key = "API_KEY"
client = Client(apikey=key)

The following example shows how you can access and send a request to each of CoinMarketCap's endpoint (cryptocurrency, exchange, global_metrics, tools). Notice plural and singular method endings. Plurals allow a list of id, symbol or slug, singular allows only a single value.

from coinmarketcap import Client
from datetime import datetime

# Init sandbox client.
client = Client(sandbox=True)

# fetch cryptocurrency info
client.cryptocurrency.info.symbols(["BTC", "ETH"])
client.cryptocurrency.info.ids(1)

# fetch exchange info
client.exchange.info.slugs("binance")
client.exchange.info.ids([1, 4])

# fetch global market data
time = datetime.strptime("2018-12-21", "%Y-%m-%d")
client.global_metrics.quotes.latest()
client.global_metrics.quotes.historical(time_start=time)

amount_1 = 100.4
amount_2 = "901.23"
id = 4
# convert price historic price
client.tools.price.convert_id(amount_1, id, time=time)
client.tools.price.convert_symbol(amount_2, "BTC", convert=["USD", "ETH"])

Due to CoinMarketCap's credit and rate limit system, implementing a proper request throttler is complex. Anyway, I tried to apply three different levels of throttling. WARNING, this module has no perception of credits, only requests.

from coinmarketcap import Client
# By default throttling of requests are off.
# Ignore the Client's keyword arguments "throttle", "plan", and "block" if
# you don't want the client to throttle requests.  

# client_1 will not exceed the number of request one can do each minute.
# Hopefully, an request limit exception will be raised if the limit each minute are exceeded.
# Hopefully, an HTTPError exception will be raised if the daily request limit is exceeded.
client_1 = Client(throttle="minute", plan="basic")

# client_2 will not exceed the daily request limit.
# Hopefully, the thread will be blocked if monthly request limit is exceeded.
# Hopefully, An HTTPError exception is raised if monthly request limit are exceeded.
client_2 = Client(throttle="daily", block=True, plan="hobbyist")

# client_3 will never exceeded CoinMarketCap request limit.
# Hopefully, will never exceed the monthly limit.
# Hopefully, an ratelimit exception is raised if the request limit is exceeded.
client_3 = Client(throttle="monthly", block=False, plan="professional")

Each request is cached, the expiration time of data can be adjusted with the keyword argument expire. Set expire=0 if don't want any cached data.

from coinmarketcap import Client
# cached request will be removed after 1 second
client = Client(expire=1)

# cacherd request will be removed after 1 h
client = Client(expire=3600)

# To remove all data from the cache, use the method clear_cache
client.clear_cache()

TODO

  • Enable Proper throttling of requests.
  • Testing of different python versions.

Metadata

Release files for CoinMarketCapAPI 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CoinMarketCapAPI 0.3
File Size Uploaded
CoinMarketCapAPI-0.3.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CoinMarketCapAPI 0.3
File Interpreter ABI Platform
CoinMarketCapAPI-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 28.1 kB

Release files / CoinMarketCapAPI-0.3.tar.gz

Download URL CoinMarketCapAPI-0.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0365ec46553472fdbc95c26dbd6eaad514c4bb12399d42f1f285471734ea0b1b
BLAKE2b-256 checksum
How to use checksums
5aa0462ce4cc94efe634603918984dd9e6df5d1c1f7b90e3b1177d19bb78e7c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release files / CoinMarketCapAPI-0.3-py3-none-any.whl

Download URL CoinMarketCapAPI-0.3-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
955ceb417ec25ce278bb11c9b3c9d61a4956e78092031f76d1add67545fa0445
BLAKE2b-256 checksum
How to use checksums
62413d02a10becbe119a28fe5d6c1201b45ea809c656cd6477bcedc3f752806a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release history Release notifications | RSS feed

0.5

2 release files

0.4

2 release files

This release

0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page