sandbox_quant/strategy/
model.rs1use 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 PriceSmaCrossLong,
11}
12
13impl StrategyTemplate {
14 pub fn slug(self) -> &'static str {
15 match self {
16 Self::LiquidationBreakdownShort => "liquidation-breakdown-short",
17 Self::PriceSmaCrossLong => "price-sma-cross-long",
18 }
19 }
20
21 pub fn steps(self) -> &'static [&'static str; 7] {
22 match self {
23 Self::LiquidationBreakdownShort => &[
24 "Find a liquidation cluster above current price",
25 "Wait for price to trade into that cluster",
26 "Detect failure to hold above the sweep area",
27 "Confirm downside continuation",
28 "Enter short from best bid/ask with slippage cap",
29 "Place reduce-only stop loss and take profit from actual fill",
30 "End the strategy after exchange protection is live",
31 ],
32 Self::PriceSmaCrossLong => &[
33 "Read historical trend state from price bars",
34 "Track moving-average cross signals",
35 "Enter long after confirmed bullish cross",
36 "Apply configured stop and take-profit bounds",
37 "Manage the position until exit",
38 "Record realized PnL for the completed trade",
39 "Close any remaining position at the end of the window",
40 ],
41 }
42 }
43
44 pub fn all() -> [Self; 1] {
45 [Self::LiquidationBreakdownShort]
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum StrategyWatchState {
51 Armed,
52 Triggered,
53 Completed,
54 Failed,
55 Stopped,
56}
57
58impl StrategyWatchState {
59 pub fn as_str(self) -> &'static str {
60 match self {
61 Self::Armed => "armed",
62 Self::Triggered => "triggered",
63 Self::Completed => "completed",
64 Self::Failed => "failed",
65 Self::Stopped => "stopped",
66 }
67 }
68}
69
70#[derive(Debug, Clone, PartialEq)]
71pub struct StrategyWatch {
72 pub id: u64,
73 pub mode: BinanceMode,
74 pub template: StrategyTemplate,
75 pub instrument: Instrument,
76 pub state: StrategyWatchState,
77 pub current_step: usize,
78 pub config: StrategyStartConfig,
79 pub created_at: DateTime<Utc>,
80 pub updated_at: DateTime<Utc>,
81}
82
83impl StrategyWatch {
84 pub fn new(
85 id: u64,
86 mode: BinanceMode,
87 template: StrategyTemplate,
88 instrument: Instrument,
89 config: StrategyStartConfig,
90 ) -> Self {
91 let now = Utc::now();
92 Self {
93 id,
94 mode,
95 template,
96 instrument,
97 state: StrategyWatchState::Armed,
98 current_step: 1,
99 config,
100 created_at: now,
101 updated_at: now,
102 }
103 }
104}