Skip to main content

Python wrapper around the CoinGecko API

Project description

CoinGecko API wrapper

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 coresponding functions. Optional parameters can be also passed using same names, as defined in CoinGecko API doc (https://www.coingecko.com/api/docs/v3)

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')
{'bitcoin': {'usd': 3461.27}, 'ethereum': {'usd': 106.92}, 'litecoin': {'usd': 32.72}}

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

API documentation

https://www.coingecko.com/api/docs/v3

Endpoints included

  • 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/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 (no pagination required))
      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}/status_updates (Get status updates for a given coin (beta))
      cg.get_coin_status_updates_by_id()
    
    • /coins/{id}/contract/{contract_address} (Get coin info from contract address)
      cg.get_coin_info_from_contract_address_by_id()
    
  • exchanges (beta)
    • /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))
    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()
    
  • status_updates (beta)
    • /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()
    
  • global
    • /global (Get cryptocurrency global data)
    cg.get_global()
    

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-0.1.6.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

pycoingecko-0.1.6-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycoingecko-0.1.6.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pycoingecko-0.1.6.tar.gz
Algorithm Hash digest
SHA256 169786b4a3924ff5cbf6c7bfc6d68e080fc225e100aad0db55ec88b57ad8e9f9
MD5 6d9d7004a02e96d07b160956f0a6966b
BLAKE2b-256 58a690ea690fb42b98a6c53583c7fa41dee19f82440d3c79287bf8189b12f987

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycoingecko-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pycoingecko-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dadc718ac75b5c6d73f6d0087e14afe6705304f5b798b8c920cf62880636e204
MD5 e2994aea7af07ef83d42123f735daa85
BLAKE2b-256 d2622defe8b10cf6004ef5cc477305b3fafd29134aaca64e18149cd9f51c44ae

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