File size: 1,795 Bytes
8294aff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Trading module placeholder
// This would contain Nautilus Trader strategy integration

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
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
    }
}