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 trade_type: String,
24    pub amount: Decimal,
25    pub price: Decimal,
26    pub event_at: DateTime<Utc>,
27    pub fees_trading: Option<Decimal>,
28    pub fees_gas: Option<Decimal>,
29    pub fees_total: Option<Decimal>,
30    pub is_taker: Option<bool>,
31    pub extra_data: Option<JsonValue>,
32    pub unmatched_amount: Decimal,
33    pub is_fully_matched: bool,
34    pub id: Uuid,
35    pub created_at: DateTime<Utc>,
36    pub updated_at: DateTime<Utc>,
37    pub created_by: Option<String>,
38    pub updated_by: Option<String>,
39}
40
41impl PositionTrade {
42    /// Create a new PositionTrade.
43    pub fn new(
44        position_id: Uuid,
45        raw_trade_id: Uuid,
46        trade_type: String,
47        amount: Decimal,
48        price: Decimal,
49        event_at: DateTime<Utc>,
50        fees_trading: Decimal,
51        fees_gas: Decimal,
52        fees_total: Decimal,
53        is_taker: bool,
54        extra_data: JsonValue,
55        unmatched_amount: Decimal,
56        is_fully_matched: bool,
57        id: Uuid,
58        created_at: DateTime<Utc>,
59        updated_at: DateTime<Utc>,
60        created_by: String,
61        updated_by: String,
62    ) -> Self {
63        Self {
64            position_id,
65            raw_trade_id,
66            trade_type,
67            amount,
68            price,
69            event_at,
70            fees_trading: Some(fees_trading),
71            fees_gas: Some(fees_gas),
72            fees_total: Some(fees_total),
73            is_taker: Some(is_taker),
74            extra_data: Some(extra_data),
75            unmatched_amount,
76            is_fully_matched,
77            id,
78            created_at,
79            updated_at,
80            created_by: Some(created_by),
81            updated_by: Some(updated_by),
82        }
83    }
84
85    /// Convert to a JSON string.
86    pub fn to_json(&self) -> Result<String, serde_json::Error> {
87        serde_json::to_string(self)
88    }
89
90    /// Convert from a JSON string.
91    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
92        serde_json::from_str(json)
93    }
94
95    /// Convert to a dictionary-like structure.
96    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
97        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
98        if let serde_json::Value::Object(map) = json {
99            map
100        } else {
101            serde_json::Map::new()
102        }
103    }
104}