cripsy_binary_api/domain/
position.rs1use serde::{Deserialize, Serialize};
4
5use crate::domain::operation::OrderId;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum Side {
9 Buy,
10 Sell,
11}
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct Position {
15 pub id: OrderId,
16 pub instrument_type: String,
18 pub symbol: String,
19 pub side: Side,
20 pub amount: f64,
21 pub open_price: Option<f64>,
22 pub pnl: Option<f64>,
23 pub invested: Option<f64>,
24 pub open_at: i64,
25 pub close_at: Option<i64>,
26 pub leverage: Option<u32>,
27}
28
29impl Position {
30 pub fn is_closed(&self) -> bool {
31 self.close_at.is_some()
32 }
33}
34
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
36pub struct PositionHistory {
37 pub positions: Vec<Position>,
38 pub offset: usize,
39 pub total: Option<usize>,
40}