Skip to main content

longbridge/trade/requests/
get_today_orders.rs

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