This commit is contained in:
2026-03-02 01:36:14 -04:00
parent d907c5765e
commit 311df9aeda
21 changed files with 2772 additions and 33 deletions

View File

@@ -0,0 +1,97 @@
"""
Example: Integrating CCXT DataSource into main.py
This shows how to register a CCXT exchange datasource in your application.
"""
# In your backend/src/main.py, add this to the lifespan function:
"""
from datasource.adapters.ccxt_adapter import CCXTDataSource
@asynccontextmanager
async def lifespan(app: FastAPI):
global agent_executor
# Initialize data sources
demo_source = DemoDataSource()
datasource_registry.register("demo", demo_source)
subscription_manager.register_source("demo", demo_source)
# Add CCXT Binance datasource
binance_source = CCXTDataSource(
exchange_id="binance",
poll_interval=60, # Poll every 60 seconds for updates
)
datasource_registry.register("binance", binance_source)
subscription_manager.register_source("binance", binance_source)
# Add CCXT Coinbase datasource
coinbase_source = CCXTDataSource(
exchange_id="coinbase",
poll_interval=60,
)
datasource_registry.register("coinbase", coinbase_source)
subscription_manager.register_source("coinbase", coinbase_source)
# Add CCXT Kraken datasource
kraken_source = CCXTDataSource(
exchange_id="kraken",
poll_interval=60,
)
datasource_registry.register("kraken", kraken_source)
subscription_manager.register_source("kraken", kraken_source)
logger.info("DataSource infrastructure initialized with demo + CCXT sources")
# ... rest of initialization ...
yield
# Cleanup
await binance_source.close()
await coinbase_source.close()
await kraken_source.close()
# ... rest of cleanup ...
"""
# Usage examples:
# 1. Connect to datafeed WebSocket and request Binance data:
"""
{
"type": "request",
"source": "binance",
"method": "search_symbols",
"params": {
"query": "BTC"
}
}
"""
# 2. Get historical bars from Binance:
"""
{
"type": "request",
"source": "binance",
"method": "get_bars",
"params": {
"symbol": "BTC/USDT",
"resolution": "60",
"from_time": 1234567890,
"to_time": 1234567999
}
}
"""
# 3. Subscribe to polling updates:
"""
{
"type": "subscribe",
"source": "binance",
"symbol": "BTC/USDT",
"resolution": "1"
}
"""
print("See comments above for integration examples!")