Skip to main content

rust_okx/api/account/requests/
settings.rs

1use std::borrow::Cow;
2
3use serde::Serialize;
4
5/// Request for [`set_position_mode`](crate::api::account::Account::set_position_mode).
6#[derive(Debug, Clone, Serialize)]
7pub struct SetPositionModeRequest<'a> {
8    #[serde(rename = "posMode")]
9    pos_mode: Cow<'a, str>,
10}
11
12impl<'a> SetPositionModeRequest<'a> {
13    /// Create a position-mode update.
14    pub fn new(pos_mode: impl Into<Cow<'a, str>>) -> Self {
15        Self {
16            pos_mode: pos_mode.into(),
17        }
18    }
19}
20
21/// Request for [`set_collateral_assets`](crate::api::account::Account::set_collateral_assets).
22#[derive(Debug, Clone, Serialize)]
23pub struct SetCollateralAssetsRequest<'a> {
24    #[serde(rename = "type")]
25    collateral_type: Cow<'a, str>,
26    #[serde(rename = "collateralEnabled")]
27    collateral_enabled: bool,
28    #[serde(rename = "ccyList", skip_serializing_if = "Vec::is_empty")]
29    ccy_list: Vec<Cow<'a, str>>,
30}
31
32impl<'a> SetCollateralAssetsRequest<'a> {
33    /// Create a request that updates the collateral setting for all assets.
34    pub fn all(collateral_enabled: bool) -> Self {
35        Self {
36            collateral_type: Cow::Borrowed("all"),
37            collateral_enabled,
38            ccy_list: Vec::new(),
39        }
40    }
41
42    /// Create a request that updates the collateral setting for specific currencies.
43    pub fn custom<I, C>(ccy_list: I, collateral_enabled: bool) -> Self
44    where
45        I: IntoIterator<Item = C>,
46        C: Into<Cow<'a, str>>,
47    {
48        Self {
49            collateral_type: Cow::Borrowed("custom"),
50            collateral_enabled,
51            ccy_list: ccy_list.into_iter().map(Into::into).collect(),
52        }
53    }
54
55    /// Create a collateral-assets request with an explicit OKX `type` value.
56    pub fn new(collateral_type: impl Into<Cow<'a, str>>, collateral_enabled: bool) -> Self {
57        Self {
58            collateral_type: collateral_type.into(),
59            collateral_enabled,
60            ccy_list: Vec::new(),
61        }
62    }
63
64    /// Set the currency list for a custom collateral-assets request.
65    pub fn currencies<I, C>(mut self, ccy_list: I) -> Self
66    where
67        I: IntoIterator<Item = C>,
68        C: Into<Cow<'a, str>>,
69    {
70        self.ccy_list = ccy_list.into_iter().map(Into::into).collect();
71        self
72    }
73}
74
75/// Request for [`set_greeks`](crate::api::account::Account::set_greeks).
76#[derive(Debug, Clone, Serialize)]
77pub struct SetGreeksRequest<'a> {
78    #[serde(rename = "greeksType")]
79    greeks_type: Cow<'a, str>,
80}
81
82impl<'a> SetGreeksRequest<'a> {
83    /// Create a greeks-display update.
84    pub fn new(greeks_type: impl Into<Cow<'a, str>>) -> Self {
85        Self {
86            greeks_type: greeks_type.into(),
87        }
88    }
89}
90
91/// Request for [`set_isolated_mode`](crate::api::account::Account::set_isolated_mode).
92#[derive(Debug, Clone, Serialize)]
93pub struct SetIsolatedModeRequest<'a> {
94    #[serde(rename = "isoMode")]
95    iso_mode: Cow<'a, str>,
96    #[serde(rename = "type")]
97    mode_type: Cow<'a, str>,
98}
99
100impl<'a> SetIsolatedModeRequest<'a> {
101    /// Create an isolated-mode update.
102    pub fn new(iso_mode: impl Into<Cow<'a, str>>, mode_type: impl Into<Cow<'a, str>>) -> Self {
103        Self {
104            iso_mode: iso_mode.into(),
105            mode_type: mode_type.into(),
106        }
107    }
108}
109
110/// Request for [`set_auto_loan`](crate::api::account::Account::set_auto_loan).
111#[derive(Debug, Clone, Serialize)]
112pub struct SetAutoLoanRequest {
113    #[serde(rename = "autoLoan")]
114    auto_loan: bool,
115}
116
117impl SetAutoLoanRequest {
118    /// Create an auto-loan update.
119    pub fn new(auto_loan: bool) -> Self {
120        Self { auto_loan }
121    }
122}
123
124/// Request for [`set_account_level`](crate::api::account::Account::set_account_level).
125#[derive(Debug, Clone, Serialize)]
126pub struct SetAccountLevelRequest<'a> {
127    #[serde(rename = "acctLv")]
128    acct_lv: Cow<'a, str>,
129}
130
131impl<'a> SetAccountLevelRequest<'a> {
132    /// Create an account-level update.
133    pub fn new(acct_lv: impl Into<Cow<'a, str>>) -> Self {
134        Self {
135            acct_lv: acct_lv.into(),
136        }
137    }
138}