From ebd427501797bb30b0dadcf69c396f2dd267dfd6 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Wed, 1 Oct 2025 21:14:09 +0200 Subject: [PATCH] refactor: remove get_all_products method from market API wrappers and update documentation --- README.md | 2 ++ demos/market_providers_api_demo.py | 18 ------------- src/app/markets/__init__.py | 26 ++++++++++++++----- src/app/markets/base.py | 8 ------ src/app/markets/binance.py | 11 -------- src/app/markets/coinbase.py | 4 --- src/app/markets/cryptocompare.py | 4 --- src/app/markets/yfinance.py | 3 --- tests/tools/test_market_tool.py | 1 - ...ggregator.py => test_market_aggregator.py} | 0 10 files changed, 21 insertions(+), 56 deletions(-) rename tests/utils/{test_market_data_aggregator.py => test_market_aggregator.py} (100%) diff --git a/README.md b/README.md index 95981f3..a545c92 100644 --- a/README.md +++ b/README.md @@ -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).\ 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** 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. diff --git a/demos/market_providers_api_demo.py b/demos/market_providers_api_demo.py index 8c368e8..393a478 100644 --- a/demos/market_providers_api_demo.py +++ b/demos/market_providers_api_demo.py @@ -186,24 +186,6 @@ class ProviderTester: results["tests"]["get_products"] = f"ERROR: {error_msg}" 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 timestamp = datetime.now() try: diff --git a/src/app/markets/__init__.py b/src/app/markets/__init__.py index d0eb6ad..6f09b2f 100644 --- a/src/app/markets/__init__.py +++ b/src/app/markets/__init__.py @@ -12,14 +12,29 @@ __all__ = [ "MarketAPIs", "BinanceWrapper", "CoinBaseWrapper", "CryptoCompareWra class MarketAPIsTool(BaseWrapper, Toolkit): """ - Classe per comporre più MarketAPI con gestione degli errori e aggregazione dei dati. - Usa WrapperHandler per gestire più API con logica di retry e failover. - Si può scegliere se aggregare i dati da tutte le fonti o usare una singola fonte tramite delle chiamate apposta. + Class that aggregates multiple market API wrappers and manages them using WrapperHandler. + This class supports retrieving product information and historical prices. + 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"): + """ + 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"} - wrappers = [ BinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper, YFinanceWrapper ] + wrappers = [ BinanceWrapper, YFinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper ] self.wrappers: WrapperHandler[BaseWrapper] = WrapperHandler.build_wrappers(wrappers, kwargs=kwargs) Toolkit.__init__( @@ -28,7 +43,6 @@ class MarketAPIsTool(BaseWrapper, Toolkit): tools=[ self.get_product, self.get_products, - self.get_all_products, self.get_historical_prices, self.get_products_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)) def get_products(self, asset_ids: list[str]) -> list[ProductInfo]: 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]: return self.wrappers.try_call(lambda w: w.get_historical_prices(asset_id, limit)) diff --git a/src/app/markets/base.py b/src/app/markets/base.py index 5761675..12892bb 100644 --- a/src/app/markets/base.py +++ b/src/app/markets/base.py @@ -26,14 +26,6 @@ class BaseWrapper: """ 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']: """ Get historical price data for a specific asset ID. diff --git a/src/app/markets/binance.py b/src/app/markets/binance.py index d5dfe10..2eb85f0 100644 --- a/src/app/markets/binance.py +++ b/src/app/markets/binance.py @@ -54,17 +54,6 @@ class BinanceWrapper(BaseWrapper): 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]: symbol = self.__format_symbol(asset_id) diff --git a/src/app/markets/coinbase.py b/src/app/markets/coinbase.py index 286ec6f..9e4c64d 100644 --- a/src/app/markets/coinbase.py +++ b/src/app/markets/coinbase.py @@ -73,10 +73,6 @@ class CoinBaseWrapper(BaseWrapper): assets = self.client.get_products(product_ids=all_asset_ids) 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]: asset_id = self.__format(asset_id) end_time = datetime.now() diff --git a/src/app/markets/cryptocompare.py b/src/app/markets/cryptocompare.py index c81a3bb..98e5284 100644 --- a/src/app/markets/cryptocompare.py +++ b/src/app/markets/cryptocompare.py @@ -67,10 +67,6 @@ class CryptoCompareWrapper(BaseWrapper): assets.append(get_product(asset_data)) 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]: response = self.__request("/data/v2/histohour", params = { "fsym": asset_id, diff --git a/src/app/markets/yfinance.py b/src/app/markets/yfinance.py index 9e7fcd2..02af2f6 100644 --- a/src/app/markets/yfinance.py +++ b/src/app/markets/yfinance.py @@ -62,9 +62,6 @@ class YFinanceWrapper(BaseWrapper): products.append(product) 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]: symbol = self._format_symbol(asset_id) diff --git a/tests/tools/test_market_tool.py b/tests/tools/test_market_tool.py index 7513585..c6da5a8 100644 --- a/tests/tools/test_market_tool.py +++ b/tests/tools/test_market_tool.py @@ -11,7 +11,6 @@ class TestMarketAPIsTool: assert market_wrapper is not None assert hasattr(market_wrapper, 'get_product') assert hasattr(market_wrapper, 'get_products') - assert hasattr(market_wrapper, 'get_all_products') assert hasattr(market_wrapper, 'get_historical_prices') def test_wrapper_capabilities(self): diff --git a/tests/utils/test_market_data_aggregator.py b/tests/utils/test_market_aggregator.py similarity index 100% rename from tests/utils/test_market_data_aggregator.py rename to tests/utils/test_market_aggregator.py