1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2use serde::{Deserialize, Serialize};
8
9use chrono::{DateTime, Utc};
11use rust_decimal::Decimal;
12use serde_json::Value as JsonValue;
13use uuid::Uuid;
14
15use crate::enums::MarketType;
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct EnrichedTrade {
21 pub pnl_usd: Decimal,
22 pub pnl: Decimal,
23 pub roi: Decimal,
24 pub holding_duration: chrono::Duration,
25 pub fee_json: 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: String,
36 pub base_token_symbol: String,
37 pub quote_token_symbol: String,
38 pub base_token_address: String,
39 pub quote_token_address: String,
40 pub base_amount: Decimal,
41 pub quote_amount: Decimal,
42 pub usd_amount: Decimal,
43 pub market_type: String,
44 pub created_at: DateTime<Utc>,
45 pub updated_at: DateTime<Utc>,
46 pub created_by: String,
47 pub updated_by: String,
48}
49
50impl EnrichedTrade {
51 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,
83 pnl,
84 roi,
85 holding_duration,
86 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,
97 base_token_symbol,
98 quote_token_symbol,
99 base_token_address,
100 quote_token_address,
101 base_amount,
102 quote_amount,
103 usd_amount,
104 market_type,
105 created_at,
106 updated_at,
107 created_by,
108 updated_by,
109 }
110 }
111
112 pub fn to_json(&self) -> Result<String, serde_json::Error> {
114 serde_json::to_string(self)
115 }
116
117 pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
119 serde_json::from_str(json)
120 }
121
122 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}