Spaces:
Runtime error
Runtime error
| // Trading module placeholder | |
| // This would contain Nautilus Trader strategy integration | |
| use serde::{Deserialize, Serialize}; | |
| pub struct StrategyConfig { | |
| pub name: String, | |
| pub symbols: Vec<String>, | |
| pub capital: f64, | |
| pub risk_per_trade: f64, | |
| pub max_positions: usize, | |
| } | |
| impl Default for StrategyConfig { | |
| fn default() -> Self { | |
| Self { | |
| name: "RapidAgentStrategy".to_string(), | |
| symbols: vec![ | |
| "BTCUSDT".to_string(), | |
| "ETHUSDT".to_string(), | |
| "SOLUSDT".to_string(), | |
| ], | |
| capital: 10000.0, | |
| risk_per_trade: 0.02, | |
| max_positions: 3, | |
| } | |
| } | |
| } | |
| pub struct TradingStrategy { | |
| config: StrategyConfig, | |
| } | |
| impl TradingStrategy { | |
| pub fn new(config: StrategyConfig) -> Self { | |
| Self { config } | |
| } | |
| pub fn should_entry(&self, symbol: &str, rsi: f64, trend: &str) -> bool { | |
| if rsi < 30.0 && trend == "bullish" { | |
| return true; | |
| } | |
| if rsi < 40.0 && trend == "bullish" { | |
| return true; | |
| } | |
| false | |
| } | |
| pub fn should_exit(&self, symbol: &str, rsi: f64, pnl_percent: f64) -> bool { | |
| if rsi > 70.0 { | |
| return true; | |
| } | |
| if pnl_percent >= self.config.risk_per_trade * 5.0 { | |
| return true; | |
| } | |
| if pnl_percent <= -self.config.risk_per_trade * 2.0 { | |
| return true; | |
| } | |
| false | |
| } | |
| pub fn calculate_position_size(&self, capital: f64, entry: f64, stop_loss: f64) -> f64 { | |
| let risk_amount = capital * self.config.risk_per_trade; | |
| let risk_per_unit = (entry - stop_loss).abs() / entry; | |
| risk_amount / risk_per_unit | |
| } | |
| } | |