Skip to main content

bybit/models/
risk_limit_request.rs

1use crate::prelude::*;
2
3/// Represents a request to fetch risk limit data for a trading category on Bybit.
4/// Risk limits define the maximum position size and leverage for a trader, critical for
5/// managing exposure in perpetual futures.
6#[derive(Clone, Default)]
7pub struct RiskLimitRequest<'a> {
8    /// The trading category (e.g., Linear for USDT-margined perpetuals).
9    /// Determines the type of futures contract. Bots must ensure this matches the trading pair.
10    pub category: Category,
11
12    /// The trading symbol (e.g., "BTCUSDT").
13    /// Specifies the market for which risk limits are queried. Optional, as some endpoints allow
14    /// category-wide queries. Bots should validate symbols to avoid API errors.
15    pub symbol: Option<Cow<'a, str>>,
16}
17
18impl<'a> RiskLimitRequest<'a> {
19    /// Creates a default request for the Linear category.
20    /// Simplifies initialization for bots targeting USDT-margined perpetuals.
21    pub fn default() -> RiskLimitRequest<'a> {
22        RiskLimitRequest::new(Category::Linear, None)
23    }
24    /// Constructs a new request with specified category and symbol.
25    /// Enables precise queries for risk limits, critical for bots managing leverage and position
26    /// sizes in perpetual futures.
27    pub fn new(category: Category, symbol: Option<&'a str>) -> RiskLimitRequest<'a> {
28        RiskLimitRequest {
29            category,
30            symbol: symbol.map(Cow::Borrowed),
31        }
32    }
33}