Refactor Predictor and market data handling

- Added Predictor class with input preparation and instructions for financial strategy generation.
- Removed PredictorAgent class and integrated its functionality into the new Predictor module.
- Created a base market API wrapper and specific implementations for Coinbase and CryptoCompare.
- Introduced PublicBinanceAgent for fetching public prices from Binance.
- Refactored ToolAgent to utilize the new Predictor and market API wrappers for improved data handling and predictions.
- Updated models to streamline the selection of available LLM providers.
- Removed deprecated signer classes for Coinbase and CryptoCompare.
This commit is contained in:
2025-09-26 03:43:31 +02:00
parent 48502fc6c7
commit 148bff7cfd
18 changed files with 362 additions and 2324 deletions

67
src/app/markets/base.py Normal file
View File

@@ -0,0 +1,67 @@
from coinbase.rest.types.product_types import Candle, GetProductResponse
class BaseWrapper:
def get_product(self, asset_id: str) -> 'ProductInfo':
raise NotImplementedError
def get_products(self, asset_ids: list[str]) -> list['ProductInfo']:
raise NotImplementedError
def get_all_products(self) -> list['ProductInfo']:
raise NotImplementedError
def get_historical_prices(self, asset_id: str = "BTC") -> list['Price']:
raise NotImplementedError
class ProductInfo:
id: str
symbol: str
price: float
volume_24h: float
status: str
quote_currency: str
def from_coinbase(product_data: GetProductResponse) -> 'ProductInfo':
product = ProductInfo()
product.id = product_data.product_id
product.symbol = product_data.base_currency_id
product.price = float(product_data.price)
product.volume_24h = float(product_data.volume_24h) if product_data.volume_24h else 0
# TODO Check what status means in Coinbase
product.status = product_data.status
return product
def from_cryptocompare(asset_data: dict) -> 'ProductInfo':
product = ProductInfo()
product.id = asset_data['FROMSYMBOL'] + '-' + asset_data['TOSYMBOL']
product.symbol = asset_data['FROMSYMBOL']
product.price = float(asset_data['PRICE'])
product.volume_24h = float(asset_data['VOLUME24HOUR'])
product.status = "" # Cryptocompare does not provide status
return product
class Price:
high: float
low: float
open: float
close: float
volume: float
time: str
def from_coinbase(candle_data: Candle) -> 'Price':
price = Price()
price.high = float(candle_data.high)
price.low = float(candle_data.low)
price.open = float(candle_data.open)
price.close = float(candle_data.close)
price.volume = float(candle_data.volume)
price.time = str(candle_data.start)
return price
def from_cryptocompare(price_data: dict) -> 'Price':
price = Price()
price.high = float(price_data['high'])
price.low = float(price_data['low'])
price.open = float(price_data['open'])
price.close = float(price_data['close'])
price.volume = float(price_data['volumeto'])
price.time = str(price_data['time'])
return price