61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
"""
|
|
TBD
|
|
"""
|
|
|
|
__author__ = "Lukas Mahler"
|
|
__version__ = "0.0.1"
|
|
__date__ = "23.09.2021"
|
|
__email__ = "m@hler.eu"
|
|
__status__ = "Development"
|
|
|
|
# Imports
|
|
from pycoingecko import CoinGeckoAPI
|
|
|
|
|
|
class GeckoAPI:
|
|
|
|
def __init__(self):
|
|
self.api = self.getAPI()
|
|
self.coinlist = self.getCoins()
|
|
|
|
@staticmethod
|
|
def getAPI():
|
|
"""
|
|
|
|
"""
|
|
|
|
api = CoinGeckoAPI()
|
|
if api.ping()['gecko_says'] == '(V3) To the Moon!':
|
|
return api
|
|
else:
|
|
raise ConnectionError("Couldnt connect to Coingecko API.")
|
|
|
|
def getCoins(self):
|
|
"""
|
|
|
|
"""
|
|
|
|
return self.api.get_coins_list()
|
|
|
|
def getSymbol(self, symbol_id, curr="EUR", decimal=2):
|
|
"""
|
|
|
|
"""
|
|
|
|
matching = [x for x in self.coinlist if x["id"] == symbol_id.lower()]
|
|
if len(matching) == 1:
|
|
resp_dict = self.api.get_price(ids=matching[0]["id"], vs_currencies=curr.lower())
|
|
price = resp_dict[matching[0]["id"]][curr.lower()]
|
|
if isinstance(price, int):
|
|
price = float(price) # Convert to always have floats
|
|
price = f"{price:.{decimal}f}"
|
|
return price
|
|
else:
|
|
print(matching)
|
|
# No unique coin found
|
|
return "Not found"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
exit()
|