bybit/models/open_interest_request.rs
1use crate::prelude::*;
2
3/// Parameters for requesting open interest data.
4///
5/// This struct defines the parameters for querying open interest via the `/v5/market/open-interest` endpoint. Open interest represents the total number of outstanding contracts, a key metric for assessing market participation and sentiment in perpetual futures.
6#[derive(Clone, Default)]
7pub struct OpenInterestRequest<'a> {
8 /// The product category (e.g., Linear, Inverse).
9 ///
10 /// Specifies the instrument type. For perpetual futures, use `Linear` or `Inverse`. Bots must set this to fetch open interest for the correct contract type.
11 pub category: Category,
12
13 /// The trading pair symbol (e.g., "BTCUSDT").
14 ///
15 /// Identifies the perpetual futures contract. Bots must specify a valid symbol to retrieve open interest data.
16 pub symbol: Cow<'a, str>,
17
18 /// The time interval for open interest data (e.g., "5min", "1h", "1d").
19 ///
20 /// Specifies the granularity of the open interest data, such as `5min` (5 minutes), `1h` (1 hour), or `1d` (1 day). Bots should choose an interval that aligns with their analysis timeframe—shorter intervals for intraday strategies, longer for trend analysis.
21 pub interval: Cow<'a, str>,
22
23 /// The start time for the open interest data (Unix timestamp in milliseconds).
24 ///
25 /// Defines the beginning of the time range. Bots should set this for historical open interest analysis, such as studying market participation trends in perpetual futures.
26 pub start_time: Option<u64>,
27
28 /// The end time for the open interest data (Unix timestamp in milliseconds).
29 ///
30 /// Defines the end of the time range. Bots should set this to limit data to a specific period, optimizing performance when processing large datasets.
31 pub end_time: Option<u64>,
32
33 /// The maximum number of records to return (1-200, default: 200).
34 ///
35 /// Controls the number of open interest records returned. Bots should set a reasonable limit to balance data completeness with performance, especially for high-frequency strategies requiring real-time data.
36 pub limit: Option<u64>,
37}
38
39impl<'a> OpenInterestRequest<'a> {
40 /// Creates a default OpenInterest request.
41 ///
42 /// Returns a request with `category` set to `Linear`, `symbol` set to `"BTCUSDT"`, and `interval` set to `"1h"`. Suitable for testing but should be customized for production to match specific trading needs and analysis timeframes.
43 pub fn default() -> OpenInterestRequest<'a> {
44 OpenInterestRequest::new(Category::Linear, "BTCUSDT", "1h", None, None, None)
45 }
46 /// Constructs a new OpenInterest request with specified parameters.
47 ///
48 /// Allows full customization. Bots should use this to specify the exact symbol, interval, and time range to align with their strategy for analyzing open interest in perpetual futures.
49 pub fn new(
50 category: Category,
51 symbol: &'a str,
52 interval: &'a str,
53 start_time: Option<u64>,
54 end_time: Option<u64>,
55 limit: Option<u64>,
56 ) -> OpenInterestRequest<'a> {
57 OpenInterestRequest {
58 category,
59 symbol: Cow::Borrowed(symbol),
60 interval: Cow::Borrowed(interval),
61 start_time,
62 end_time,
63 limit,
64 }
65 }
66}