Returning API result in separate values

Question:

I’m trying to create a simple price listener through Coingecko API through this code:

from pycoingecko import CoinGeckoAPI

cg = CoinGeckoAPI()
cg.get_price(ids='bitcoin', vs_currencies='usd')

print(cg.get_price)

But I get the following error message:

<bound method list_args_to_comma_separated..input_args of
<pycoingecko.api.CoinGeckoAPI object at 0x0000017E6EA13940>>

I understand that the output should be: {‘bitcoin’: {‘usd’: 3462.04}}

So how can I make it tell the token name alone and the price in USD alone too?

Asked By: BlueSky Trading

||

Answers:

You can assign a call of the function to variable and then have access to it’s data in dict type

Answered By: MrGre4a

As the commenters are pointing out, you didn’t call the function properly. Either write print(cg.get_price(ids='bitcoin', vs_currencies='usd')) at the end, or assign the value of cg.get_price(ids='bitcoin', vs_currencies='usd') to a variable, and print that variable.

Answered By: airD

please tell me how can I get a pair of BTC-ETH price from coingeco API, for example?

Answered By: Timur Sol
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.