deribit_base/model/
position.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 21/7/25
5******************************************************************************/
6use pretty_simple_display::{DebugPretty, DisplaySimple};
7use serde::{Deserialize, Serialize};
8
9/// Position direction enumeration
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "lowercase")]
12pub enum Direction {
13    /// Buy direction
14    Buy,
15    /// Sell direction
16    Sell,
17}
18
19/// Position structure
20#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
21pub struct Position {
22    /// Average price of the position
23    pub average_price: f64,
24    /// Average price in USD
25    pub average_price_usd: Option<f64>,
26    /// Delta (price sensitivity) of the position
27    pub delta: Option<f64>,
28    /// Direction of the position (buy/sell)
29    pub direction: Direction,
30    /// Estimated liquidation price
31    pub estimated_liquidation_price: Option<f64>,
32    /// Floating profit/loss
33    pub floating_profit_loss: Option<f64>,
34    /// Floating profit/loss in USD
35    pub floating_profit_loss_usd: Option<f64>,
36    /// Gamma (delta sensitivity) of the position
37    pub gamma: Option<f64>,
38    /// Current index price
39    pub index_price: Option<f64>,
40    /// Initial margin requirement
41    pub initial_margin: Option<f64>,
42    /// Name of the instrument
43    pub instrument_name: String,
44    /// Interest value
45    pub interest_value: Option<f64>,
46    /// Instrument kind (future, option, etc.)
47    pub kind: Option<String>,
48    /// Leverage used for the position
49    pub leverage: Option<i32>,
50    /// Maintenance margin requirement
51    pub maintenance_margin: Option<f64>,
52    /// Current mark price
53    pub mark_price: Option<f64>,
54    /// Margin used by open orders
55    pub open_orders_margin: Option<f64>,
56    /// Realized funding payments
57    pub realized_funding: Option<f64>,
58    /// Realized profit/loss
59    pub realized_profit_loss: Option<f64>,
60    /// Settlement price
61    pub settlement_price: Option<f64>,
62    /// Position size
63    pub size: f64,
64    /// Position size in currency units
65    pub size_currency: Option<f64>,
66    /// Theta (time decay) of the position
67    pub theta: Option<f64>,
68    /// Total profit/loss
69    pub total_profit_loss: Option<f64>,
70    /// Vega (volatility sensitivity) of the position
71    pub vega: Option<f64>,
72    /// Unrealized profit/loss
73    pub unrealized_profit_loss: Option<f64>,
74}