workspace/projects/trading-platform/apps/trading-agents/example_usage.py
rckrdmrd ea1879f4ad feat: Initial workspace structure with multi-level Git configuration
- Configure workspace Git repository with comprehensive .gitignore
- Add Odoo as submodule for ERP reference code
- Include documentation: SETUP.md, GIT-STRUCTURE.md
- Add gitignore templates for projects (backend, frontend, database)
- Structure supports independent repos per project/subproject level

Workspace includes:
- core/ - Reusable patterns, modules, orchestration system
- projects/ - Active projects (erp-suite, gamilit, trading-platform, etc.)
- knowledge-base/ - Reference code and patterns (includes Odoo submodule)
- devtools/ - Development tools and templates
- customers/ - Client implementations template

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 10:44:23 -06:00

216 lines
6.0 KiB
Python

"""
Example Usage of Trading Agents
This script demonstrates how to use the trading agents system.
"""
import asyncio
import logging
from src.agents.atlas import AtlasAgent
from src.agents.orion import OrionAgent
from src.agents.nova import NovaAgent
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
async def example_atlas_agent():
"""
Example: Running Atlas agent (Conservative)
"""
print("\n" + "="*60)
print("Example 1: Atlas Agent (Conservative)")
print("="*60)
# Create agent with $1000 initial equity
agent = AtlasAgent(equity=1000.0)
# Start the agent
await agent.start()
print(f"\nAgent Status: {agent.status.value}")
print(f"Initial Equity: ${agent.equity:.2f}")
print(f"Allowed Pairs: {agent.config.allowed_pairs}")
print(f"Max Positions: {agent.config.max_positions}")
print(f"Max Drawdown: {agent.config.max_drawdown}%")
# Simulate receiving a BUY signal
print("\n--- Simulating BUY signal for BTCUSDT ---")
signal = {
'symbol': 'BTCUSDT',
'action': 'buy',
'confidence': 0.85,
'price': 45000.0
}
await agent.on_signal(signal)
# Check metrics
print("\n--- Agent Metrics ---")
metrics = agent.get_metrics()
for key, value in metrics.items():
print(f"{key}: {value}")
# Stop the agent
await agent.stop()
async def example_orion_agent():
"""
Example: Running Orion agent (Moderate)
"""
print("\n" + "="*60)
print("Example 2: Orion Agent (Moderate)")
print("="*60)
# Create agent
agent = OrionAgent(equity=5000.0)
await agent.start()
print(f"\nAgent: {agent.config.name}")
print(f"Profile: {agent.config.profile.value}")
print(f"Equity: ${agent.equity:.2f}")
# Simulate multiple signals
signals = [
{'symbol': 'BTCUSDT', 'action': 'buy', 'confidence': 0.75, 'price': 45000.0},
{'symbol': 'ETHUSDT', 'action': 'buy', 'confidence': 0.70, 'price': 2800.0},
{'symbol': 'BNBUSDT', 'action': 'buy', 'confidence': 0.68, 'price': 350.0},
]
print("\n--- Processing signals ---")
for signal in signals:
print(f"\nSignal: {signal['symbol']} {signal['action']} @ ${signal['price']:.2f}")
await agent.on_signal(signal)
# Show positions
print(f"\n--- Open Positions: {len(agent.positions)} ---")
for pos in agent.positions:
print(f" {pos.symbol}: {pos.side.upper()} {pos.quantity:.6f} @ ${pos.entry_price:.2f}")
print(f" SL: ${pos.stop_loss:.2f}, TP: ${pos.take_profit:.2f}")
await agent.stop()
async def example_nova_agent():
"""
Example: Running Nova agent (Aggressive)
"""
print("\n" + "="*60)
print("Example 3: Nova Agent (Aggressive)")
print("="*60)
# Create agent
agent = NovaAgent(equity=10000.0)
await agent.start()
print(f"\nAgent: {agent.config.name}")
print(f"Profile: {agent.config.profile.value}")
print(f"Max Trades/Day: {agent.config.max_trades_per_day}")
print(f"Max Positions: {agent.config.max_positions}")
# Simulate high-frequency signals
print("\n--- Processing multiple signals ---")
for i in range(5):
signal = {
'symbol': f"{['BTC', 'ETH', 'BNB', 'ADA', 'XRP'][i]}USDT",
'action': 'buy',
'confidence': 0.60 + (i * 0.05),
'price': 100.0 * (i + 1)
}
print(f"Signal {i+1}: {signal['symbol']} {signal['action']}")
await agent.on_signal(signal)
# Show metrics
metrics = agent.get_metrics()
print(f"\n--- Metrics ---")
print(f"Total Trades: {metrics['total_trades']}")
print(f"Positions: {metrics['positions']}")
print(f"Win Rate: {metrics['win_rate']:.2f}%")
await agent.stop()
async def example_risk_management():
"""
Example: Risk management in action
"""
print("\n" + "="*60)
print("Example 4: Risk Management")
print("="*60)
agent = AtlasAgent(equity=1000.0)
await agent.start()
# Test 1: Max positions limit
print("\n--- Test: Max Positions Limit ---")
for i in range(5): # Try to open 5 positions (max is 3 for Atlas)
signal = {
'symbol': f"TEST{i}USDT",
'action': 'buy',
'confidence': 0.85,
'price': 100.0
}
can_open = agent.can_open_position()
print(f"Position {i+1}: {'✓ Can open' if can_open else '✗ Cannot open (max reached)'}")
if can_open:
# Manually add position for testing
from src.agents.base import Position
pos = Position(
symbol=signal['symbol'],
side='buy',
quantity=0.01,
entry_price=signal['price'],
current_price=signal['price']
)
agent.add_position(pos)
# Test 2: Drawdown limit
print("\n--- Test: Drawdown Limit ---")
agent.update_equity(1000.0) # Reset
agent.peak_equity = 1000.0
print(f"Initial: Equity=${agent.equity:.2f}, Peak=${agent.peak_equity:.2f}")
# Simulate losses
agent.update_equity(970.0) # -3%
print(f"After -3% loss: Drawdown={agent.metrics.current_drawdown:.2f}%")
agent.update_equity(950.0) # -5%
print(f"After -5% loss: Drawdown={agent.metrics.current_drawdown:.2f}%")
# Check if can trade
can_trade = await agent.check_risk_limits()
print(f"Can trade: {'✓ Yes' if can_trade else '✗ No (max drawdown reached)'}")
await agent.stop()
async def main():
"""Run all examples"""
print("\n" + "="*60)
print("OrbiQuant Trading Agents - Usage Examples")
print("="*60)
# Run examples
await example_atlas_agent()
await asyncio.sleep(1)
await example_orion_agent()
await asyncio.sleep(1)
await example_nova_agent()
await asyncio.sleep(1)
await example_risk_management()
print("\n" + "="*60)
print("All examples completed!")
print("="*60 + "\n")
if __name__ == "__main__":
asyncio.run(main())