longbridge/trade/requests/
replace_order.rs1use rust_decimal::Decimal;
2use serde::Serialize;
3
4use crate::trade::{AttachedOrderType, OrderType, OutsideRTH, TimeInForceType};
5
6#[derive(Debug, Serialize, Clone)]
8pub struct ReplaceOrderOptions {
9 order_id: String,
10 quantity: Decimal,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 price: Option<Decimal>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 trigger_price: Option<Decimal>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 limit_offset: Option<Decimal>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 trailing_amount: Option<Decimal>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 trailing_percent: Option<Decimal>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 limit_depth_level: Option<i32>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 trigger_count: Option<i32>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 monitor_price: Option<Decimal>,
27 #[serde(skip_serializing_if = "Option::is_none")]
28 remark: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 attached_params: Option<ReplaceAttachedParams>,
31}
32
33impl ReplaceOrderOptions {
34 #[inline]
36 pub fn new(order_id: impl Into<String>, quantity: Decimal) -> Self {
37 Self {
38 order_id: order_id.into(),
39 quantity,
40 price: None,
41 trigger_price: None,
42 limit_offset: None,
43 trailing_amount: None,
44 trailing_percent: None,
45 limit_depth_level: None,
46 trigger_count: None,
47 monitor_price: None,
48 remark: None,
49 attached_params: None,
50 }
51 }
52
53 #[inline]
55 #[must_use]
56 pub fn price(self, price: Decimal) -> Self {
57 Self {
58 price: Some(price),
59 ..self
60 }
61 }
62
63 #[inline]
65 #[must_use]
66 pub fn trigger_price(self, trigger_price: Decimal) -> Self {
67 Self {
68 trigger_price: Some(trigger_price),
69 ..self
70 }
71 }
72
73 #[inline]
75 #[must_use]
76 pub fn limit_offset(self, limit_offset: Decimal) -> Self {
77 Self {
78 limit_offset: Some(limit_offset),
79 ..self
80 }
81 }
82
83 #[inline]
85 #[must_use]
86 pub fn trailing_amount(self, trailing_amount: Decimal) -> Self {
87 Self {
88 trailing_amount: Some(trailing_amount),
89 ..self
90 }
91 }
92
93 #[inline]
95 #[must_use]
96 pub fn trailing_percent(self, trailing_percent: Decimal) -> Self {
97 Self {
98 trailing_percent: Some(trailing_percent),
99 ..self
100 }
101 }
102
103 #[inline]
105 #[must_use]
106 pub fn limit_depth_level(self, limit_depth_level: i32) -> Self {
107 Self {
108 limit_depth_level: Some(limit_depth_level),
109 ..self
110 }
111 }
112
113 #[inline]
115 #[must_use]
116 pub fn trigger_count(self, trigger_count: i32) -> Self {
117 Self {
118 trigger_count: Some(trigger_count),
119 ..self
120 }
121 }
122
123 #[inline]
125 #[must_use]
126 pub fn monitor_price(self, monitor_price: Decimal) -> Self {
127 Self {
128 monitor_price: Some(monitor_price),
129 ..self
130 }
131 }
132
133 #[inline]
135 #[must_use]
136 pub fn remark(self, remark: impl Into<String>) -> Self {
137 Self {
138 remark: Some(remark.into()),
139 ..self
140 }
141 }
142
143 pub fn attached_params(self, params: ReplaceAttachedParams) -> Self {
145 Self {
146 attached_params: Some(params),
147 ..self
148 }
149 }
150}
151
152#[derive(Debug, Serialize, Clone)]
154pub struct ReplaceAttachedParams {
155 attached_order_type: AttachedOrderType,
156 #[serde(skip_serializing_if = "Option::is_none")]
157 profit_taker_price: Option<Decimal>,
158 #[serde(skip_serializing_if = "Option::is_none")]
159 stop_loss_price: Option<Decimal>,
160 #[serde(skip_serializing_if = "Option::is_none")]
161 time_in_force: Option<TimeInForceType>,
162 #[serde(skip_serializing_if = "Option::is_none")]
163 expire_time: Option<i64>,
164 #[serde(skip_serializing_if = "Option::is_none")]
165 activate_order_type: Option<OrderType>,
166 #[serde(skip_serializing_if = "Option::is_none")]
167 profit_taker_submit_price: Option<Decimal>,
168 #[serde(skip_serializing_if = "Option::is_none")]
169 stop_loss_submit_price: Option<Decimal>,
170 #[serde(skip_serializing_if = "Option::is_none")]
171 activate_rth: Option<OutsideRTH>,
172 #[serde(skip_serializing_if = "Option::is_none")]
173 profit_taker_id: Option<i64>,
174 #[serde(skip_serializing_if = "Option::is_none")]
175 stop_loss_id: Option<i64>,
176 #[serde(skip_serializing_if = "Option::is_none")]
177 cancel_all_attached: Option<bool>,
178 #[serde(skip_serializing_if = "Option::is_none")]
179 main_id: Option<i64>,
180 #[serde(skip_serializing_if = "Option::is_none")]
181 quantity: Option<Decimal>,
182 #[serde(skip_serializing_if = "Option::is_none")]
183 market_price: Option<Decimal>,
184}
185
186impl ReplaceAttachedParams {
187 pub fn new(attached_order_type: AttachedOrderType) -> Self {
189 Self {
190 attached_order_type,
191 profit_taker_price: None,
192 stop_loss_price: None,
193 time_in_force: None,
194 expire_time: None,
195 activate_order_type: None,
196 profit_taker_submit_price: None,
197 stop_loss_submit_price: None,
198 activate_rth: None,
199 profit_taker_id: None,
200 stop_loss_id: None,
201 cancel_all_attached: None,
202 main_id: None,
203 quantity: None,
204 market_price: None,
205 }
206 }
207 pub fn profit_taker_price(self, v: Decimal) -> Self {
209 Self {
210 profit_taker_price: Some(v),
211 ..self
212 }
213 }
214 pub fn stop_loss_price(self, v: Decimal) -> Self {
216 Self {
217 stop_loss_price: Some(v),
218 ..self
219 }
220 }
221 pub fn time_in_force(self, v: TimeInForceType) -> Self {
223 Self {
224 time_in_force: Some(v),
225 ..self
226 }
227 }
228 pub fn expire_time(self, v: i64) -> Self {
230 Self {
231 expire_time: Some(v),
232 ..self
233 }
234 }
235 pub fn activate_order_type(self, v: OrderType) -> Self {
237 Self {
238 activate_order_type: Some(v),
239 ..self
240 }
241 }
242 pub fn profit_taker_submit_price(self, v: Decimal) -> Self {
244 Self {
245 profit_taker_submit_price: Some(v),
246 ..self
247 }
248 }
249 pub fn stop_loss_submit_price(self, v: Decimal) -> Self {
251 Self {
252 stop_loss_submit_price: Some(v),
253 ..self
254 }
255 }
256 pub fn activate_rth(self, v: OutsideRTH) -> Self {
258 Self {
259 activate_rth: Some(v),
260 ..self
261 }
262 }
263 pub fn profit_taker_id(self, v: i64) -> Self {
265 Self {
266 profit_taker_id: Some(v),
267 ..self
268 }
269 }
270 pub fn stop_loss_id(self, v: i64) -> Self {
272 Self {
273 stop_loss_id: Some(v),
274 ..self
275 }
276 }
277 pub fn cancel_all_attached(self) -> Self {
279 Self {
280 cancel_all_attached: Some(true),
281 ..self
282 }
283 }
284 pub fn main_id(self, v: i64) -> Self {
286 Self {
287 main_id: Some(v),
288 ..self
289 }
290 }
291 pub fn quantity(self, v: Decimal) -> Self {
293 Self {
294 quantity: Some(v),
295 ..self
296 }
297 }
298 pub fn market_price(self, v: Decimal) -> Self {
300 Self {
301 market_price: Some(v),
302 ..self
303 }
304 }
305}