Skip to main content

rust_okx/api/account/requests/
loans.rs

1use serde::Serialize;
2/// Request body for `POST /api/v5/account/spot-manual-borrow-repay`.
3#[derive(Debug, Clone, Serialize)]
4pub struct SpotManualBorrowRepayRequest {
5    ccy: String,
6    side: String,
7    amt: String,
8}
9
10impl SpotManualBorrowRepayRequest {
11    /// Create a manual spot borrow or repay request.
12    pub fn new(ccy: impl Into<String>, side: impl Into<String>, amt: impl Into<String>) -> Self {
13        Self {
14            ccy: ccy.into(),
15            side: side.into(),
16            amt: amt.into(),
17        }
18    }
19}
20
21/// Request body for `POST /api/v5/account/set-auto-repay`.
22#[derive(Debug, Clone, Serialize)]
23pub struct SetAutoRepayRequest {
24    #[serde(rename = "autoRepay")]
25    auto_repay: bool,
26}
27
28impl SetAutoRepayRequest {
29    /// Enable or disable automatic repayment.
30    pub fn new(auto_repay: bool) -> Self {
31        Self { auto_repay }
32    }
33}
34
35/// Query parameters for `GET /api/v5/account/spot-borrow-repay-history`.
36#[derive(Debug, Clone, Default, Serialize)]
37pub struct SpotBorrowRepayHistoryRequest {
38    #[serde(skip_serializing_if = "Option::is_none")]
39    ccy: Option<String>,
40    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
41    event_type: Option<String>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    after: Option<String>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    before: Option<String>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    limit: Option<u32>,
48}
49
50impl SpotBorrowRepayHistoryRequest {
51    /// Create an unfiltered history query.
52    pub fn new() -> Self {
53        Self::default()
54    }
55
56    /// Filter by currency.
57    pub fn currency(mut self, value: impl Into<String>) -> Self {
58        self.ccy = Some(value.into());
59        self
60    }
61
62    /// Filter by event type.
63    pub fn event_type(mut self, value: impl Into<String>) -> Self {
64        self.event_type = Some(value.into());
65        self
66    }
67
68    /// Return records earlier than this millisecond timestamp.
69    pub fn after(mut self, value: impl Into<String>) -> Self {
70        self.after = Some(value.into());
71        self
72    }
73
74    /// Return records newer than this millisecond timestamp.
75    pub fn before(mut self, value: impl Into<String>) -> Self {
76        self.before = Some(value.into());
77        self
78    }
79
80    /// Set the result count from 1 through 100.
81    pub fn limit(mut self, value: u32) -> Self {
82        self.limit = Some(value);
83        self
84    }
85}
86
87/// Request body for `POST /api/v5/account/set-auto-earn`.
88#[derive(Debug, Clone, Serialize)]
89pub struct SetAutoEarnRequest {
90    #[serde(rename = "earnType")]
91    earn_type: String,
92    ccy: String,
93    action: String,
94}
95
96impl SetAutoEarnRequest {
97    /// Create an auto-earn update.
98    ///
99    /// `earn_type` is `0` for auto-lend/stake and `1` for USDG-style earn;
100    /// `action` is `turn_on` or `turn_off`.
101    pub fn new(
102        earn_type: impl Into<String>,
103        ccy: impl Into<String>,
104        action: impl Into<String>,
105    ) -> Self {
106        Self {
107            earn_type: earn_type.into(),
108            ccy: ccy.into(),
109            action: action.into(),
110        }
111    }
112}