1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Account {
7 pub id: String,
9
10 pub account_number: String,
12
13 pub account_type: AccountType,
15
16 pub status: AccountStatus,
18
19 pub created_at: DateTime<Utc>,
21
22 pub currency: String,
24
25 pub paper_trading: bool,
27
28 pub region: Option<String>,
30
31 pub name: Option<String>,
33
34 pub email: Option<String>,
36
37 pub phone: Option<String>,
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
43#[serde(rename_all = "UPPERCASE")]
44pub enum AccountType {
45 Cash,
47
48 Margin,
50
51 Ira,
53
54 Other,
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60#[serde(rename_all = "UPPERCASE")]
61pub enum AccountStatus {
62 Active,
64
65 Closed,
67
68 Pending,
70
71 Suspended,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct AccountBalance {
78 pub cash: f64,
80
81 pub buying_power: f64,
83
84 pub market_value: f64,
86
87 pub total_value: f64,
89
90 pub unrealized_profit_loss: f64,
92
93 pub unrealized_profit_loss_percentage: f64,
95
96 pub currency: String,
98
99 pub settled_cash: Option<f64>,
101
102 pub unsettled_cash: Option<f64>,
104
105 pub withdrawable_cash: Option<f64>,
107
108 pub tradable_cash: Option<f64>,
110
111 pub margin_buying_power: Option<f64>,
113
114 pub option_buying_power: Option<f64>,
116
117 pub day_trading_buying_power: Option<f64>,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct Position {
124 pub symbol: String,
126
127 pub instrument_id: String,
129
130 pub quantity: f64,
132
133 pub cost_basis: f64,
135
136 pub market_value: f64,
138
139 pub unrealized_profit_loss: f64,
141
142 pub unrealized_profit_loss_percentage: f64,
144
145 pub current_price: f64,
147
148 pub opened_at: DateTime<Utc>,
150
151 pub name: Option<String>,
153
154 pub security_type: Option<String>,
156
157 pub exchange: Option<String>,
159
160 pub currency: Option<String>,
162
163 pub side: Option<String>,
165
166 pub status: Option<String>,
168
169 pub tradable_quantity: Option<f64>,
171
172 pub unsettled_quantity: Option<f64>,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct AccountProfile {
179 pub id: String,
181
182 pub account_number: String,
184
185 pub account_type: AccountType,
187
188 pub status: AccountStatus,
190
191 pub region: String,
193
194 pub name: String,
196
197 pub email: Option<String>,
199
200 pub phone: Option<String>,
202
203 pub currency: String,
205
206 pub paper_trading: bool,
208
209 pub created_at: DateTime<Utc>,
211
212 pub kyc_status: Option<String>,
214
215 pub risk_level: Option<String>,
217
218 pub permissions: Option<Vec<String>>,
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize)]
224pub struct TradeHistory {
225 pub id: String,
227
228 pub symbol: String,
230
231 pub instrument_id: String,
233
234 pub name: Option<String>,
236
237 pub action: String,
239
240 pub quantity: f64,
242
243 pub price: f64,
245
246 pub amount: f64,
248
249 pub fees: Option<f64>,
251
252 pub trade_time: DateTime<Utc>,
254
255 pub status: String,
257
258 pub order_id: Option<String>,
260
261 pub currency: Option<String>,
263
264 pub exchange: Option<String>,
266
267 pub security_type: Option<String>,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize)]
273pub struct PositionParams {
274 #[serde(rename = "account_id")]
276 pub account_id: String,
277
278 #[serde(rename = "page_size")]
280 pub page_size: u32,
281
282 #[serde(rename = "last_instrument_id", skip_serializing_if = "Option::is_none")]
284 pub last_instrument_id: Option<String>,
285}
286
287impl PositionParams {
288 pub fn new(account_id: impl Into<String>, page_size: u32) -> Self {
290 Self {
291 account_id: account_id.into(),
292 page_size,
293 last_instrument_id: None,
294 }
295 }
296
297 pub fn last_instrument_id(mut self, last_instrument_id: impl Into<String>) -> Self {
299 self.last_instrument_id = Some(last_instrument_id.into());
300 self
301 }
302}
303
304#[derive(Debug, Clone, Serialize, Deserialize)]
306pub struct BalanceParams {
307 #[serde(rename = "account_id")]
309 pub account_id: String,
310
311 #[serde(rename = "total_asset_currency")]
313 pub total_asset_currency: String,
314}
315
316impl BalanceParams {
317 pub fn new(account_id: impl Into<String>, total_asset_currency: impl Into<String>) -> Self {
319 Self {
320 account_id: account_id.into(),
321 total_asset_currency: total_asset_currency.into(),
322 }
323 }
324
325 pub fn new_with_default_currency(account_id: impl Into<String>) -> Self {
327 Self::new(account_id, "HKD")
328 }
329}