sandbox_quant/domain/
position.rs1use crate::domain::instrument::Instrument;
2use crate::domain::market::Market;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Side {
6 Buy,
7 Sell,
8}
9
10#[derive(Debug, Clone, PartialEq)]
11pub struct PositionSnapshot {
12 pub instrument: Instrument,
13 pub market: Market,
14 pub signed_qty: f64,
21 pub entry_price: Option<f64>,
22}
23
24impl PositionSnapshot {
25 pub fn side(&self) -> Option<Side> {
26 if self.signed_qty > 0.0 {
27 Some(Side::Buy)
28 } else if self.signed_qty < 0.0 {
29 Some(Side::Sell)
30 } else {
31 None
32 }
33 }
34
35 pub fn abs_qty(&self) -> f64 {
36 self.signed_qty.abs()
37 }
38
39 pub fn is_flat(&self) -> bool {
40 self.signed_qty.abs() <= f64::EPSILON
41 }
42}