Is there a Coingecko Python API function to query coins based on their 3 letter abbreviation symbol?

Viewed 1776

I am utilizing the coingecko python API, and I want to query bitcoin and other coins price using their symbols like 'BTC' and 'ETH'.

Currently can query with

prices['BTC'] = cg.get_price(ids='bitcoin', vs_currencies='usd')['bitcoin']['usd']
prices['ETH'] = cg.get_price(ids='eth', vs_currencies='usd')['bitcoin']['usd']

However, is there a function for cg python that will let me use the 3 letter abbreviation for the coins?

2 Answers

i've been wondering the same thing too. There doesn't seem to be any standardization for the id field...even having to discern whether to use yearn, or yearn-finance, or yearn.finance, etc is not very ideal...

coin_list = cg.get_coins_list()
d = {}
for coin in coin_list:
    d[coin['symbol']] = coin['id']

# now use d['btc'] to search

prices['BTC'] = cg.get_price(ids=d['btc'], vs_currencies='usd')['bitcoin']['usd']
prices['ETH'] = cg.get_price(ids=d['eth'], vs_currencies='usd')['bitcoin']['usd']
Related