Python wrapper for the CoinGecko API
MIT License
Python3 wrapper around the CoinGecko API (V3)
PyPI
pip install -U pycoingecko
or from source
git clone https://github.com/man-c/pycoingecko.git
cd pycoingecko
python3 setup.py install
For free API:
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
For users with Pro API Key:
from pycoingecko import CoinGeckoAPI
cg = pycoingecko.CoinGeckoAPI(api_key='YOUR_API_KEY')
The required parameters for each endpoint are defined as required (mandatory) parameters for the corresponding functions. Any optional parameters can be passed using same names, as defined in CoinGecko API doc (https://www.coingecko.com/en/api/documentation).
For any parameter:
str
('true', 'false'') or bool
(True
, False
)Usage examples:
# /simple/price endpoint with the required parameters
>>> cg.get_price(ids='bitcoin', vs_currencies='usd')
{'bitcoin': {'usd': 3462.04}}
>>> cg.get_price(ids='bitcoin,litecoin,ethereum', vs_currencies='usd')
# OR (lists can be used for multiple-valued arguments)
>>> cg.get_price(ids=['bitcoin', 'litecoin', 'ethereum'], vs_currencies='usd')
{'bitcoin': {'usd': 3461.27}, 'ethereum': {'usd': 106.92}, 'litecoin': {'usd': 32.72}}
>>> cg.get_price(ids='bitcoin,litecoin,ethereum', vs_currencies='usd,eur')
# OR (lists can be used for multiple-valued arguments)
>>> cg.get_price(ids=['bitcoin', 'litecoin', 'ethereum'], vs_currencies=['usd', 'eur'])
{'bitcoin': {'usd': 3459.39, 'eur': 3019.33}, 'ethereum': {'usd': 106.91, 'eur': 93.31}, 'litecoin': {'usd': 32.72, 'eur': 28.56}}
# optional parameters can be passed as defined in the API doc (https://www.coingecko.com/api/docs/v3)
>>> cg.get_price(ids='bitcoin', vs_currencies='usd', include_market_cap='true', include_24hr_vol='true', include_24hr_change='true', include_last_updated_at='true')
{'bitcoin': {'usd': 3458.74, 'usd_market_cap': 60574330199.29028, 'usd_24h_vol': 4182664683.6247883, 'usd_24h_change': 1.2295378479069035, 'last_updated_at': 1549071865}}
# OR (also booleans can be used for boolean type arguments)
>>> cg.get_price(ids='bitcoin', vs_currencies='usd', include_market_cap=True, include_24hr_vol=True, include_24hr_change=True, include_last_updated_at=True)
{'bitcoin': {'usd': 3458.74, 'usd_market_cap': 60574330199.29028, 'usd_24h_vol': 4182664683.6247883, 'usd_24h_change': 1.2295378479069035, 'last_updated_at': 1549071865}}
https://www.coingecko.com/en/api/documentation
⚠️ Endpoints documentation: To make sure that you are using properly each endpoint you should check the API documentation. Return behaviour and parameters of the endpoints, such as pagination, might have changed. Any optional parameters defined in CoinGecko API doc can be passed as function parameters using same parameters names with the API (see Examples above).
cg.ping()
cg.get_price()
cg.get_token_price()
cg.get_supported_vs_currencies()
/coins/list (List all supported coins id, name and symbol (no pagination required))
cg.get_coins_list()
/coins/markets (List all supported coins price, market cap, volume, and market related data)
cg.get_coins_markets()
/coins/{id} (Get current data (name, price, market, ... including exchange tickers) for a coin)
cg.get_coin_by_id()
/coins/{id}/tickers (Get coin tickers (paginated to 100 items))
cg.get_coin_ticker_by_id()
/coins/{id}/history (Get historical data (name, price, market, stats) at a given date for a coin)
cg.get_coin_history_by_id()
/coins/{id}/market_chart (Get historical market data include price, market cap, and 24h volume (granularity auto))
cg.get_coin_market_chart_by_id()
/coins/{id}/market_chart/range (Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto))
cg.get_coin_market_chart_range_by_id()
cg.get_coin_ohlc_by_id()
cg.get_coin_info_from_contract_address_by_id()
cg.get_coin_market_chart_from_contract_address_by_id()
cg.get_coin_market_chart_range_from_contract_address_by_id()
cg.get_asset_platforms()
cg.get_coins_categories_list()
cg.get_coins_categories()
cg.get_exchanges_list()
cg.get_exchanges_id_name_list()
cg.get_exchanges_by_id()
cg.get_exchanges_tickers_by_id()
cg.get_exchanges_volume_chart_by_id()
cg.get_indexes()
cg.get_indexes_by_market_id_and_index_id()
cg.get_indexes_list()
cg.get_derivatives()
cg.get_derivatives_exchanges()
cg.get_derivatives_exchanges_by_id()
cg.get_derivatives_exchanges_list()
cg.get_nfts_list()
cg.get_nfts_by_id()
cg.get_nfts_collection_by_asset_platform_id_and_contract_address()
cg.get_exchange_rates()
cg.search()
cg.get_search_trending()
cg.get_global()
cg.get_global_decentralized_finance_defi()
cg.get_companies_public_treasury_by_coin_id()
Install required packages for testing using:
pip install pytest responses
Run unit tests with:
# after installing pytest and responses using pip3
pytest tests