Skip to main content

sandbox_quant/strategy/
model.rs

1use chrono::{DateTime, Utc};
2
3use crate::app::bootstrap::BinanceMode;
4use crate::domain::instrument::Instrument;
5use crate::strategy::command::StrategyStartConfig;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum StrategyTemplate {
9    LiquidationBreakdownShort,
10}
11
12impl StrategyTemplate {
13    pub fn slug(self) -> &'static str {
14        match self {
15            Self::LiquidationBreakdownShort => "liquidation-breakdown-short",
16        }
17    }
18
19    pub fn steps(self) -> &'static [&'static str; 7] {
20        match self {
21            Self::LiquidationBreakdownShort => &[
22                "Find a liquidation cluster above current price",
23                "Wait for price to trade into that cluster",
24                "Detect failure to hold above the sweep area",
25                "Confirm downside continuation",
26                "Enter short from best bid/ask with slippage cap",
27                "Place reduce-only stop loss and take profit from actual fill",
28                "End the strategy after exchange protection is live",
29            ],
30        }
31    }
32
33    pub fn all() -> [Self; 1] {
34        [Self::LiquidationBreakdownShort]
35    }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum StrategyWatchState {
40    Armed,
41    Triggered,
42    Completed,
43    Failed,
44    Stopped,
45}
46
47impl StrategyWatchState {
48    pub fn as_str(self) -> &'static str {
49        match self {
50            Self::Armed => "armed",
51            Self::Triggered => "triggered",
52            Self::Completed => "completed",
53            Self::Failed => "failed",
54            Self::Stopped => "stopped",
55        }
56    }
57}
58
59#[derive(Debug, Clone, PartialEq)]
60pub struct StrategyWatch {
61    pub id: u64,
62    pub mode: BinanceMode,
63    pub template: StrategyTemplate,
64    pub instrument: Instrument,
65    pub state: StrategyWatchState,
66    pub current_step: usize,
67    pub config: StrategyStartConfig,
68    pub created_at: DateTime<Utc>,
69    pub updated_at: DateTime<Utc>,
70}
71
72impl StrategyWatch {
73    pub fn new(
74        id: u64,
75        mode: BinanceMode,
76        template: StrategyTemplate,
77        instrument: Instrument,
78        config: StrategyStartConfig,
79    ) -> Self {
80        let now = Utc::now();
81        Self {
82            id,
83            mode,
84            template,
85            instrument,
86            state: StrategyWatchState::Armed,
87            current_step: 1,
88            config,
89            created_at: now,
90            updated_at: now,
91        }
92    }
93}