Skip to main content

Python wrapper around the CoinGecko API

Project description

CoinGecko API wrapper

PyPi Version GitHub

Python3 wrapper around the CoinGecko API (V3)

Installation

PyPI

pip install pycoingecko

or from source

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

Usage

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

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/api/docs/v3)

For any parameter:

  • Lists are supported as input for multiple-valued comma-separated parameters
    (e.g. see /simple/price usage examples).
  • Booleans are supported as input for boolean type parameters; they can be str ('true', 'false'') or bool (True, False)
    (e.g. see /simple/price usage examples).

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/api/docs/v3

Endpoints included

:warning: Endpoints documentation: To make sure that your 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).

  • ping
    • /ping (Check API server status)
      cg.ping()
      
  • simple
    • /simple/price (Get the current price of any cryptocurrencies in any other supported currencies that you need)
      cg.get_price()
      
    • /simple/token_price/{id} (Get current price of tokens (using contract addresses) for a given platform in any other currency that you need)
      cg.get_token_price()
      
    • /simple/supported_vs_currencies (Get list of supported_vs_currencies)
      cg.get_supported_vs_currencies()
      
  • coins
    • /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()
      
    • /coins/{id}/status_updates (Get status updates for a given coin (beta))
      cg.get_coin_status_updates_by_id()
      
    • /coins/{id}/ohlc (Get coin's OHLC (beta))
      cg.get_coin_ohlc_by_id()
      
  • contract
    • /coins/{id}/contract/{contract_address} (Get coin info from contract address)
      cg.get_coin_info_from_contract_address_by_id()
      
    • /coins/{id}/contract/{contract_address}/market_chart/ (Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address)
      cg.get_coin_market_chart_from_contract_address_by_id()
      
    • /coins/{id}/contract/{contract_address}/market_chart/range (Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) from a contract address)
      cg.get_coin_market_chart_range_from_contract_address_by_id()
      
  • asset_platforms
    • /asset_platforms (List all asset platforms (Blockchain networks))
      cg.get_asset_platforms()
      
  • categories
    • /coins/categories/list (List all categories)
      cg.get_coins_categories_list()
      
    • coins/categories (List all categories with market data)
      cg.get_coins_categories()
      
  • exchanges
    • /exchanges (List all exchanges)
      cg.get_exchanges_list()
      
    • /exchanges/list (List all supported markets id and name (no pagination required))
      cg.get_exchanges_id_name_list()
      
    • /exchanges/{id} (Get exchange volume in BTC and top 100 tickers only)
      cg.get_exchanges_by_id()
      
    • /exchanges/{id}/tickers (Get exchange tickers (paginated, 100 tickers per page))
      cg.get_exchanges_tickers_by_id()
      
    • /exchanges/{id}/status_updates (Get status updates for a given exchange (beta))
      cg.get_exchanges_status_updates_by_id()
      
    • /exchanges/{id}/volume_chart (Get volume_chart data for a given exchange (beta))
      cg.get_exchanges_volume_chart_by_id()
      
  • finance
    • /finance_platforms (List all finance platforms)
      cg.get_finance_platforms()
      
    • /finance_products (List all finance products)
      cg.get_finance_products()
      
  • indexes
    • /indexes (List all market indexes)
      cg.get_indexes()
      
    • /indexes/{market_id}/{id} (Get market index by market id and index id)
      cg.get_indexes_by_market_id_and_index_id()
      
    • /indexes/list (List market indexes id and name)
      cg.get_indexes_list()
      
  • derivatives
    • /derivatives (List all derivative tickers)
      cg.get_derivatives()
      
    • /derivatives/exchanges (List all derivative exchanges)
      cg.get_derivatives_exchanges()
      
    • /derivatives/exchanges/{id} (Show derivative exchange data)
      cg.get_derivatives_exchanges_by_id()
      
    • /derivatives/exchanges/list (List all derivative exchanges name and identifier)
      cg.get_derivatives_exchanges_list()
      
  • status_updates
    • /status_updates (List all status_updates with data (description, category, created_at, user, user_title and pin))
      cg.get_status_updates()
      
  • events
    • /events (Get events, paginated by 100)
      cg.get_events()
      
    • /events/countries (Get list of event countries)
      cg.get_events_countries()
      
    • /events/types (Get list of events types)
      cg.get_events_types()
      
  • exchange_rates
    • /exchange_rates (Get BTC-to-Currency exchange rates)
      cg.get_exchange_rates()
      
  • trending
    • /search/trending (Get trending search coins (Top-7) on CoinGecko in the last 24 hours)
      cg.get_search_trending()
      
  • global
    • /global (Get cryptocurrency global data)
      cg.get_global()
      
    • /global/decentralized_finance_defi (Get cryptocurrency global decentralized finance(defi) data)
      cg.get_global_decentralized_finance_defi()
      
  • companies (beta)
    • /companies/public_treasury/{coin_id} (Get public companies data)
      cg.get_companies_public_treasury_by_coin_id()
      

Test

Run unit tests with:

# after installing pytest using pip3
pytest tests

License

MIT

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

pycoingecko-2.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

pycoingecko-2.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pycoingecko-2.2.0.tar.gz.

File metadata

  • Download URL: pycoingecko-2.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pycoingecko-2.2.0.tar.gz
Algorithm Hash digest
SHA256 9add73085729b1f10f93c7948490b09e8cd47c29bebe47dccb319e8b49502d0c
MD5 23a80de7ba30c85d73416de59723bca6
BLAKE2b-256 fdd823109f45b328d618ce320a57cfc4a31769f8d38606d6731fa33802aa73d6

See more details on using hashes here.

File details

Details for the file pycoingecko-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: pycoingecko-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pycoingecko-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3646968c8c6936ca4e94b5f562328a763c12a0e9644141cb0215089dda59fe01
MD5 9bd0a3e9712efb51e080939032bc2e6a
BLAKE2b-256 826f9e9d1d72a3082dffc891a67cc78c950d43b62fe8fda4d53091ff56c6b127

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