12 fix docs #13
@@ -39,6 +39,8 @@ cp .env.example .env
|
|||||||
Le API Keys devono essere inserite nelle variabili opportune dopo l'uguale e ***senza*** spazi. Esse si possono ottenere tramite i loro providers (alcune sono gratuite, altre a pagamento).\
|
Le API Keys devono essere inserite nelle variabili opportune dopo l'uguale e ***senza*** spazi. Esse si possono ottenere tramite i loro providers (alcune sono gratuite, altre a pagamento).\
|
||||||
Nel file [.env.example](.env.example) sono presenti tutte le variabili da compilare con anche il link per recuperare le chiavi, quindi, dopo aver copiato il file, basta seguire le istruzioni al suo interno.
|
Nel file [.env.example](.env.example) sono presenti tutte le variabili da compilare con anche il link per recuperare le chiavi, quindi, dopo aver copiato il file, basta seguire le istruzioni al suo interno.
|
||||||
|
|
||||||
|
Le chiavi non sono necessarie per far partire l'applicazione, ma senza di esse alcune funzionalità non saranno disponibili o saranno limitate. Per esempio senza la chiave di NewsAPI non si potranno recuperare le ultime notizie sul mercato delle criptovalute. Ciononostante, l'applicazione usa anche degli strumenti che non richiedono chiavi API, come Yahoo Finance e GNews, che permettono di avere comunque un'analisi di base del mercato.
|
||||||
|
|
||||||
### **2. Ollama**
|
### **2. Ollama**
|
||||||
Per utilizzare modelli AI localmente, è necessario installare Ollama, un gestore di modelli LLM che consente di eseguire modelli direttamente sul proprio hardware. Si consiglia di utilizzare Ollama con il supporto GPU per prestazioni ottimali, ma è possibile eseguirlo anche solo con la CPU.
|
Per utilizzare modelli AI localmente, è necessario installare Ollama, un gestore di modelli LLM che consente di eseguire modelli direttamente sul proprio hardware. Si consiglia di utilizzare Ollama con il supporto GPU per prestazioni ottimali, ma è possibile eseguirlo anche solo con la CPU.
|
||||||
|
|
||||||
|
|||||||
@@ -186,24 +186,6 @@ class ProviderTester:
|
|||||||
results["tests"]["get_products"] = f"ERROR: {error_msg}"
|
results["tests"]["get_products"] = f"ERROR: {error_msg}"
|
||||||
results["overall_status"] = "PARTIAL"
|
results["overall_status"] = "PARTIAL"
|
||||||
|
|
||||||
# Test get_all_products
|
|
||||||
timestamp = datetime.now()
|
|
||||||
try:
|
|
||||||
all_products = wrapper.get_all_products()
|
|
||||||
self.formatter.print_request_info(
|
|
||||||
provider_name, "get_all_products()", timestamp, "✅ SUCCESS"
|
|
||||||
)
|
|
||||||
self.formatter.print_product_table(all_products, f"{provider_name} All Products")
|
|
||||||
results["tests"]["get_all_products"] = "SUCCESS"
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
error_msg = str(e)
|
|
||||||
self.formatter.print_request_info(
|
|
||||||
provider_name, "get_all_products()", timestamp, "❌ ERROR", error_msg
|
|
||||||
)
|
|
||||||
results["tests"]["get_all_products"] = f"ERROR: {error_msg}"
|
|
||||||
results["overall_status"] = "PARTIAL"
|
|
||||||
|
|
||||||
# Test get_historical_prices
|
# Test get_historical_prices
|
||||||
timestamp = datetime.now()
|
timestamp = datetime.now()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -12,14 +12,29 @@ __all__ = [ "MarketAPIs", "BinanceWrapper", "CoinBaseWrapper", "CryptoCompareWra
|
|||||||
|
|
||||||
class MarketAPIsTool(BaseWrapper, Toolkit):
|
class MarketAPIsTool(BaseWrapper, Toolkit):
|
||||||
"""
|
"""
|
||||||
Classe per comporre più MarketAPI con gestione degli errori e aggregazione dei dati.
|
Class that aggregates multiple market API wrappers and manages them using WrapperHandler.
|
||||||
Usa WrapperHandler per gestire più API con logica di retry e failover.
|
This class supports retrieving product information and historical prices.
|
||||||
Si può scegliere se aggregare i dati da tutte le fonti o usare una singola fonte tramite delle chiamate apposta.
|
This class can also aggregate data from multiple sources to provide a more comprehensive view of the market.
|
||||||
|
The following wrappers are included in this order:
|
||||||
|
- BinanceWrapper
|
||||||
|
- YFinanceWrapper
|
||||||
|
- CoinBaseWrapper
|
||||||
|
- CryptoCompareWrapper
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, currency: str = "USD"):
|
def __init__(self, currency: str = "USD"):
|
||||||
|
"""
|
||||||
|
Initialize the MarketAPIsTool with multiple market API wrappers.
|
||||||
|
The following wrappers are included in this order:
|
||||||
|
- BinanceWrapper
|
||||||
|
- YFinanceWrapper
|
||||||
|
- CoinBaseWrapper
|
||||||
|
- CryptoCompareWrapper
|
||||||
|
Args:
|
||||||
|
currency (str): Valuta in cui restituire i prezzi. Default è "USD".
|
||||||
|
"""
|
||||||
kwargs = {"currency": currency or "USD"}
|
kwargs = {"currency": currency or "USD"}
|
||||||
wrappers = [ BinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper, YFinanceWrapper ]
|
wrappers = [ BinanceWrapper, YFinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper ]
|
||||||
self.wrappers: WrapperHandler[BaseWrapper] = WrapperHandler.build_wrappers(wrappers, kwargs=kwargs)
|
self.wrappers: WrapperHandler[BaseWrapper] = WrapperHandler.build_wrappers(wrappers, kwargs=kwargs)
|
||||||
|
|
||||||
Toolkit.__init__(
|
Toolkit.__init__(
|
||||||
@@ -28,7 +43,6 @@ class MarketAPIsTool(BaseWrapper, Toolkit):
|
|||||||
tools=[
|
tools=[
|
||||||
self.get_product,
|
self.get_product,
|
||||||
self.get_products,
|
self.get_products,
|
||||||
self.get_all_products,
|
|
||||||
self.get_historical_prices,
|
self.get_historical_prices,
|
||||||
self.get_products_aggregated,
|
self.get_products_aggregated,
|
||||||
self.get_historical_prices_aggregated,
|
self.get_historical_prices_aggregated,
|
||||||
@@ -39,8 +53,6 @@ class MarketAPIsTool(BaseWrapper, Toolkit):
|
|||||||
return self.wrappers.try_call(lambda w: w.get_product(asset_id))
|
return self.wrappers.try_call(lambda w: w.get_product(asset_id))
|
||||||
def get_products(self, asset_ids: list[str]) -> list[ProductInfo]:
|
def get_products(self, asset_ids: list[str]) -> list[ProductInfo]:
|
||||||
return self.wrappers.try_call(lambda w: w.get_products(asset_ids))
|
return self.wrappers.try_call(lambda w: w.get_products(asset_ids))
|
||||||
def get_all_products(self) -> list[ProductInfo]:
|
|
||||||
return self.wrappers.try_call(lambda w: w.get_all_products())
|
|
||||||
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
||||||
return self.wrappers.try_call(lambda w: w.get_historical_prices(asset_id, limit))
|
return self.wrappers.try_call(lambda w: w.get_historical_prices(asset_id, limit))
|
||||||
|
|
||||||
|
|||||||
@@ -26,14 +26,6 @@ class BaseWrapper:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_all_products(self) -> list['ProductInfo']:
|
|
||||||
"""
|
|
||||||
Get product information for all available assets.
|
|
||||||
Returns:
|
|
||||||
list[ProductInfo]: A list of objects containing product information.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list['Price']:
|
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list['Price']:
|
||||||
"""
|
"""
|
||||||
Get historical price data for a specific asset ID.
|
Get historical price data for a specific asset ID.
|
||||||
|
|||||||
@@ -54,17 +54,6 @@ class BinanceWrapper(BaseWrapper):
|
|||||||
|
|
||||||
return [get_product(self.currency, ticker) for ticker in tickers]
|
return [get_product(self.currency, ticker) for ticker in tickers]
|
||||||
|
|
||||||
def get_all_products(self) -> list[ProductInfo]:
|
|
||||||
all_tickers = self.client.get_ticker()
|
|
||||||
products = []
|
|
||||||
|
|
||||||
for ticker in all_tickers:
|
|
||||||
# Filtra solo i simboli che terminano con la valuta di default
|
|
||||||
if ticker['symbol'].endswith(self.currency):
|
|
||||||
product = get_product(self.currency, ticker)
|
|
||||||
products.append(product)
|
|
||||||
return products
|
|
||||||
|
|
||||||
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
||||||
symbol = self.__format_symbol(asset_id)
|
symbol = self.__format_symbol(asset_id)
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ class CoinBaseWrapper(BaseWrapper):
|
|||||||
assets = self.client.get_products(product_ids=all_asset_ids)
|
assets = self.client.get_products(product_ids=all_asset_ids)
|
||||||
return [get_product(asset) for asset in assets.products]
|
return [get_product(asset) for asset in assets.products]
|
||||||
|
|
||||||
def get_all_products(self) -> list[ProductInfo]:
|
|
||||||
assets = self.client.get_products()
|
|
||||||
return [get_product(asset) for asset in assets.products]
|
|
||||||
|
|
||||||
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
||||||
asset_id = self.__format(asset_id)
|
asset_id = self.__format(asset_id)
|
||||||
end_time = datetime.now()
|
end_time = datetime.now()
|
||||||
|
|||||||
@@ -67,10 +67,6 @@ class CryptoCompareWrapper(BaseWrapper):
|
|||||||
assets.append(get_product(asset_data))
|
assets.append(get_product(asset_data))
|
||||||
return assets
|
return assets
|
||||||
|
|
||||||
def get_all_products(self) -> list[ProductInfo]:
|
|
||||||
# TODO serve davvero il workaroud qui? Possiamo prendere i dati da un altro endpoint intanto
|
|
||||||
raise NotImplementedError("get_all_products is not supported by CryptoCompare API")
|
|
||||||
|
|
||||||
def get_historical_prices(self, asset_id: str, limit: int = 100) -> list[dict]:
|
def get_historical_prices(self, asset_id: str, limit: int = 100) -> list[dict]:
|
||||||
response = self.__request("/data/v2/histohour", params = {
|
response = self.__request("/data/v2/histohour", params = {
|
||||||
"fsym": asset_id,
|
"fsym": asset_id,
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ class YFinanceWrapper(BaseWrapper):
|
|||||||
products.append(product)
|
products.append(product)
|
||||||
return products
|
return products
|
||||||
|
|
||||||
def get_all_products(self) -> list[ProductInfo]:
|
|
||||||
raise NotImplementedError("YFinanceWrapper does not support get_all_products due to API limitations.")
|
|
||||||
|
|
||||||
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
def get_historical_prices(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
||||||
symbol = self._format_symbol(asset_id)
|
symbol = self._format_symbol(asset_id)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class TestMarketAPIsTool:
|
|||||||
assert market_wrapper is not None
|
assert market_wrapper is not None
|
||||||
assert hasattr(market_wrapper, 'get_product')
|
assert hasattr(market_wrapper, 'get_product')
|
||||||
assert hasattr(market_wrapper, 'get_products')
|
assert hasattr(market_wrapper, 'get_products')
|
||||||
assert hasattr(market_wrapper, 'get_all_products')
|
|
||||||
assert hasattr(market_wrapper, 'get_historical_prices')
|
assert hasattr(market_wrapper, 'get_historical_prices')
|
||||||
|
|
||||||
def test_wrapper_capabilities(self):
|
def test_wrapper_capabilities(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user