nomy_data_models/models/
trade_match.rs

1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2//! TradeMatch model definition.
3//!
4//! This file is generated automatically from the Python SQLAlchemy model.
5//! Do not edit this file manually.
6
7use serde::{Deserialize, Serialize};
8
9// Standard imports that may be needed
10use chrono::{DateTime, Utc};
11use rust_decimal::Decimal;
12use serde_json::Value as JsonValue;
13use uuid::Uuid;
14
15// Additional imports specific to this model
16// No additional imports needed
17
18/// Model representing a realized PnL event from matching trades.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct TradeMatch {
21    pub match_created_at: DateTime<Utc>,
22    pub position_id: Uuid,
23    pub position_opened_at: DateTime<Utc>,
24    pub opening_trade_id: Uuid,
25    pub opening_trade_event_at: DateTime<Utc>,
26    pub closing_trade_id: Uuid,
27    pub closing_trade_event_at: DateTime<Utc>,
28    pub matched_amount: Decimal,
29    pub entry_price: Decimal,
30    pub exit_price: Decimal,
31    pub pnl: Decimal,
32    pub pnl_usd: Decimal,
33    pub roi: Option<Decimal>,
34    pub holding_duration: Option<chrono::Duration>,
35    pub id: Uuid,
36    pub created_at: DateTime<Utc>,
37    pub updated_at: DateTime<Utc>,
38    pub created_by: Option<String>,
39    pub updated_by: Option<String>,
40}
41
42impl TradeMatch {
43    /// Create a new TradeMatch.
44    pub fn new(
45        match_created_at: DateTime<Utc>,
46        position_id: Uuid,
47        position_opened_at: DateTime<Utc>,
48        opening_trade_id: Uuid,
49        opening_trade_event_at: DateTime<Utc>,
50        closing_trade_id: Uuid,
51        closing_trade_event_at: DateTime<Utc>,
52        matched_amount: Decimal,
53        entry_price: Decimal,
54        exit_price: Decimal,
55        pnl: Decimal,
56        pnl_usd: Decimal,
57        roi: Decimal,
58        holding_duration: chrono::Duration,
59        id: Uuid,
60        created_at: DateTime<Utc>,
61        updated_at: DateTime<Utc>,
62        created_by: String,
63        updated_by: String,
64    ) -> Self {
65        Self {
66            match_created_at,
67            position_id,
68            position_opened_at,
69            opening_trade_id,
70            opening_trade_event_at,
71            closing_trade_id,
72            closing_trade_event_at,
73            matched_amount,
74            entry_price,
75            exit_price,
76            pnl,
77            pnl_usd,
78            roi: Some(roi),
79            holding_duration: Some(holding_duration),
80            id,
81            created_at,
82            updated_at,
83            created_by: Some(created_by),
84            updated_by: Some(updated_by),
85        }
86    }
87
88    /// Convert to a JSON string.
89    pub fn to_json(&self) -> Result<String, serde_json::Error> {
90        serde_json::to_string(self)
91    }
92
93    /// Convert from a JSON string.
94    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
95        serde_json::from_str(json)
96    }
97
98    /// Convert to a dictionary-like structure.
99    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
100        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
101        if let serde_json::Value::Object(map) = json {
102            map
103        } else {
104            serde_json::Map::new()
105        }
106    }
107}