Skip to main content

rust_okx/api/trade/requests/
advanced.rs

1use serde::Serialize;
2
3/// Request body for `POST /api/v5/trade/easy-convert`.
4#[derive(Debug, Clone, Serialize)]
5pub struct EasyConvertRequest {
6    #[serde(rename = "fromCcy")]
7    from_ccy: Vec<String>,
8    #[serde(rename = "toCcy")]
9    to_ccy: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    source: Option<String>,
12}
13
14impl EasyConvertRequest {
15    /// Create an easy-convert request with one to five source currencies.
16    pub fn new<I, S>(from_ccy: I, to_ccy: impl Into<String>) -> Self
17    where
18        I: IntoIterator<Item = S>,
19        S: Into<String>,
20    {
21        Self {
22            from_ccy: from_ccy.into_iter().map(Into::into).collect(),
23            to_ccy: to_ccy.into(),
24            source: None,
25        }
26    }
27
28    /// Set the funding source: `1` for trading or `2` for funding.
29    pub fn source(mut self, value: impl Into<String>) -> Self {
30        self.source = Some(value.into());
31        self
32    }
33}
34
35/// Query parameters for easy-convert history.
36#[derive(Debug, Clone, Default, Serialize)]
37pub struct EasyConvertHistoryRequest {
38    #[serde(skip_serializing_if = "Option::is_none")]
39    after: Option<String>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    before: Option<String>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    limit: Option<u32>,
44}
45
46impl EasyConvertHistoryRequest {
47    /// Create an empty history query.
48    pub fn new() -> Self {
49        Self::default()
50    }
51
52    /// Return records earlier than this millisecond timestamp.
53    pub fn after(mut self, value: impl Into<String>) -> Self {
54        self.after = Some(value.into());
55        self
56    }
57
58    /// Return records newer than this millisecond timestamp.
59    pub fn before(mut self, value: impl Into<String>) -> Self {
60        self.before = Some(value.into());
61        self
62    }
63
64    /// Set the number of results, from 1 through 100.
65    pub fn limit(mut self, value: u32) -> Self {
66        self.limit = Some(value);
67        self
68    }
69}
70
71/// Query parameters for one-click-repay currency-list endpoints.
72#[derive(Debug, Clone, Default, Serialize)]
73pub struct OneClickRepayCurrencyListRequest {
74    #[serde(rename = "debtType", skip_serializing_if = "Option::is_none")]
75    debt_type: Option<String>,
76}
77
78impl OneClickRepayCurrencyListRequest {
79    /// Create an unfiltered currency-list query.
80    pub fn new() -> Self {
81        Self::default()
82    }
83
84    /// Filter debt by `cross` or `isolated` type.
85    pub fn debt_type(mut self, value: impl Into<String>) -> Self {
86        self.debt_type = Some(value.into());
87        self
88    }
89}
90
91/// One or more debt currencies accepted by the legacy and v2 repay APIs.
92#[derive(Debug, Clone, Serialize)]
93#[serde(untagged)]
94enum DebtCurrencySelection {
95    One(String),
96    Many(Vec<String>),
97}
98
99/// Request body shared by one-click-repay v1 and v2 endpoints.
100#[derive(Debug, Clone, Serialize)]
101pub struct OneClickRepayRequest {
102    #[serde(rename = "debtCcy")]
103    debt_ccy: DebtCurrencySelection,
104    #[serde(rename = "repayCcy", skip_serializing_if = "Option::is_none")]
105    repay_ccy: Option<String>,
106    #[serde(rename = "repayCcyList", skip_serializing_if = "Option::is_none")]
107    repay_ccy_list: Option<Vec<String>>,
108}
109
110impl OneClickRepayRequest {
111    /// Build the legacy v1 request (`debtCcy` array + one `repayCcy`).
112    pub fn new<I, S>(debt_ccy: I, repay_ccy: impl Into<String>) -> Self
113    where
114        I: IntoIterator<Item = S>,
115        S: Into<String>,
116    {
117        Self {
118            debt_ccy: DebtCurrencySelection::Many(debt_ccy.into_iter().map(Into::into).collect()),
119            repay_ccy: Some(repay_ccy.into()),
120            repay_ccy_list: None,
121        }
122    }
123
124    /// Build the v2 request (`debtCcy` string + prioritized `repayCcyList`).
125    pub fn v2<I, S>(debt_ccy: impl Into<String>, repay_ccy_list: I) -> Self
126    where
127        I: IntoIterator<Item = S>,
128        S: Into<String>,
129    {
130        Self {
131            debt_ccy: DebtCurrencySelection::One(debt_ccy.into()),
132            repay_ccy: None,
133            repay_ccy_list: Some(repay_ccy_list.into_iter().map(Into::into).collect()),
134        }
135    }
136}
137
138/// Query parameters for one-click-repay history endpoints.
139#[derive(Debug, Clone, Default, Serialize)]
140pub struct OneClickRepayHistoryRequest {
141    #[serde(skip_serializing_if = "Option::is_none")]
142    after: Option<String>,
143    #[serde(skip_serializing_if = "Option::is_none")]
144    before: Option<String>,
145    #[serde(skip_serializing_if = "Option::is_none")]
146    limit: Option<u32>,
147}
148
149impl OneClickRepayHistoryRequest {
150    /// Create an empty history query.
151    pub fn new() -> Self {
152        Self::default()
153    }
154
155    /// Return records earlier than this millisecond timestamp.
156    pub fn after(mut self, value: impl Into<String>) -> Self {
157        self.after = Some(value.into());
158        self
159    }
160
161    /// Return records newer than this millisecond timestamp.
162    pub fn before(mut self, value: impl Into<String>) -> Self {
163        self.before = Some(value.into());
164        self
165    }
166
167    /// Set the number of results, from 1 through 100.
168    pub fn limit(mut self, value: u32) -> Self {
169        self.limit = Some(value);
170        self
171    }
172}