longport/trade/requests/
submit_order.rs

1use rust_decimal::Decimal;
2use serde::Serialize;
3use time::Date;
4
5use crate::{
6    serde_utils,
7    trade::{OrderSide, OrderType, OutsideRTH, TimeInForceType},
8};
9
10/// Options for submit order request
11#[derive(Debug, Serialize, Clone)]
12pub struct SubmitOrderOptions {
13    symbol: String,
14    order_type: OrderType,
15    side: OrderSide,
16    submitted_quantity: Decimal,
17    time_in_force: TimeInForceType,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    submitted_price: Option<Decimal>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    trigger_price: Option<Decimal>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    limit_offset: Option<Decimal>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    trailing_amount: Option<Decimal>,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    trailing_percent: Option<Decimal>,
28    #[serde(with = "serde_utils::date_opt")]
29    expire_date: Option<Date>,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    outside_rth: Option<OutsideRTH>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    limit_depth_level: Option<i32>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    trigger_count: Option<i32>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    monitor_price: Option<Decimal>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    remark: Option<String>,
40}
41
42impl SubmitOrderOptions {
43    /// Create a new `SubmitOrderOptions`
44    #[inline]
45    pub fn new(
46        symbol: impl Into<String>,
47        order_type: OrderType,
48        side: OrderSide,
49        submitted_quantity: Decimal,
50        time_in_force: TimeInForceType,
51    ) -> Self {
52        Self {
53            symbol: symbol.into(),
54            order_type,
55            side,
56            submitted_quantity,
57            time_in_force,
58            submitted_price: None,
59            trigger_price: None,
60            limit_offset: None,
61            trailing_amount: None,
62            trailing_percent: None,
63            expire_date: None,
64            outside_rth: None,
65            limit_depth_level: None,
66            trigger_count: None,
67            monitor_price: None,
68            remark: None,
69        }
70    }
71
72    /// Set the submitted price
73    #[inline]
74    #[must_use]
75    pub fn submitted_price(self, submitted_price: Decimal) -> Self {
76        Self {
77            submitted_price: Some(submitted_price),
78            ..self
79        }
80    }
81
82    /// Set the trigger price
83    #[inline]
84    #[must_use]
85    pub fn trigger_price(self, trigger_price: Decimal) -> Self {
86        Self {
87            trigger_price: Some(trigger_price),
88            ..self
89        }
90    }
91
92    /// Set the limit offset
93    #[inline]
94    #[must_use]
95    pub fn limit_offset(self, limit_offset: Decimal) -> Self {
96        Self {
97            limit_offset: Some(limit_offset),
98            ..self
99        }
100    }
101
102    /// Set the trailing amount
103    #[inline]
104    #[must_use]
105    pub fn trailing_amount(self, trailing_amount: Decimal) -> Self {
106        Self {
107            trailing_amount: Some(trailing_amount),
108            ..self
109        }
110    }
111
112    /// Set the trailing percent
113    #[inline]
114    #[must_use]
115    pub fn trailing_percent(self, trailing_percent: Decimal) -> Self {
116        Self {
117            trailing_percent: Some(trailing_percent),
118            ..self
119        }
120    }
121
122    /// Set the expire date
123    #[inline]
124    #[must_use]
125    pub fn expire_date(self, expire_date: Date) -> Self {
126        Self {
127            expire_date: Some(expire_date),
128            ..self
129        }
130    }
131
132    /// Enable or disable outside regular trading hours
133    #[inline]
134    #[must_use]
135    pub fn outside_rth(self, outside_rth: OutsideRTH) -> Self {
136        Self {
137            outside_rth: Some(outside_rth),
138            ..self
139        }
140    }
141
142    /// Set the limit depth level
143    pub fn limit_depth_level(self, level: i32) -> Self {
144        Self {
145            limit_depth_level: Some(level),
146            ..self
147        }
148    }
149
150    /// Set the trigger count
151    pub fn trigger_count(self, count: i32) -> Self {
152        Self {
153            trigger_count: Some(count),
154            ..self
155        }
156    }
157
158    /// Set the monitor price
159    pub fn monitor_price(self, price: Decimal) -> Self {
160        Self {
161            monitor_price: Some(price),
162            ..self
163        }
164    }
165
166    /// Set the remark
167    #[inline]
168    #[must_use]
169    pub fn remark(self, remark: impl Into<String>) -> Self {
170        Self {
171            remark: Some(remark.into()),
172            ..self
173        }
174    }
175}