From dc326acf855709a1d5a5a86d6e88f4c72c0e508c Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 5 Aug 2025 17:36:58 +0300 Subject: [PATCH] launch configs --- .vscode/launch.json | 109 ++++++++++++++++++++++++++++++++++++++++++++ COBY/main.py | 73 ++++++++++++++++++++--------- 2 files changed, 161 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 03722b5..359ce44 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -190,6 +190,91 @@ "group": "Universal Data Stream", "order": 2 } + }, + { + "name": "🌐 COBY Multi-Exchange Data Aggregation", + "type": "python", + "request": "launch", + "program": "COBY/main.py", + "console": "integratedTerminal", + "justMyCode": false, + "env": { + "PYTHONUNBUFFERED": "1", + "COBY_API_HOST": "0.0.0.0", + "COBY_API_PORT": "8080", + "COBY_WEBSOCKET_PORT": "8081" + }, + "preLaunchTask": "Kill Stale Processes", + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 1 + } + }, + { + "name": "🔍 COBY Debug Mode", + "type": "python", + "request": "launch", + "program": "COBY/main.py", + "args": [ + "--debug" + ], + "console": "integratedTerminal", + "justMyCode": false, + "env": { + "PYTHONUNBUFFERED": "1", + "COBY_API_HOST": "localhost", + "COBY_API_PORT": "8080", + "COBY_WEBSOCKET_PORT": "8081", + "COBY_LOG_LEVEL": "DEBUG" + }, + "preLaunchTask": "Kill Stale Processes", + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 2 + } + }, + { + "name": "🔧 COBY Development Mode (Auto-reload)", + "type": "python", + "request": "launch", + "program": "COBY/main.py", + "args": [ + "--debug", + "--reload" + ], + "console": "integratedTerminal", + "justMyCode": false, + "env": { + "PYTHONUNBUFFERED": "1", + "COBY_API_HOST": "localhost", + "COBY_API_PORT": "8080", + "COBY_WEBSOCKET_PORT": "8081", + "COBY_LOG_LEVEL": "DEBUG" + }, + "preLaunchTask": "Kill Stale Processes", + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 3 + } + }, + { + "name": "🏥 COBY Health Check", + "type": "python", + "request": "launch", + "program": "COBY/health_check.py", + "console": "integratedTerminal", + "justMyCode": false, + "env": { + "PYTHONUNBUFFERED": "1" + }, + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 4 + } } ], @@ -261,6 +346,30 @@ "order": 5 } }, + { + "name": "🌐 COBY Multi-Exchange System (Full Stack)", + "configurations": [ + "🌐 COBY Multi-Exchange Data Aggregation" + ], + "stopAll": true, + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 6 + } + }, + { + "name": "🔧 COBY Development Environment", + "configurations": [ + "🔧 COBY Development Mode (Auto-reload)" + ], + "stopAll": true, + "presentation": { + "hidden": false, + "group": "COBY System", + "order": 7 + } + } ] } diff --git a/COBY/main.py b/COBY/main.py index e6b4e5c..dc1c2f4 100644 --- a/COBY/main.py +++ b/COBY/main.py @@ -75,11 +75,13 @@ class COBYApplication: ) self.tasks.append(api_task) - # Start exchange connectors (placeholder for now) - logger.info("Exchange connectors would start here...") + # Start exchange connectors + logger.info("Starting exchange connectors...") + await self._start_exchange_connectors() - # Start data processing pipeline (placeholder for now) - logger.info("Data processing pipeline would start here...") + # Start data processing pipeline + logger.info("Starting data processing pipeline...") + await self._start_data_processing() self.running = True logger.info("COBY system started successfully") @@ -123,26 +125,55 @@ class COBYApplication: except Exception as e: logger.error(f"Error stopping COBY application: {e}") - async def _run_api_server(self, app, host: str, port: int): - """Run the API server""" + async def _start_exchange_connectors(self): + """Start exchange connectors""" try: - # Import here to avoid circular imports - import uvicorn + # Import connectors + from connectors.binance_connector import BinanceConnector + from connectors.kucoin_connector import KucoinConnector + from connectors.coinbase_connector import CoinbaseConnector - config = uvicorn.Config( - app, - host=host, - port=port, - log_level="info", - access_log=True - ) - server = uvicorn.Server(config) - await server.serve() + # Initialize connectors + self.connectors = { + 'binance': BinanceConnector(), + 'kucoin': KucoinConnector(), + 'coinbase': CoinbaseConnector() + } - except ImportError: - logger.error("uvicorn not available, falling back to basic server") - # Fallback implementation would go here - await asyncio.sleep(3600) # Keep running for an hour + # Start connectors + for name, connector in self.connectors.items(): + try: + logger.info(f"Starting {name} connector...") + connector_task = asyncio.create_task(self._run_connector(connector)) + self.tasks.append(connector_task) + except Exception as e: + logger.error(f"Failed to start {name} connector: {e}") + + except Exception as e: + logger.error(f"Error starting exchange connectors: {e}") + + async def _run_connector(self, connector): + """Run a single connector""" + try: + # Connect to exchange + if await connector.connect(): + logger.info(f"Connected to {connector.exchange_name}") + + # Subscribe to default symbols + default_symbols = ['BTCUSDT', 'ETHUSDT', 'ADAUSDT', 'SOLUSDT'] + for symbol in default_symbols: + try: + await connector.subscribe_orderbook(symbol) + await connector.subscribe_trades(symbol) + logger.info(f"Subscribed to {symbol} on {connector.exchange_name}") + except Exception as e: + logger.warning(f"Failed to subscribe to {symbol} on {connector.exchange_name}: {e}") + + # Keep connector running + while connector.is_connected: + await asyncio.sleep(1) + + async def main():