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 token_price: Decimal,
34    pub token_symbol_pair: String,
35    pub token_address_pair: Option<String>,
36    pub base_token_symbol: String,
37    pub quote_token_symbol: String,
38    pub base_token_address: Option<String>,
39    pub quote_token_address: Option<String>,
40    pub base_amount: Decimal,
41    pub quote_amount: Decimal,
42    pub usd_amount: Option<Decimal>,
43    pub market_type: String,
44    pub created_at: DateTime<Utc>,
45    pub updated_at: DateTime<Utc>,
46    pub created_by: Option<String>,
47    pub updated_by: Option<String>,
48}
49
50impl EnrichedTrade {
51    /// Create a new EnrichedTrade.
52    pub fn new(
53        pnl_usd: Decimal,
54        pnl: Decimal,
55        roi: Decimal,
56        holding_duration: chrono::Duration,
57        fee_json: JsonValue,
58        id: Uuid,
59        event_at: DateTime<Utc>,
60        txn_id: String,
61        wallet_address: String,
62        chain_id: i32,
63        exchange: String,
64        is_buy: bool,
65        token_price: Decimal,
66        token_symbol_pair: String,
67        token_address_pair: String,
68        base_token_symbol: String,
69        quote_token_symbol: String,
70        base_token_address: String,
71        quote_token_address: String,
72        base_amount: Decimal,
73        quote_amount: Decimal,
74        usd_amount: Decimal,
75        market_type: String,
76        created_at: DateTime<Utc>,
77        updated_at: DateTime<Utc>,
78        created_by: String,
79        updated_by: String,
80    ) -> Self {
81        Self {
82            pnl_usd: Some(pnl_usd),
83            pnl: Some(pnl),
84            roi: Some(roi),
85            holding_duration: Some(holding_duration),
86            fee_json: Some(fee_json),
87            id,
88            event_at,
89            txn_id,
90            wallet_address,
91            chain_id,
92            exchange,
93            is_buy,
94            token_price,
95            token_symbol_pair,
96            token_address_pair: Some(token_address_pair),
97            base_token_symbol,
98            quote_token_symbol,
99            base_token_address: Some(base_token_address),
100            quote_token_address: Some(quote_token_address),
101            base_amount,
102            quote_amount,
103            usd_amount: Some(usd_amount),
104            market_type,
105            created_at,
106            updated_at,
107            created_by: Some(created_by),
108            updated_by: Some(updated_by),
109        }
110    }
111
112    /// Convert to a JSON string.
113    pub fn to_json(&self) -> Result<String, serde_json::Error> {
114        serde_json::to_string(self)
115    }
116
117    /// Convert from a JSON string.
118    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
119        serde_json::from_str(json)
120    }
121
122    /// Convert to a dictionary-like structure.
123    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
124        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
125        if let serde_json::Value::Object(map) = json {
126            map
127        } else {
128            serde_json::Map::new()
129        }
130    }
131}