1use uuid::Uuid;
2use serde::{Serialize, Deserialize};
3
4#[derive(Debug, Clone)]
5pub struct QAOrder {
6 pub account_cookie: String,
7 pub user_id: String,
8 pub instrument_id: String,
9 pub towards: i32,
10 pub exchange_id: String,
11 pub order_time: String,
12 pub volume: f64,
13 pub price: f64,
14 pub order_id: String,
15 pub seqno: String,
16 pub direction: String,
17 pub offset: String,
18 pub volume_orign: f64,
19 pub price_type: String,
20 pub limit_price: f64,
21 pub time_condition: String,
22 pub volume_condition: String,
23 pub insert_date_time: String,
24 pub exchange_order_id: String,
25 pub status: i32,
26 pub volume_left: f64,
27 pub last_msg: String,
28}
29
30impl QAOrder {
31 pub fn new(
32 account: String,
33 code: String,
34 towards: i32,
35 exchange_id: String,
36 order_time: String,
37 volume: f64,
38 price: f64,
39 order_id: String,
40 ) -> Self {
41 let mut direction = "BUY".to_string();
42 let mut offset = "OPEN".to_string();
43
44 match towards {
45 1 | 2 => {}
46 -1 => {
47 direction = "SELL".to_string();
48 }
49 -2 => {
50 direction = "SELL".to_string();
51 }
52 3 => {
53 offset = "CLOSE".to_string();
54 }
55 -3 => {
56 direction = "SELL".to_string();
57 offset = "CLOSE".to_string();
58 }
59 _ => {}
60 }
61
62 Self {
63 account_cookie: account.clone(),
64 user_id: account.clone(),
65 instrument_id: code.clone(),
66 towards,
67 exchange_id,
68 order_time,
69 volume,
70 price,
71 order_id,
72 seqno: "".to_string(),
73 direction,
74 offset,
75 volume_orign: 0.0,
76 price_type: "LIMIT".to_string(),
77 limit_price: price,
78 time_condition: "AND".to_string(),
79 volume_condition: "GFD".to_string(),
80 insert_date_time: "".to_string(),
81 exchange_order_id: Uuid::new_v4().to_string(),
82 status: 100,
83 volume_left: volume,
84 last_msg: "".to_string(),
85 }
86 }
87
88 pub fn to_trade_order(&self) -> TradeOrder {
89 TradeOrder{
90 aid: "insert_order".to_string(),
91 user_id: self.account_cookie.clone(),
92 order_id: self.order_id.clone(),
93 exchange_id: self.exchange_id.clone(),
94 instrument_id: self.instrument_id.clone(),
95 direction: self.direction.clone(),
96 offset: self.offset.clone(),
97 volume: self.volume as i64,
98 price_type: self.price_type.clone(),
99 limit_price: self.price,
100 volume_condition: self.volume_condition.clone(),
101 time_condition: self.time_condition.clone()
102 }
103 }
104}
105
106
107#[derive(Serialize, Deserialize, Debug)]
108pub struct TradeOrder {
109 pub aid: String,
110 pub user_id: String,
111 pub order_id: String,
112 pub exchange_id: String,
113 pub instrument_id: String,
114 pub direction: String,
115 pub offset: String,
116 pub volume: i64,
117 pub price_type: String,
118 pub limit_price: f64,
119 pub volume_condition: String,
120 pub time_condition: String,
121}