Skip to main content

bybit/models/
subscription.rs

1/// Parameters for WebSocket subscription requests.
2///
3/// Used to construct a WebSocket subscription request to subscribe to real-time data streams, such as order book updates or trade events. Bots use this to configure WebSocket feeds for market monitoring and trading signals in perpetual futures trading.
4#[derive(Clone, Debug, Default)]
5pub struct Subscription<'a> {
6    /// The operation type (e.g., "subscribe").
7    ///
8    /// Specifies the WebSocket operation, typically `"subscribe"` for subscribing to data streams. Bots must set this correctly to initiate subscriptions.
9    pub op: &'a str,
10
11    /// A list of subscription arguments.
12    ///
13    /// Specifies the data streams to subscribe to, such as `"orderbook.50.BTCUSDT"` or `"trade.BTCUSDT"`. Bots should provide valid topics to receive relevant market data.
14    pub args: Vec<&'a str>,
15}
16
17impl<'a> Subscription<'a> {
18    /// Constructs a new Subscription with specified parameters.
19    ///
20    /// Allows customization of the WebSocket subscription. Bots should use this to specify the operation and subscription arguments for their data needs.
21    pub fn new(op: &'a str, args: Vec<&'a str>) -> Self {
22        Self { op, args }
23    }
24    /// Creates a default Subscription.
25    ///
26    /// Returns a subscription with `op` set to `"subscribe"` and an empty argument list. Suitable for testing but should be customized with valid topics for production.
27    pub fn default() -> Subscription<'a> {
28        Subscription::new("subscribe", vec![])
29    }
30}