Skip to main content

longport/trade/requests/
get_history_orders.rs

1use serde::Serialize;
2use time::OffsetDateTime;
3
4use crate::{
5    Market, serde_utils,
6    trade::{OrderSide, OrderStatus},
7    types::normalize_symbol_owned,
8};
9
10/// Options for get history orders request
11#[derive(Debug, Default, Serialize, Clone)]
12pub struct GetHistoryOrdersOptions {
13    #[serde(skip_serializing_if = "Option::is_none")]
14    symbol: Option<String>,
15    #[serde(skip_serializing_if = "<[_]>::is_empty")]
16    status: Vec<OrderStatus>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    side: Option<OrderSide>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    market: Option<Market>,
21    #[serde(
22        skip_serializing_if = "Option::is_none",
23        with = "serde_utils::timestamp_opt"
24    )]
25    start_at: Option<OffsetDateTime>,
26    #[serde(
27        skip_serializing_if = "Option::is_none",
28        with = "serde_utils::timestamp_opt"
29    )]
30    end_at: Option<OffsetDateTime>,
31    // Pagination cursor (1-based), set internally by `history_orders` while
32    // walking pages. Not a public builder — callers always get every page.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    page: Option<u32>,
35}
36
37impl GetHistoryOrdersOptions {
38    /// Create a new `GetHistoryOrdersOptions`
39    #[inline]
40    pub fn new() -> Self {
41        Default::default()
42    }
43
44    /// Set the security symbol
45    #[inline]
46    #[must_use]
47    pub fn symbol(self, symbol: impl Into<String>) -> Self {
48        Self {
49            symbol: Some(normalize_symbol_owned(symbol)),
50            ..self
51        }
52    }
53
54    /// Set the order status
55    #[inline]
56    #[must_use]
57    pub fn status(self, status: impl IntoIterator<Item = OrderStatus>) -> Self {
58        Self {
59            status: status.into_iter().collect(),
60            ..self
61        }
62    }
63
64    /// Set the order side
65    #[inline]
66    #[must_use]
67    pub fn side(self, side: OrderSide) -> Self {
68        Self {
69            side: Some(side),
70            ..self
71        }
72    }
73
74    /// Set the market
75    #[inline]
76    #[must_use]
77    pub fn market(self, market: Market) -> Self {
78        Self {
79            market: Some(market),
80            ..self
81        }
82    }
83
84    /// Set the start time
85    #[inline]
86    #[must_use]
87    pub fn start_at(self, start_at: OffsetDateTime) -> Self {
88        Self {
89            start_at: Some(start_at),
90            ..self
91        }
92    }
93
94    /// Set the end time
95    #[inline]
96    #[must_use]
97    pub fn end_at(self, end_at: OffsetDateTime) -> Self {
98        Self {
99            end_at: Some(end_at),
100            ..self
101        }
102    }
103
104    /// Internal 1-based pagination cursor used by `history_orders` to walk all
105    /// pages. Not a public builder — the SDK sets this while paginating.
106    #[inline]
107    pub(crate) fn with_page(self, page: u32) -> Self {
108        Self {
109            page: Some(page),
110            ..self
111        }
112    }
113}