rusty_feeder/exchange/upbit/data/
trade.rs1use rust_decimal::Decimal;
7use rusty_model::enums::OrderSide;
8use serde::{Deserialize, Serialize};
9use smartstring::alias::String;
10
11#[derive(Debug, Clone, Deserialize, Serialize)]
13#[repr(align(64))] pub struct TradeMessage {
15 #[serde(rename = "type")]
17 pub message_type: String,
18
19 pub code: String,
21
22 pub trade_price: Decimal,
24
25 pub trade_volume: Decimal,
27
28 pub ask_bid: String,
30
31 pub prev_closing_price: Decimal,
33
34 pub change: String,
36
37 pub change_price: Decimal,
39
40 pub trade_date: String,
42
43 pub trade_time: String,
45
46 pub trade_timestamp: u64,
48
49 pub timestamp: u64,
51
52 pub sequential_id: u64,
54
55 pub best_ask_price: Option<Decimal>,
57
58 pub best_ask_size: Option<Decimal>,
60
61 pub best_bid_price: Option<Decimal>,
63
64 pub best_bid_size: Option<Decimal>,
66
67 pub stream_type: String,
69}
70
71#[derive(Debug, Clone)]
73#[repr(align(64))] pub struct Transaction {
75 pub code: String,
77
78 pub sequential_id: u64,
80
81 pub price: Decimal,
83
84 pub volume: Decimal,
86
87 pub side: OrderSide,
89
90 pub trade_timestamp_ns: u64,
92
93 pub timestamp_ns: u64,
95
96 pub local_time_ns: u64,
98
99 pub best_ask_price: Option<Decimal>,
101
102 pub best_ask_size: Option<Decimal>,
104
105 pub best_bid_price: Option<Decimal>,
107
108 pub best_bid_size: Option<Decimal>,
110}
111
112impl Transaction {
113 #[inline(always)]
115 #[must_use]
116 pub fn from_trade_message(msg: &TradeMessage, local_time_ns: u64) -> Self {
117 let side = match msg.ask_bid.as_str() {
118 "BID" => OrderSide::Buy,
119 _ => OrderSide::Sell,
120 };
121
122 let trade_timestamp_ns = msg.trade_timestamp * 1_000_000;
124 let timestamp_ns = msg.timestamp * 1_000_000;
125
126 Self {
127 code: msg.code.clone(),
128 sequential_id: msg.sequential_id,
129 price: msg.trade_price,
130 volume: msg.trade_volume,
131 side,
132 trade_timestamp_ns,
133 timestamp_ns,
134 local_time_ns,
135 best_ask_price: msg.best_ask_price,
136 best_ask_size: msg.best_ask_size,
137 best_bid_price: msg.best_bid_price,
138 best_bid_size: msg.best_bid_size,
139 }
140 }
141}