Skip to main content

bybit/models/
adl_alert_request.rs

1use crate::prelude::*;
2
3/// Parameters for requesting ADL (Auto-Deleveraging) alert data.
4///
5/// This struct defines the parameters for querying ADL alerts via the
6/// `/v5/market/adlAlert` endpoint. ADL is a risk management mechanism
7/// that automatically closes positions when the insurance pool balance
8/// reaches certain thresholds to prevent systemic risk.
9///
10/// # Important Notes
11/// - Data update frequency is every 1 minute
12/// - Covers: USDT Perpetual, USDT Delivery, USDC Perpetual, USDC Delivery, Inverse Contracts
13/// - The `symbol` parameter is optional; if not provided, returns all symbols
14#[derive(Clone, Default)]
15pub struct ADLAlertRequest<'a> {
16    /// The trading symbol (e.g., "BTCUSDT").
17    ///
18    /// Specifies the contract to filter ADL alerts. This parameter is optional.
19    /// If not provided, the endpoint returns ADL alerts for all symbols.
20    /// Must be in uppercase.
21    pub symbol: Option<Cow<'a, str>>,
22}
23
24impl<'a> ADLAlertRequest<'a> {
25    /// Creates a default ADLAlert request.
26    ///
27    /// Returns a request with no symbol filter (returns all symbols).
28    /// Suitable for getting a complete overview of ADL alerts across all symbols.
29    pub fn default() -> ADLAlertRequest<'a> {
30        ADLAlertRequest::new(None)
31    }
32
33    /// Constructs a new ADLAlert request with specified parameters.
34    ///
35    /// Allows customization of the request parameters. Bots should use this to
36    /// specify an optional symbol filter for ADL alert queries.
37    ///
38    /// # Arguments
39    ///
40    /// * `symbol` - Optional symbol filter (e.g., "BTCUSDT", "ETHUSDT")
41    pub fn new(symbol: Option<&'a str>) -> ADLAlertRequest<'a> {
42        ADLAlertRequest {
43            symbol: symbol.map(Cow::Borrowed),
44        }
45    }
46
47    /// Constructs a new ADLAlert request for a specific symbol.
48    ///
49    /// Convenience method for creating requests filtered by a specific symbol.
50    ///
51    /// # Arguments
52    ///
53    /// * `symbol` - The symbol to filter by (e.g., "BTCUSDT", "ETHUSDT")
54    pub fn for_symbol(symbol: &'a str) -> ADLAlertRequest<'a> {
55        ADLAlertRequest::new(Some(symbol))
56    }
57
58    /// Constructs a new ADLAlert request for all symbols.
59    ///
60    /// Convenience method for creating requests without symbol filtering.
61    pub fn all_symbols() -> ADLAlertRequest<'a> {
62        ADLAlertRequest::new(None)
63    }
64
65    /// Sets the symbol filter for the request.
66    ///
67    /// Returns a new request with the specified symbol filter.
68    pub fn with_symbol(mut self, symbol: &'a str) -> Self {
69        self.symbol = Some(Cow::Borrowed(symbol));
70        self
71    }
72
73    /// Removes the symbol filter from the request.
74    ///
75    /// Returns a new request without symbol filtering.
76    pub fn without_symbol(mut self) -> Self {
77        self.symbol = None;
78        self
79    }
80
81    /// Creates an ADLAlertRequest for BTCUSDT.
82    ///
83    /// Convenience method for creating requests for BTCUSDT.
84    pub fn btcusdt() -> ADLAlertRequest<'a> {
85        ADLAlertRequest::for_symbol("BTCUSDT")
86    }
87
88    /// Creates an ADLAlertRequest for ETHUSDT.
89    ///
90    /// Convenience method for creating requests for ETHUSDT.
91    pub fn ethusdt() -> ADLAlertRequest<'a> {
92        ADLAlertRequest::for_symbol("ETHUSDT")
93    }
94
95    /// Creates an ADLAlertRequest for SOLUSDT.
96    ///
97    /// Convenience method for creating requests for SOLUSDT.
98    pub fn solusdt() -> ADLAlertRequest<'a> {
99        ADLAlertRequest::for_symbol("SOLUSDT")
100    }
101
102    /// Creates an ADLAlertRequest for XRPUSDT.
103    ///
104    /// Convenience method for creating requests for XRPUSDT.
105    pub fn xrpusdt() -> ADLAlertRequest<'a> {
106        ADLAlertRequest::for_symbol("XRPUSDT")
107    }
108
109    /// Creates an ADLAlertRequest for ADAUSDT.
110    ///
111    /// Convenience method for creating requests for ADAUSDT.
112    pub fn adausdt() -> ADLAlertRequest<'a> {
113        ADLAlertRequest::for_symbol("ADAUSDT")
114    }
115}