Skip to main content

gateio_rs/api/spot/
get_price_orders.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// # Retrieve running auto order list
4///
5/// Retrieve running price-triggered orders (also called auto orders or conditional orders).
6/// These orders are not placed in the order book until their trigger condition is met.
7///
8/// ## Status Values:
9/// - "open": Waiting to trigger
10/// - "cancelled": Manually cancelled  
11/// - "finish": Successfully executed
12/// - "failed": Failed to execute
13/// - "expired": Expired
14///
15/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#retrieve-running-auto-order-list)
16pub struct GetPriceOrders {
17    /// Order status filter
18    pub status: Option<String>,
19    /// Currency pair (market) filter
20    pub market: Option<String>,
21    /// Account type filter
22    pub account: Option<String>,
23    /// Maximum number of records to return
24    pub limit: Option<i32>,
25    /// Offset for pagination
26    pub offset: Option<i32>,
27    /// API credentials for authentication
28    pub credentials: Option<Credentials>,
29}
30
31impl GetPriceOrders {
32    /// Creates a new GetPriceOrders request
33    pub fn new() -> Self {
34        Self {
35            status: None,
36            market: None,
37            account: None,
38            limit: None,
39            offset: None,
40            credentials: None,
41        }
42    }
43
44    /// Filter by order status
45    /// - "open": Waiting to trigger
46    /// - "cancelled": Manually cancelled  
47    /// - "finish": Successfully executed
48    /// - "failed": Failed to execute
49    /// - "expired": Expired
50    pub fn status(mut self, status: &str) -> Self {
51        self.status = Some(status.into());
52        self
53    }
54
55    /// Filter by currency pair (market)
56    pub fn market(mut self, market: &str) -> Self {
57        self.market = Some(market.into());
58        self
59    }
60
61    /// Filter by account type
62    /// - "normal": Normal spot trading account
63    /// - "margin": Margin trading account  
64    /// - "unified": Unified trading account
65    pub fn account(mut self, account: &str) -> Self {
66        self.account = Some(account.into());
67        self
68    }
69
70    /// Maximum number of records to return (default: 100, max: 1000)
71    pub fn limit(mut self, limit: i32) -> Self {
72        self.limit = Some(limit);
73        self
74    }
75
76    /// Offset for pagination (default: 0)
77    pub fn offset(mut self, offset: i32) -> Self {
78        self.offset = Some(offset);
79        self
80    }
81
82    /// Sets the API credentials for authentication
83    pub fn credentials(mut self, creds: Credentials) -> Self {
84        self.credentials = Some(creds);
85        self
86    }
87}
88
89impl From<GetPriceOrders> for Request {
90    fn from(request: GetPriceOrders) -> Request {
91        let mut params = Vec::new();
92
93        if let Some(status) = request.status {
94            params.push(("status".into(), status));
95        }
96
97        if let Some(market) = request.market {
98            params.push(("market".into(), market));
99        }
100
101        if let Some(account) = request.account {
102            params.push(("account".into(), account));
103        }
104
105        if let Some(limit) = request.limit {
106            params.push(("limit".into(), limit.to_string()));
107        }
108
109        if let Some(offset) = request.offset {
110            params.push(("offset".into(), offset.to_string()));
111        }
112
113        Request {
114            method: Method::Get,
115            path: "/api/v4/spot/price_orders".into(),
116            params,
117            payload: "".to_string(),
118            x_gate_exp_time: None,
119            credentials: request.credentials,
120            sign: true,
121        }
122    }
123}