Skip to content

Commit

Permalink
ship
Browse files Browse the repository at this point in the history
  • Loading branch information
ashioyajotham committed Jan 12, 2025
1 parent 2a312ac commit 5b96378
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
62 changes: 62 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions todos.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5b96378

Please sign in to comment.