Home

Awesome

CoinGecko API wrapper

PyPi Version GitHub

Python3 wrapper around the CoinGecko API (V3) ๐ŸฆŽ<br> Supports both Public and Pro API:

Installation

PyPI

pip install -U pycoingecko

or from source

git clone https://github.com/man-c/pycoingecko.git
cd pycoingecko
python3 setup.py install

Usage

For free Public API:

For Pro API:

Examples

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:

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}}

API documentation

https://www.coingecko.com/en/api/documentation

๐Ÿ“ก Endpoints included

:warning: 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. <br> Any optional parameters defined in CoinGecko API doc can be passed as function parameters using same parameters names with the API (see Examples above).

<details><summary>ping</summary> <p> </details> <details><summary>key</summary> <p> </details> <details><summary>simple</summary> <p> </details> <details><summary>coins</summary> <p> </details> <details><summary>contract</summary> <p> </details> <details><summary>asset_platforms</summary> <p> </details> <details><summary>categories</summary> <p> </details> <details><summary>exchanges</summary> <p> </details> <details><summary>indexes</summary> <p>
cg.get_indexes()
cg.get_indexes_by_market_id_and_index_id()
cg.get_indexes_list()
</details> <details><summary>derivatives</summary> <p> </details> <details><summary>nfts (beta)</summary> <p> </details> <details><summary>exchange_rates</summary> <p> </details> <details><summary>search</summary> <p> </details> <details><summary>trending</summary> <p> </details> <details><summary>global</summary> <p> </details> <details><summary>companies (beta)</summary> <p> </details>

Test

Installation

Install required packages for testing using:

pip install pytest responses

Usage

Run unit tests with:

# after installing pytest and responses using pip3
pytest tests

License

MIT