Skip to main content

bybit/http/
spot_margin_trade.rs

1use rust_decimal::Decimal;
2use serde::{Deserialize, Serialize};
3
4use crate::SpotMarginMode;
5
6// --- Toggle Margin Trade ---
7
8/// Request body for
9/// [`Client::switch_spot_margin_mode`](crate::http::Client::switch_spot_margin_mode).
10///
11/// The account must have completed spot margin activation (including the required quiz)
12/// before this call succeeds.
13#[derive(Debug, Serialize, Clone)]
14#[serde(rename_all = "camelCase")]
15pub struct SwitchSpotMarginModeRequest {
16    pub spot_margin_mode: SpotMarginMode,
17}
18
19impl SwitchSpotMarginModeRequest {
20    pub fn enable() -> Self {
21        Self {
22            spot_margin_mode: SpotMarginMode::Enabled,
23        }
24    }
25
26    pub fn disable() -> Self {
27        Self {
28            spot_margin_mode: SpotMarginMode::Disabled,
29        }
30    }
31}
32
33#[derive(Debug, Deserialize, PartialEq)]
34#[serde(rename_all = "camelCase")]
35pub struct SwitchSpotMarginModeResult {
36    pub spot_margin_mode: SpotMarginMode,
37}
38
39// --- Set Leverage ---
40
41/// Request body for
42/// [`Client::set_spot_margin_leverage`](crate::http::Client::set_spot_margin_leverage).
43///
44/// The account must have completed spot margin activation (including the required quiz)
45/// before this call succeeds.
46#[derive(Debug, Serialize, Clone)]
47#[serde(rename_all = "camelCase")]
48pub struct SetSpotMarginLeverageRequest {
49    /// Maximum leverage. Range: [2, 10]
50    pub leverage: Decimal,
51    /// Coin name, uppercase only
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub currency: Option<String>,
54}
55
56impl SetSpotMarginLeverageRequest {
57    pub fn new(leverage: Decimal) -> Self {
58        Self {
59            leverage,
60            currency: None,
61        }
62    }
63
64    pub fn with_currency(mut self, v: String) -> Self {
65        self.currency = Some(v);
66        self
67    }
68}