rusty_feeder/exchange/upbit/
types.rs1use crate::provider::prelude::*;
6use rust_decimal::Decimal;
7use serde::{Deserialize, Serialize};
8use smartstring::alias::String;
9
10pub const UPBIT_WS_URL: &str = "wss://api.upbit.com/websocket/v1";
12
13pub const UPBIT_WS_PRIVATE_URL: &str = "wss://api.upbit.com/websocket/v1/private";
15
16pub const UPBIT_API_URL: &str = "https://api.upbit.com";
18
19pub const UPBIT_RATE_LIMITS: &[RateLimit] = &[
21 RateLimit {
22 limit_type: "REQUEST_WEIGHT",
23 interval: "MINUTE",
24 interval_num: 1,
25 limit: 900, },
27 RateLimit {
28 limit_type: "ORDERS",
29 interval: "MINUTE",
30 interval_num: 1,
31 limit: 200, },
33 RateLimit {
34 limit_type: "RAW_REQUESTS",
35 interval: "SECOND",
36 interval_num: 1,
37 limit: 30, },
39];
40
41#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
43#[serde(rename_all = "lowercase")]
44pub enum UpbitMessageType {
45 #[serde(rename = "trade")]
47 Trade,
48
49 #[serde(rename = "orderbook")]
51 Orderbook,
52
53 #[serde(rename = "ticker")]
55 Ticker,
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
60#[serde(rename_all = "UPPERCASE")]
61pub enum StreamType {
62 #[serde(rename = "SNAPSHOT")]
64 Snapshot,
65
66 #[serde(rename = "REALTIME")]
68 Realtime,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
73#[serde(rename_all = "UPPERCASE")]
74pub enum ChangeDirection {
75 #[serde(rename = "RISE")]
77 Rise,
78
79 #[serde(rename = "EVEN")]
81 Even,
82
83 #[serde(rename = "FALL")]
85 Fall,
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
90#[serde(rename_all = "UPPERCASE")]
91pub enum TradeSide {
92 #[serde(rename = "ASK")]
94 Ask,
95
96 #[serde(rename = "BID")]
98 Bid,
99}
100
101#[derive(Debug, Clone, Serialize)]
103pub struct SubscriptionRequest {
104 pub ticket: String,
106
107 #[serde(rename = "type")]
109 pub data_type: String,
110
111 pub codes: Vec<String>,
113
114 #[serde(skip_serializing_if = "Option::is_none")]
116 pub is_only_snapshot: Option<bool>,
117
118 #[serde(skip_serializing_if = "Option::is_none")]
120 pub is_only_realtime: Option<bool>,
121}
122
123#[derive(Debug, Clone, Serialize)]
125pub struct FormatRequest {
126 pub format: String,
128}
129
130#[derive(Debug, Clone, Deserialize, Serialize)]
132#[repr(align(64))] pub struct TradeResponse {
134 #[serde(rename = "type")]
136 pub message_type: String,
137
138 pub code: String,
140
141 pub trade_price: Decimal,
143
144 pub trade_volume: Decimal,
146
147 pub ask_bid: String,
149
150 pub prev_closing_price: Decimal,
152
153 pub change: String,
155
156 pub change_price: Decimal,
158
159 pub trade_date: String,
161
162 pub trade_time: String,
164
165 pub trade_timestamp: u64,
167
168 pub timestamp: u64,
170
171 pub sequential_id: u64,
173
174 pub best_ask_price: Option<Decimal>,
176
177 pub best_ask_size: Option<Decimal>,
179
180 pub best_bid_price: Option<Decimal>,
182
183 pub best_bid_size: Option<Decimal>,
185
186 pub stream_type: String,
188}
189
190#[derive(Debug, Clone, Deserialize, Serialize)]
192#[repr(align(64))] pub struct OrderbookResponse {
194 #[serde(rename = "type")]
196 pub message_type: String,
197
198 pub code: String,
200
201 pub total_ask_size: Decimal,
203
204 pub total_bid_size: Decimal,
206
207 pub orderbook_units: Vec<OrderbookUnit>,
209
210 pub timestamp: u64,
212
213 pub stream_type: String,
215}
216
217#[derive(Debug, Clone, Deserialize, Serialize)]
219pub struct OrderbookUnit {
220 pub ask_price: Decimal,
222
223 pub bid_price: Decimal,
225
226 pub ask_size: Decimal,
228
229 pub bid_size: Decimal,
231}