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 /// 1: on, 0: off.
17 pub spot_margin_mode: SpotMarginMode,
18}
19
20impl SwitchSpotMarginModeRequest {
21 /// Turn spot margin trading on.
22 pub fn enable() -> Self {
23 Self {
24 spot_margin_mode: SpotMarginMode::Enabled,
25 }
26 }
27
28 /// Turn spot margin trading off.
29 pub fn disable() -> Self {
30 Self {
31 spot_margin_mode: SpotMarginMode::Disabled,
32 }
33 }
34}
35
36/// Result of `POST /v5/spot-margin-trade/switch-mode` ([`Client::switch_spot_margin_mode`](crate::http::Client::switch_spot_margin_mode)).
37#[derive(Debug, Deserialize, PartialEq)]
38#[serde(rename_all = "camelCase")]
39pub struct SwitchSpotMarginModeResult {
40 /// Spot margin status. 1: on, 0: off.
41 pub spot_margin_mode: SpotMarginMode,
42}
43
44// --- Set Leverage ---
45
46/// Request body for
47/// [`Client::set_spot_margin_leverage`](crate::http::Client::set_spot_margin_leverage).
48///
49/// The account must have completed spot margin activation (including the required quiz)
50/// before this call succeeds.
51#[derive(Debug, Serialize, Clone)]
52#[serde(rename_all = "camelCase")]
53pub struct SetSpotMarginLeverageRequest {
54 /// Maximum leverage. Range: [2, 10]
55 pub leverage: Decimal,
56 /// Coin name, uppercase only
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub currency: Option<String>,
59}
60
61impl SetSpotMarginLeverageRequest {
62 /// Create with the required fields; set the optional ones with the `with_*` methods.
63 pub fn new(leverage: Decimal) -> Self {
64 Self {
65 leverage,
66 currency: None,
67 }
68 }
69
70 /// Set `currency`: coin name, uppercase only.
71 pub fn with_currency(mut self, v: impl Into<String>) -> Self {
72 self.currency = Some(v.into());
73 self
74 }
75}