bot_engine/
sync_traits.rs1use bot_core::{AccountState, Fill};
7use rust_decimal::Decimal;
8
9use crate::account_syncer::SyncError;
10use crate::performance_metrics::PerformanceMetricsSnapshot;
11
12#[derive(Debug, Clone)]
14pub struct TradeSyncResult {
15 pub success: bool,
17 pub pnl: Option<f64>,
19}
20
21#[async_trait::async_trait]
25pub trait TradeSync: Send + Sync {
26 fn add_fill(&mut self, fill: Fill);
28
29 fn should_sync(&self) -> bool;
31
32 fn pending_count(&self) -> usize;
34
35 fn last_pnl(&self) -> Option<f64>;
37
38 fn set_metrics_snapshot(&mut self, _snapshot: Option<PerformanceMetricsSnapshot>) {}
40
41 async fn sync(
43 &mut self,
44 current_price: Option<Decimal>,
45 stop_bot: bool,
46 stop_reason: &str,
47 ) -> Result<TradeSyncResult, SyncError>;
48
49 async fn shutdown_sync(
51 &mut self,
52 current_price: Option<Decimal>,
53 stop_reason: &str,
54 ) -> Result<TradeSyncResult, SyncError>;
55}
56
57#[derive(Debug, Clone)]
59pub struct AccountSyncResult {
60 pub success: bool,
62 pub pnl: Option<f64>,
64}
65
66#[async_trait::async_trait]
70pub trait AccountSync: Send + Sync {
71 fn should_sync(&self) -> bool;
73
74 fn last_pnl(&self) -> Option<f64>;
76
77 fn set_metrics_snapshot(&mut self, _snapshot: Option<PerformanceMetricsSnapshot>) {}
79
80 async fn sync(
82 &mut self,
83 account_state: &AccountState,
84 stop_bot: bool,
85 stop_reason: &str,
86 ) -> Result<AccountSyncResult, SyncError>;
87
88 async fn shutdown_sync(
90 &mut self,
91 account_state: &AccountState,
92 stop_reason: &str,
93 ) -> Result<AccountSyncResult, SyncError>;
94}