Skip to main content

rust_okx/api/account/requests/
loans.rs

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