See also: Asynchronous Pymarketcap Scraper
from pymarketcap import Pymarketcap
cmc = Pymarketcap(timeout=10)
cmc.exchanges()
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-4-14a2dd05fa2d> in <module>() ----> 1 from pymarketcap import Pymarketcap 2 cmc = Pymarketcap(timeout=10) 3 4 cmc.exchanges() ~/Escritorio/code/pydocs/my_libraries/pymarketcap/pymarketcap/__init__.py in <module>() 12 __license__ = "BSD License" 13 ---> 14 from pymarketcap.core import Pymarketcap 15 from pymarketcap.errors import ( 16 CoinmarketcapError, ImportError: No module named 'pymarketcap.core'
All methods are self explained in docstrings:
print(cmc.exchanges.__doc__)
listings()
¶List all criptocurrencies with their ids, names, symbol and website slug. You can use cached cryptocurrencies
property also.
cmc.listings()
ticker(currency=None, limit=0, start=0, convert="USD")
¶If currency == None
, you will obtain data for all currencies in coinmarketcap:
cmc.ticker()
You can pass a currency through name
, symbol
, website_slug
or id
:
data_from_symbol = cmc.ticker("BTC")
data_from_slug = cmc.ticker("bitcoin")
data_from_slug
To get all cryptocurrencies fields you can use the next property:
cmc.cryptocurrencies
Other parameters:
print(cmc.ticker.__doc__)
If you want to get the valid badges that can be passed to convert
param programatically, use this:
print(cmc.ticker_badges)
ticker_all(convert="USD")
¶Obtain all currencies from ticker
method navigating through all API paginated responses.
cmc.ticker_all()
stats(convert="USD")
¶Get global criptocurrency statistics. The convert
parameter works just like in previous method.
cmc.stats()
currency(name, convert="USD")
¶Get metadata from a cryptocurrency passed as first argument.
cmc.currency("BTC")
markets(name, convert="USD")
¶Get all markets for a exchange in coinmarketcap. Pass a currency symbol or slug as first parameter. You can convert the response fields "volume_24h"
and "price"
between "USD"
and "BTC"
with convert
parameter.
cmc.markets("BTC", convert="BTC")
ranks()
¶Get gainers and losers rankings:
cmc.ranks()
historical(currency, start=datetime(2008, 8, 18), end=datetime.now(), revert=False)
¶Get historical prices for a currency. You can filter by start
and end
datetimes provided in datetime
objects. With parameter revert
active, the response will be ordered in chronological order.
from datetime import datetime
cmc.historical("ETH", start=datetime(2018, 2, 1), revert=True)
recently(convert="USD")
¶Get recently added coins in coinmarketcap along with other metadata.
list(cmc.recently())
exchange(name, convert="USD")
¶Get data about a exchange:
cmc.exchange("okex")
In order to obtain all available values for the name
parameter, use:
cmc.exchange_slugs
If you want to get all formatted exchange names:
cmc.exchange_names
exchanges(convert="USD")
¶Get all available exchanges in coinmarketcap ranked by volumes with some metadata:
cmc.exchanges()
If you want to connect with exchanges see
ccxt
library.
tokens(convert="USD")
¶Get platforms tokens data:
cmc.tokens()
cmc.graphs.currency("BTC")
graphs.global_cap([bitcoin=True, start=None, end=None])
¶Display data from total market capitalization charts, including or excluding bitcoin:
cmc.graphs.global_cap(bitcoin=False)
graphs.dominance(start=None, end=None)
¶Get data from percentage of total market capitalization chart:
from datetime import datetime, timedelta
ten_days_ago = datetime.now() - timedelta(days=10)
cmc.graphs.dominance(start=ten_days_ago)
convert(value, currency_in, currency_out)
¶This method converts the value passed as first parameter as price of the currency_in
currency to price of the currency_out
parameter. Works as coinmarketcap criptocurrencies calculator. For example, if you want to converts $100€$ to dolars, use:
cmc.convert(100, "EUR", "USD")
For get all the currencies supported by this method (all currencies; fiat + crypto):
cmc.currencies_to_convert
download_logo(name, size=64, filename=None)
¶Download a currency image logo in .png
format. Valid sizes are: [16, 32, 64, 128, 200]
.
from random import choice
currency = choice([curr["name"] for curr in cmc.cryptocurrencies])
filename = cmc.download_logo(currency, size=200)
from IPython.display import Image
Image(filename)
# Clean downloaded logo
import os
try:
os.remove(filename)
except FileNotFoundError:
pass
download_exchange_logo(name, size=64, filename=None)
¶Download a exchange image logo in .png
format. Valid sizes are: [16, 32, 64, 128, 200]
.
exchange = choice([str(exc["website_slug"]) for exc in cmc.cryptoexchanges])
filename = cmc.download_exchange_logo(exchange, size=128)
Image(filename)
try:
os.remove(filename)
except FileNotFoundError:
pass
from pymarketcap import (
CoinmarketcapError, # This class is top hierarchy class errors
CoinmarketcapHTTPError,
CoinmarketcapTooManyRequestsError
)
You could prevent errors like this
This only happens with Pymarketcap
class. In asynchronous interface, failed requests will be restarted in a queue.