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?
Answers:
You can assign a call of the function to variable and then have access to it’s data in dict type
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.
please tell me how can I get a pair of BTC-ETH price from coingeco API, for example?
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?
You can assign a call of the function to variable and then have access to it’s data in dict type
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.
please tell me how can I get a pair of BTC-ETH price from coingeco API, for example?