3 market api (#8)

* Creazione branch tool, refactor degli import e soppressione dei warning

* Update pytest configuration and dependencies in pyproject.toml

* Add news API integration and related configurations

- Update .env.example to include NEWS_API_KEY configuration
- Add newsapi-python dependency in pyproject.toml
- Implement NewsAPI class for fetching news articles
- Create Article model for structured news data
- Add tests for NewsAPI functionality in test_news_api.py
- Update pytest configuration to include news marker

* Add news API functionality and update tests for article retrieval

* ToDo:
1. Aggiungere un aggregator per i dati recuperati dai provider.
2. Lavorare effettivamente all'issue

Done:
1. creati test per i provider
2. creato market_providers_api_demo.py per mostrare i dati recuperati dalle api dei providers
3. aggiornato i provider
4. creato il provider binance sia pubblico che con chiave
5. creato error_handler.py per gestire decoratori e utilità: retry automatico, gestione timeout...

* Refactor news API integration to use NewsApiWrapper and GnewsWrapper; add tests for Gnews API functionality

* Add CryptoPanic API integration and related tests; update .env.example and test configurations

* Implement WrapperHandler for managing multiple news API wrappers; add tests for wrapper functionality

* Enhance WrapperHandler
- docstrings
- add try_call_all method
- update tests

* pre merge con phil

* Add DuckDuckGo and Google News wrappers; refactor CryptoPanic and NewsAPI

- Implemented DuckDuckGoWrapper for news retrieval using DuckDuckGo tools.
- Added GoogleNewsWrapper for accessing Google News RSS feed.
- Refactored CryptoPanicWrapper to unify get_top_headlines and get_latest_news methods.
- Updated NewsApiWrapper to simplify top headlines retrieval.
- Added tests for DuckDuckGo and Google News wrappers.
- Enhanced documentation for CryptoPanicWrapper and NewsApiWrapper.
- Created base module for social media integrations.

* - Refactor struttura progetto: divisione tra agent e toolkit

* Refactor try_call_all method to return a dictionary of results; update tests for success and partial failures

* Fix class and test method names for DuckDuckGoWrapper

* Add Reddit API wrapper and related tests; update environment configuration

* pre merge con giacomo

* Fix import statements

* Fixes
- separated tests
- fix tests
- fix bugs reintroduced my previous merge

* Refactor market API wrappers to streamline product and price retrieval methods

* Add BinanceWrapper to market API exports

* Finito ISSUE 3

* Final review
- rm PublicBinanceAgent & updated demo
- moved in the correct folder some tests
- fix binance bug

---------

Co-authored-by: trojanhorse47 <cosmomemory@hotmail.it>
Co-authored-by: Berack96 <giacomobertolazzi7@gmail.com>
Co-authored-by: Giacomo Bertolazzi <31776951+Berack96@users.noreply.github.com>
This commit was merged in pull request #8.
This commit is contained in:
Simo
2025-10-01 15:51:25 +02:00
committed by GitHub
parent 4615ebe63e
commit dc9dc98298
50 changed files with 2673 additions and 671 deletions

View File

@@ -1,18 +1,49 @@
from coinbase.rest.types.product_types import Candle, GetProductResponse
from pydantic import BaseModel
class BaseWrapper:
"""
Interfaccia per i wrapper delle API di mercato.
Implementa i metodi di base che ogni wrapper deve avere.
Base class for market API wrappers.
All market API wrappers should inherit from this class and implement the methods.
"""
def get_product(self, asset_id: str) -> 'ProductInfo':
"""
Get product information for a specific asset ID.
Args:
asset_id (str): The asset ID to retrieve information for.
Returns:
ProductInfo: An object containing product information.
"""
raise NotImplementedError
def get_products(self, asset_ids: list[str]) -> list['ProductInfo']:
"""
Get product information for multiple asset IDs.
Args:
asset_ids (list[str]): The list of asset IDs to retrieve information for.
Returns:
list[ProductInfo]: A list of objects containing product information.
"""
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") -> 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.
Args:
asset_id (str): The asset ID to retrieve price data for.
limit (int): The maximum number of price data points to return.
Returns:
list[Price]: A list of Price objects.
"""
raise NotImplementedError
class ProductInfo(BaseModel):
@@ -27,25 +58,6 @@ class ProductInfo(BaseModel):
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(BaseModel):
"""
Rappresenta i dati di prezzo per un asset, come ottenuti dalle API di mercato.
@@ -57,23 +69,3 @@ class Price(BaseModel):
close: float = 0.0
volume: float = 0.0
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