bybit/models/order_history_request.rs
1use crate::prelude::*;
2
3/// Represents a request to retrieve order history on Bybit.
4///
5/// This struct defines parameters to query past orders, filtered by time, symbol,
6/// or status. In perpetual futures, order history is crucial for auditing performance
7/// and refining strategies. Bots should use this to analyze executed orders and
8/// adjust trading logic accordingly.
9#[derive(Clone, Default)]
10pub struct OrderHistoryRequest<'a> {
11 /// The category of the trading product (e.g., Spot, Linear).
12 ///
13 /// Specifies the market to query. Bots must set this to match the target market,
14
15 /// typically `Linear` for perpetual futures.
16 pub category: Category,
17
18 /// The trading pair symbol, e.g., "BTCUSDT".
19 ///
20 /// Filters orders by symbol. Bots can set this to focus on specific assets or
21 /// leave it as `None` for all orders in the category.
22 pub symbol: Option<Cow<'a, str>>,
23
24 /// The base coin of the trading pair (e.g., "BTC").
25 ///
26 /// Filters orders by the base asset. Useful for analyzing specific assets in
27 /// perpetual futures trading.
28 pub base_coin: Option<Cow<'a, str>>,
29
30 /// The settlement coin (e.g., "USDT").
31 ///
32 /// Filters orders by the quote asset. Useful for USDT-margined perpetual futures
33 /// markets.
34 pub settle_coin: Option<Cow<'a, str>>,
35
36 /// The unique identifier of a specific order.
37 ///
38 /// Allows querying a single order by its Bybit-provided ID. Bots should use this
39 /// for precise historical analysis.
40 pub order_id: Option<Cow<'a, str>>,
41
42 /// The user-defined identifier of a specific order.
43 ///
44 /// Allows querying a single order by its custom ID. Useful for tracking specific
45 /// orders in perpetual futures strategies.
46 pub order_link_id: Option<Cow<'a, str>>,
47
48 /// A filter to specify the order type (e.g., "tpslOrder").
49 ///
50 /// Targets specific order types, such as TP/SL orders. Bots should use this to
51 /// analyze relevant orders in perpetual futures.
52 pub order_filter: Option<Cow<'a, str>>,
53
54 /// The status of the orders to query (e.g., "Filled", "Cancelled").
55 ///
56 /// Filters orders by their execution status. Bots can use this to focus on
57 /// completed or canceled orders for performance analysis in perpetual futures.
58 pub order_status: Option<Cow<'a, str>>,
59
60 /// The start time for the query (in milliseconds).
61 ///
62 /// Filters orders created after this timestamp. Bots should use this to narrow
63 /// down historical data for specific periods in perpetual futures trading.
64 pub start_time: Option<u64>,
65
66 /// The end time for the query (in milliseconds).
67 ///
68 /// Filters orders created before this timestamp. Bots should pair this with
69 /// `start_time` for precise time-based queries.
70 pub end_time: Option<u64>,
71
72 /// The maximum number of orders to return.
73 ///
74 /// Limits the response size, typically up to 50. Bots should set this to manage
75 /// API response sizes and avoid rate limits in perpetual futures trading.
76 pub limit: Option<u64>,
77}
78
79impl<'a> OrderHistoryRequest<'a> {
80 /// Creates a default `OrderHistoryRequest` with predefined values.
81 ///
82 /// Initializes a query with common defaults. Bots should modify fields to target
83 /// specific historical orders in perpetual futures.
84 pub fn default() -> Self {
85 Self {
86 category: Category::Linear,
87 symbol: None,
88 base_coin: None,
89 settle_coin: None,
90 order_id: None,
91 order_link_id: None,
92 order_filter: None,
93 order_status: None,
94 start_time: None,
95 end_time: None,
96 limit: None,
97 }
98 }
99 /// Creates a custom `OrderHistoryRequest` with specified parameters.
100 ///
101 /// Allows bots to tailor the query fully. Ensure parameters are valid to avoid
102 /// API errors in perpetual futures trading.
103 pub fn new(
104 category: Category,
105 symbol: Option<&'a str>,
106 base_coin: Option<&'a str>,
107 settle_coin: Option<&'a str>,
108 order_id: Option<&'a str>,
109 order_link_id: Option<&'a str>,
110 order_filter: Option<&'a str>,
111 order_status: Option<&'a str>,
112 start_time: Option<u64>,
113 end_time: Option<u64>,
114 limit: Option<u64>,
115 ) -> Self {
116 Self {
117 category,
118 symbol: symbol.map(Cow::Borrowed),
119 base_coin: base_coin.map(Cow::Borrowed),
120 settle_coin: settle_coin.map(Cow::Borrowed),
121 order_id: order_id.map(Cow::Borrowed),
122 order_link_id: order_link_id.map(Cow::Borrowed),
123 order_filter: order_filter.map(Cow::Borrowed),
124 order_status: order_status.map(Cow::Borrowed),
125 start_time,
126 end_time,
127 limit,
128 }
129 }
130}