From 5b9637847c7f78e31eb8f7fc0d1953c04c35ac52 Mon Sep 17 00:00:00 2001 From: ashioyajotham Date: Sun, 12 Jan 2025 09:20:59 +0300 Subject: [PATCH] ship --- main.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ todos.txt | 14 +++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 todos.txt diff --git a/main.py b/main.py index b54f961..d5ea14b 100644 --- a/main.py +++ b/main.py @@ -356,3 +356,65 @@ def _merge_trade_recommendations(self, robo_trades: List[Dict], merged.append(trade) return merged + + async def run(self): + """Main trading loop""" + try: + await self.initialize() + + while self.is_running: + try: + # 1. Get market data + market_data = await self.get_market_data() + + # 2. Detect trading opportunities + signals = await self.detect_inefficiencies(market_data) + + # 3. Generate system trades + system_trades = self.generate_trades(signals) + + # 4. Handle robo-advisory tasks + for client_id in self.client_profiles: + # Generate client-specific trades + robo_trades = await self.generate_client_trades(client_id) + # Execute approved trades + if robo_trades: + await self.execute_trades(robo_trades) + + # 5. Execute system trades + if system_trades: + await self.execute_trades(system_trades) + + # 6. Update portfolio state + await self._update_portfolio_state() + + # 7. Check risk metrics + risk_metrics = self.update_risk_metrics() + if risk_metrics.get('max_drawdown', 0) > self.config['risk']['max_drawdown']: + print("Risk limit exceeded, reducing exposure") + await self._reduce_exposure() + + # 8. Wait for next iteration + await asyncio.sleep(self.config.get('trading', {}).get('loop_interval', 60)) + + except Exception as e: + print(f"Error in trading loop: {str(e)}") + await asyncio.sleep(5) # Brief pause before retrying + + except KeyboardInterrupt: + print("\nShutting down gracefully...") + finally: + await self.shutdown() + +if __name__ == "__main__": + # Load config + config_path = "config/trading.yaml" + + # Create and run trading system + system = TradingSystem(config_path) + + try: + asyncio.run(system.run()) + except Exception as e: + print(f"Fatal error: {str(e)}") + sys.exit(1) diff --git a/todos.txt b/todos.txt new file mode 100644 index 0000000..f476c0c --- /dev/null +++ b/todos.txt @@ -0,0 +1,14 @@ +1. Currently, the trading pairs come from the configuration files: + - `trading.yaml` has the main list of symbols (BTC/USDT, ETH/USDT, BNB/USDT) + - `strategies.yaml` has pairs for inefficiency detection + +2. The system doesn't actually take trading pairs directly from clients. Instead: + - The main system trades the pre-configured pairs from trading.yaml + - The robo-advisor component manages client portfolios using these same pairs + - There's no current mechanism for clients to specify custom trading pairs + +This could be improved by: +1. Adding client-specific trading pair configuration +2. Implementing validation for client-requested trading pairs +3. Adding dynamic pair management +4. Creating separate trading pair pools for system vs client trading \ No newline at end of file