Skip to main content

bybit_api/api/
spot_margin.rs

1//! Spot Margin API endpoints.
2
3use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::spot_margin::*;
6
7impl BybitClient {
8    /// Get Historical Interest Rate.
9    pub async fn get_historical_interest_rate(
10        &self,
11        currency: &str,
12        vip_level: Option<&str>,
13        start_time: Option<i64>,
14        end_time: Option<i64>,
15    ) -> Result<GetHistoricalInterestRateResponse> {
16        let start_time_str = start_time.map(|v| v.to_string());
17        let end_time_str = end_time.map(|v| v.to_string());
18        let mut params = vec![("currency", currency)];
19        if let Some(v) = vip_level {
20            params.push(("vipLevel", v));
21        }
22        if let Some(s) = start_time_str.as_deref() {
23            params.push(("startTime", s));
24        }
25        if let Some(s) = end_time_str.as_deref() {
26            params.push(("endTime", s));
27        }
28        self.get("/v5/spot-margin-trade/interest-rate-history", &params)
29            .await
30    }
31
32    /// Get Position Tiers.
33    pub async fn get_position_tiers(
34        &self,
35        currency: Option<&str>,
36    ) -> Result<GetPositionTiersResponse> {
37        let mut params = vec![];
38        if let Some(c) = currency {
39            params.push(("currency", c));
40        }
41        self.get("/v5/spot-margin-trade/position-tiers", &params)
42            .await
43    }
44
45    /// Get Tiered Collateral Ratio.
46    pub async fn get_tiered_collateral_ratio(
47        &self,
48        currency: Option<&str>,
49    ) -> Result<GetTieredCollateralRatioResponse> {
50        let mut params = vec![];
51        if let Some(c) = currency {
52            params.push(("currency", c));
53        }
54        self.get_public("/v5/spot-margin-trade/collateral", &params)
55            .await
56    }
57
58    /// Get VIP Margin Data.
59    pub async fn get_vip_margin_data(
60        &self,
61        vip_level: Option<&str>,
62        currency: Option<&str>,
63    ) -> Result<GetVipMarginDataResponse> {
64        let mut params = vec![];
65        if let Some(v) = vip_level {
66            params.push(("vipLevel", v));
67        }
68        if let Some(c) = currency {
69            params.push(("currency", c));
70        }
71        self.get_public("/v5/spot-margin-trade/data", &params).await
72    }
73}