'In coingecko, trying to get historical prices, but get the prices compared to every currencies

When I use the cg.get_coin_history_by_id('bitcoin', date='30-12-2017') it seems to list the price compared to everything. I don't know how to make it just print one specific currency.



Solution 1:[1]

cg.get_coin_history_by_id returns more than just price, it returns market cap, volume, etc... It isn't comparing the price to anything, it's just returning the data in multiple different currencies.

If you want to access the price for a specific currency just reference it using the keys you see in the response. For example, to get the price of bitcoin on that day in Australian dollars, you would do it like this:

api_resp = cg.get_coin_history_by_id('bitcoin', date='30-12-2017')
price_in_aud = api_resp['market_data']['current_price']['aud']
print(price_in_aud)

Output:
17446.3215245937

The structure of the json looks like this:

{
    "id":"bitcoin",
    "symbol":"btc",
    "name":"Bitcoin",
    "localization":{
       "en":"Bitcoin",
       .
       .
       .
    },
    "image":{
       "thumb":"https://assets.coingecko.com/coins/images/1/thumb/bitcoin.png?1547033579",
       ...
    },
    "market_data":{
       "current_price":{
          "aud":17446.3215245937,
          ...
       },
       "market_cap":{
          "aud":292616246981.057,
          ...
       },
       "total_volume":{
          "aud":4611856472.88116,
          ...
       }
    },
    "community_data":{
       "facebook_likes":"None",
       "twitter_followers":603664,
       ...
    },
    "developer_data":{
       "forks":13660,
       ...
       "code_additions_deletions_4_weeks":{
          "additions":"None",
          "deletions":"None"
       },
       "commit_count_4_weeks":147
    },
    "public_interest_stats":{
       "alexa_rank":2912,
       "bing_matches":"None"
    }
 }

source: pycoingecko

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gfdb