nomy_data_models/models/
enriched_trade.rs

1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2//! EnrichedTrade 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::MarketType;
17
18/// Model for storing enriched trade data with PnL calculations.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct EnrichedTrade {
21    pub pnl_usd: Option<Decimal>,
22    pub pnl: Option<Decimal>,
23    pub roi: Option<Decimal>,
24    pub holding_duration: Option<chrono::Duration>,
25    pub fee_json: Option<JsonValue>,
26    pub id: Uuid,
27    pub event_at: DateTime<Utc>,
28    pub txn_id: String,
29    pub wallet_address: String,
30    pub chain_id: i32,
31    pub exchange: String,
32    pub is_buy: bool,
33    pub is_taker: Option<bool>,
34    pub token_price: Decimal,
35    pub token_symbol_pair: String,
36    pub token_address_pair: Option<String>,
37    pub base_token_symbol: String,
38    pub quote_token_symbol: String,
39    pub base_token_address: Option<String>,
40    pub quote_token_address: Option<String>,
41    pub base_amount: Decimal,
42    pub quote_amount: Decimal,
43    pub usd_amount: Option<Decimal>,
44    pub market_type: String,
45    pub extra_data: Option<JsonValue>,
46    pub created_at: DateTime<Utc>,
47    pub updated_at: DateTime<Utc>,
48    pub created_by: Option<String>,
49    pub updated_by: Option<String>,
50}
51
52impl EnrichedTrade {
53    /// Create a new EnrichedTrade.
54    pub fn new(
55        pnl_usd: Decimal,
56        pnl: Decimal,
57        roi: Decimal,
58        holding_duration: chrono::Duration,
59        fee_json: JsonValue,
60        id: Uuid,
61        event_at: DateTime<Utc>,
62        txn_id: String,
63        wallet_address: String,
64        chain_id: i32,
65        exchange: String,
66        is_buy: bool,
67        is_taker: bool,
68        token_price: Decimal,
69        token_symbol_pair: String,
70        token_address_pair: String,
71        base_token_symbol: String,
72        quote_token_symbol: String,
73        base_token_address: String,
74        quote_token_address: String,
75        base_amount: Decimal,
76        quote_amount: Decimal,
77        usd_amount: Decimal,
78        market_type: String,
79        extra_data: JsonValue,
80        created_at: DateTime<Utc>,
81        updated_at: DateTime<Utc>,
82        created_by: String,
83        updated_by: String,
84    ) -> Self {
85        Self {
86            pnl_usd: Some(pnl_usd),
87            pnl: Some(pnl),
88            roi: Some(roi),
89            holding_duration: Some(holding_duration),
90            fee_json: Some(fee_json),
91            id,
92            event_at,
93            txn_id,
94            wallet_address,
95            chain_id,
96            exchange,
97            is_buy,
98            is_taker: Some(is_taker),
99            token_price,
100            token_symbol_pair,
101            token_address_pair: Some(token_address_pair),
102            base_token_symbol,
103            quote_token_symbol,
104            base_token_address: Some(base_token_address),
105            quote_token_address: Some(quote_token_address),
106            base_amount,
107            quote_amount,
108            usd_amount: Some(usd_amount),
109            market_type,
110            extra_data: Some(extra_data),
111            created_at,
112            updated_at,
113            created_by: Some(created_by),
114            updated_by: Some(updated_by),
115        }
116    }
117
118    /// Convert to a JSON string.
119    pub fn to_json(&self) -> Result<String, serde_json::Error> {
120        serde_json::to_string(self)
121    }
122
123    /// Convert from a JSON string.
124    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
125        serde_json::from_str(json)
126    }
127
128    /// Convert to a dictionary-like structure.
129    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
130        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
131        if let serde_json::Value::Object(map) = json {
132            map
133        } else {
134            serde_json::Map::new()
135        }
136    }
137}