Skip to main content

rust_okx/api/account/responses/
loans.rs

1use serde::Deserialize;
2
3use crate::model::NumberString;
4
5/// Spot borrow/repay mutation result.
6#[derive(Debug, Clone, Deserialize)]
7#[serde(rename_all = "camelCase")]
8#[non_exhaustive]
9pub struct SpotBorrowRepayResult {
10    /// Value returned by OKX in the `ccy` field.
11    #[serde(default)]
12    pub ccy: String,
13    /// Value returned by OKX in the `side` field.
14    #[serde(default)]
15    pub side: String,
16    /// Value returned by OKX in the `amt` field.
17    #[serde(default)]
18    pub amt: NumberString,
19}
20
21/// Auto-repay setting result.
22#[derive(Debug, Clone, Deserialize)]
23#[serde(rename_all = "camelCase")]
24#[non_exhaustive]
25pub struct SetAutoRepayResult {
26    /// Value returned by OKX in the `autoRepay` field.
27    #[serde(default)]
28    pub auto_repay: bool,
29}
30
31/// Spot borrow/repay history row.
32#[derive(Debug, Clone, Deserialize)]
33#[serde(rename_all = "camelCase")]
34#[non_exhaustive]
35pub struct SpotBorrowRepayHistory {
36    /// Value returned by OKX in the `ccy` field.
37    #[serde(default)]
38    pub ccy: String,
39    /// Value returned by OKX in the `type` field.
40    #[serde(default, rename = "type")]
41    pub event_type: String,
42    /// Value returned by OKX in the `amt` field.
43    #[serde(default)]
44    pub amt: NumberString,
45    /// Value returned by OKX in the `accBorrowed` field.
46    #[serde(default)]
47    pub acc_borrowed: NumberString,
48    /// Value returned by OKX in the `ts` field.
49    #[serde(default)]
50    pub ts: NumberString,
51}
52
53/// Auto-earn setting result.
54#[derive(Debug, Clone, Deserialize)]
55#[serde(rename_all = "camelCase")]
56#[non_exhaustive]
57pub struct SetAutoEarnResult {
58    /// Auto earn type. `0`: auto earn (auto lend, auto staking); `1`: auto earn (USDG earn).
59    #[serde(default)]
60    pub earn_type: String,
61    /// Value returned by OKX in the `ccy` field.
62    #[serde(default)]
63    pub ccy: String,
64    /// Auto earn operation action, e.g. `turn_on`/`turn_off` (deprecated).
65    #[serde(default)]
66    pub action: String,
67    /// Minimum lending APR (deprecated).
68    #[serde(default)]
69    pub apr: NumberString,
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[test]
77    fn decodes_spot_borrow_repay_result() {
78        let row: SpotBorrowRepayResult =
79            serde_json::from_str(r#"{"ccy":"USDT","side":"borrow","amt":"5"}"#).unwrap();
80        assert_eq!(row.ccy, "USDT");
81        assert_eq!(row.side, "borrow");
82    }
83}