Closed borgr closed 4 years ago
Hi!
The ids refers to the coins that you want to obtain the current price. You can see the list of the supported coins by the API using the coins/list endpoint (cg.get_coins_list()
). The list returned by this endpoint contains the id, symbol and name for each supported coin.
For the cg.get_price()
you need to provide the id of the coins.
vs_currency is the currency of the current coin price that is returned by the cg.get_price()
. The list of the supported currencies by the API can be obtained using the simple/supported_vs_currencies endpoint (cg.get_supported_vs_currencies()
).
To get the price (in eur) for XRP you need to run cg.get_price(ids='ripple', vs_currencies='eur')
, since XRP in CoinGecko's coins list (coins/list: cg.get_coins_list()
) is defined as {'id': 'ripple', 'symbol': 'xrp', 'name': 'XRP'}. Similarly, you can find other coins in the coins/list: cg.get_coins_list()
.
Also, you can find more info in API's documentation: https://www.coingecko.com/en/api
Thanks for the handy wrapper.
I tried to use cg.get_coins_list()
to first identify the index of a given input symbol, and map the symbol to the id.
However, with multiple queries of input symbols, this conversion calls cg.get_coins_list()
multiple times which easily runs into the following error:
HTTPError Traceback (most recent call last)
/var/folders/ql/gwfz_8rd7j9c79vjyqhgxp6c0000gn/T/ipykernel_6924/3259795063.py in <module>
1 input_symbol = 'rgt'
----> 2 supported_symbols = [d['symbol'] for d in cg.get_coins_list()]
3 try:
4 idx = supported_symbols.index(input_symbol)
5 except ValueError:
~/Documents/projects/token-val/.venv/lib/python3.8/site-packages/pycoingecko/utils.py in input_args(*args, **kwargs)
10 args = [arg_preprocessing(v) for v in args]
11
---> 12 return func(*args, **kwargs)
13
14 return input_args
~/Documents/projects/token-val/.venv/lib/python3.8/site-packages/pycoingecko/api.py in get_coins_list(self, **kwargs)
118 api_url = self.__api_url_params(api_url, kwargs)
119
--> 120 return self.__request(api_url)
121
122 @func_args_preprocessing
~/Documents/projects/token-val/.venv/lib/python3.8/site-packages/pycoingecko/api.py in __request(self, url)
27
28 try:
---> 29 response.raise_for_status()
30 content = json.loads(response.content.decode('utf-8'))
31 return content
~/Documents/projects/token-val/.venv/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
951
952 if http_error_msg:
--> 953 raise HTTPError(http_error_msg, response=self)
954
955 def close(self):
HTTPError: 429 Client Error: Too Many Requests for url: https://api.coingecko.com/api/v3/coins/list
Is there any way to get around this issue, or is there any function we can use to map the input symbol to id without using cg.get_coins_list()
?
Hello! You should try to keep somewhere more permanent the list (in example in a variable) in order to reuse it, instead of requesting the list for every input_symbol. Cheers,
I can't understand from the API how to get conversions. do I have to supply the full name of the coin to get it? why is the difference between the ids and the vs? e.g. what do I need to get cg.get_price(ids="xrp", vs_currencies="eur") ? and is it true cg.get_price(ids="eur", vs_currencies="xrp") is against the APIs logic in some hidden way?