-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin_manager.py
28 lines (24 loc) · 1.01 KB
/
coin_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
from singleton_metaclass import SingletonMeta
class CoinManager(metaclass=SingletonMeta):
def __init__(self) -> None:
self.available_coins = ["bitcoin", "ethereum", "maga", "solana", "sundog"]
self.latest_prices: dict[str, dict[str, int | float]] = {}
def get_available_coins(self) -> list[str]:
return self.available_coins
def get_latest_prices(self) -> dict[str, dict[str, int | float]]:
return self.latest_prices
def fetch_crypto_prices(self) -> None:
try:
url = 'https://api.coingecko.com/api/v3/simple/price'
params = {
'ids': ',' . join(self.get_available_coins()),
'vs_currencies': 'brl'
}
response = requests.get(url, params)
response.raise_for_status()
data = response.json()
print("API Response:", data)
self.latest_prices = data
except requests.RequestException as e:
print("Request Error:", e)