Skip to main content

longport/trade/requests/
get_today_orders.rs

1use serde::Serialize;
2
3use crate::{
4    Market,
5    trade::{OrderSide, OrderStatus},
6    types::normalize_symbol_owned,
7};
8
9/// Options for get today orders request
10#[derive(Debug, Default, Serialize, Clone)]
11pub struct GetTodayOrdersOptions {
12    #[serde(skip_serializing_if = "Option::is_none")]
13    symbol: Option<String>,
14    #[serde(skip_serializing_if = "<[_]>::is_empty")]
15    status: Vec<OrderStatus>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    side: Option<OrderSide>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    market: Option<Market>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    order_id: Option<String>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    is_attached: Option<bool>,
24}
25
26impl GetTodayOrdersOptions {
27    /// Create a new `GetTodayOrdersOptions`
28    #[inline]
29    pub fn new() -> Self {
30        Default::default()
31    }
32
33    /// Set the security symbol
34    #[inline]
35    #[must_use]
36    pub fn symbol(self, symbol: impl Into<String>) -> Self {
37        Self {
38            symbol: Some(normalize_symbol_owned(symbol)),
39            ..self
40        }
41    }
42
43    /// Set the order status
44    #[inline]
45    #[must_use]
46    pub fn status(self, status: impl IntoIterator<Item = OrderStatus>) -> Self {
47        Self {
48            status: status.into_iter().collect(),
49            ..self
50        }
51    }
52
53    /// Set the order side
54    #[inline]
55    #[must_use]
56    pub fn side(self, side: OrderSide) -> Self {
57        Self {
58            side: Some(side),
59            ..self
60        }
61    }
62
63    /// Set the market
64    #[inline]
65    #[must_use]
66    pub fn market(self, market: Market) -> Self {
67        Self {
68            market: Some(market),
69            ..self
70        }
71    }
72
73    /// Set the order id
74    #[inline]
75    #[must_use]
76    pub fn order_id(self, order_id: String) -> Self {
77        Self {
78            order_id: Some(order_id),
79            ..self
80        }
81    }
82
83    /// When set together with [`order_id`], indicates that `order_id` is an
84    /// attached sub-order ID. The server returns the attached sub-order itself
85    /// as an [`Order`] entry (not the parent order). Has no effect without
86    /// [`order_id`].
87    pub fn is_attached(self) -> Self {
88        Self {
89            is_attached: Some(true),
90            ..self
91        }
92    }
93}