fix market tool
This commit is contained in:
@@ -96,9 +96,6 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
|
|||||||
and combines the data using volume-weighted average price (VWAP) to provide
|
and combines the data using volume-weighted average price (VWAP) to provide
|
||||||
the most accurate and comprehensive price data.
|
the most accurate and comprehensive price data.
|
||||||
|
|
||||||
Use this when you need highly reliable price data from multiple sources.
|
|
||||||
Warning: This uses more API calls (4x) than get_product().
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
asset_id (str): The asset ID to retrieve information for (e.g., "BTC", "ETH").
|
asset_id (str): The asset ID to retrieve information for (e.g., "BTC", "ETH").
|
||||||
|
|
||||||
@@ -108,15 +105,8 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
Exception: If all providers fail to return results.
|
Exception: If all providers fail to return results.
|
||||||
|
|
||||||
Example:
|
|
||||||
>>> tool.get_product_aggregated("BTC")
|
|
||||||
ProductInfo(symbol="BTC", price=45123.50, provider="Binance, YFinance, Coinbase", ...)
|
|
||||||
"""
|
"""
|
||||||
# try_call_all returns dict[str, ProductInfo] where key is provider name
|
return self.get_products_aggregated([asset_id])[0]
|
||||||
# We need list[ProductInfo] for aggregation, so we extract values
|
|
||||||
all_products = self.handler.try_call_all(lambda w: w.get_product(asset_id))
|
|
||||||
return ProductInfo.aggregate_single_asset(all_products)
|
|
||||||
|
|
||||||
def get_products_aggregated(self, asset_ids: list[str]) -> list[ProductInfo]:
|
def get_products_aggregated(self, asset_ids: list[str]) -> list[ProductInfo]:
|
||||||
"""
|
"""
|
||||||
@@ -135,9 +125,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
|
|||||||
Raises:
|
Raises:
|
||||||
Exception: If all providers fail to return results.
|
Exception: If all providers fail to return results.
|
||||||
"""
|
"""
|
||||||
all_products: dict[str, list[ProductInfo]] = {}
|
all_products = self.handler.try_call_all(lambda w: w.get_products(asset_ids))
|
||||||
for asset in asset_ids:
|
|
||||||
all_products[asset] = self.handler.try_call_all(lambda w: w.get_product(asset))
|
|
||||||
return ProductInfo.aggregate_multi_assets(all_products)
|
return ProductInfo.aggregate_multi_assets(all_products)
|
||||||
|
|
||||||
def get_historical_prices_aggregated(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
def get_historical_prices_aggregated(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
|
||||||
|
|||||||
Reference in New Issue
Block a user