nomy_data_models/models/
position_trade.rs

1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2//! PositionTrade 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
16use crate::enums::PositionTradeType;
17
18/// Model linking a trade event to a position's lifecycle.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct PositionTrade {
21    pub position_id: Uuid,
22    pub raw_trade_id: Uuid,
23    pub raw_trade_event_at: DateTime<Utc>,
24    pub trade_type: String,
25    pub amount: Decimal,
26    pub price: Decimal,
27    pub event_at: DateTime<Utc>,
28    pub fees_trading: Option<Decimal>,
29    pub fees_gas: Option<Decimal>,
30    pub fees_total: Option<Decimal>,
31    pub is_taker: Option<bool>,
32    pub extra_data: Option<JsonValue>,
33    pub unmatched_amount: Decimal,
34    pub is_fully_matched: bool,
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 PositionTrade {
43    /// Create a new PositionTrade.
44    pub fn new(
45        position_id: Uuid,
46        raw_trade_id: Uuid,
47        raw_trade_event_at: DateTime<Utc>,
48        trade_type: String,
49        amount: Decimal,
50        price: Decimal,
51        event_at: DateTime<Utc>,
52        fees_trading: Decimal,
53        fees_gas: Decimal,
54        fees_total: Decimal,
55        is_taker: bool,
56        extra_data: JsonValue,
57        unmatched_amount: Decimal,
58        is_fully_matched: bool,
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            position_id,
67            raw_trade_id,
68            raw_trade_event_at,
69            trade_type,
70            amount,
71            price,
72            event_at,
73            fees_trading: Some(fees_trading),
74            fees_gas: Some(fees_gas),
75            fees_total: Some(fees_total),
76            is_taker: Some(is_taker),
77            extra_data: Some(extra_data),
78            unmatched_amount,
79            is_fully_matched,
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}