birdie/margin/trade/
query_open_orders.rs

1use jiff::Timestamp;
2use reqwest::Method;
3use serde::Serialize;
4
5use crate::{
6    enums::SecurityType,
7    rest_api::{Endpoint, RestApiClient},
8    Params,
9};
10
11use super::MarginOrderDetail;
12
13impl Endpoint for QueryOpenOrdersEndpoint<'_> {
14    type Response = QueryOpenOrdersResponse;
15    type Params = QueryOpenOrdersParams;
16
17    fn client(&self) -> &RestApiClient {
18        self.client
19    }
20
21    fn path(&self) -> &str {
22        "/sapi/v1/margin/openOrders"
23    }
24
25    fn method(&self) -> Method {
26        Method::GET
27    }
28
29    fn security_type(&self) -> SecurityType {
30        SecurityType::UserData
31    }
32}
33
34impl Params for QueryOpenOrdersParams {}
35
36/// Query Margin Account's Open Orders.
37///
38/// - Weight: 10
39pub struct QueryOpenOrdersEndpoint<'r> {
40    client: &'r crate::rest_api::RestApiClient,
41}
42
43impl<'r> QueryOpenOrdersEndpoint<'r> {
44    pub fn new(client: &'r crate::rest_api::RestApiClient) -> Self {
45        Self { client }
46    }
47}
48
49#[derive(Debug, Serialize)]
50#[serde(rename_all = "camelCase")]
51pub struct QueryOpenOrdersParams {
52    symbol: Option<String>,
53    is_isolated: Option<String>,
54    recv_window: Option<i64>,
55    timestamp: i64,
56}
57
58impl QueryOpenOrdersParams {
59    pub fn new() -> Self {
60        Self {
61            symbol: None,
62            is_isolated: None,
63            recv_window: None,
64            timestamp: Timestamp::now().as_millisecond(),
65        }
66    }
67
68    pub fn symbol(mut self, symbol: &str) -> Self {
69        self.symbol = Some(symbol.to_owned());
70        self
71    }
72
73    pub fn is_isolated(mut self, is_isolated: &str) -> Self {
74        self.is_isolated = Some(is_isolated.to_owned());
75        self
76    }
77
78    pub fn recv_window(mut self, recv_window: i64) -> Self {
79        self.recv_window = Some(recv_window);
80        self
81    }
82}
83
84pub type QueryOpenOrdersResponse = Vec<MarginOrderDetail>;