nomy_data_models/models/
raw_trade.rs

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