This CoinGecko Python library provides convenient access to CoinGecko API.
The recommended way to install coingecko API wrapper is via pip
pip install --upgrade coingecko
Before you start, visit coingecko to obtain a demo/paid API key. After that, you can start using the API by:
import coingecko
# Demo API key
client = coingecko.CoinGeckoDemoClient(api_key=<insert_your_demo_api_key>)
# Paid API key
client = coingecko.CoinGeckoProClient(api_key=<insert_your_paid_api_key>)
# Test your API key with ping
response = client.ping.get()
For the list of endpoints and information, visit CoinGecko API Documentation
The default values and parameter namings for each endpoints follows the official documentation.
response = client.ping.get()
# -> {'gecko_says': '(V3) To the Moon!'}
# /simple/price - one coin_id/currency
response = client.simple.get_price(ids='bitcoin', vs_currencies='usd')
# -> {'bitcoin': {'usd': 40067}}
# /simple/price - multiple coin_ids (pass in a list of strings)
response = client.simple.get_price(ids=['bitcoin', 'ethereum'], vs_currencies=['usd', 'myr'])
# -> {'bitcoin': {'usd': 40067, 'myr': 189478}, 'ethereum': {'usd': 2223.37, 'myr': 10514.34}}
# /simple/price - pass in booleans instead of string
response = client.simple.get_price(ids='bitcoin', vs_currencies='usd', include_24hr_vol=True)
# -> {'bitcoin': {'usd': 40067, 'usd_24h_vol': 16742608673.077057}}
# simple/price - precision accepts integer/string
response = client.simple.get_price(ids='bitcoin', vs_currencies='usd', precision=2)
# -> {'bitcoin': {'usd': 40066.81}}
response = client.simple.get_price(ids='bitcoin', vs_currencies='usd', precision="2")
# {'bitcoin': {'usd': 40066.81}}
Check out here!
The library is available as open source under the terms of the MIT License.