refactor: remove get_all_products method from market API wrappers and update documentation

This commit is contained in:
2025-10-01 21:14:09 +02:00
parent 9c471948ff
commit ebd4275017
10 changed files with 21 additions and 56 deletions

View File

@@ -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))

View File

@@ -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.

View File

@@ -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)

View File

@@ -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()

View File

@@ -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,

View File

@@ -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)