bybit/models/instrument_request.rs
1use crate::prelude::*;
2
3/// Parameters for requesting instrument information.
4///
5/// This struct defines the parameters for querying instrument details via the `/v5/market/instruments-info` endpoint. For perpetual futures, instrument info includes leverage, price filters, and lot size filters, which are critical for configuring trading bot parameters.
6#[derive(Clone, Default)]
7pub struct InstrumentRequest<'a> {
8 /// The product category (e.g., Linear, Inverse, Spot, Option).
9 ///
10 /// Specifies the instrument type. For perpetual futures, use `Linear` or `Inverse`. Bots must set this to filter relevant instruments.
11 pub category: Category,
12
13 /// The trading pair symbol (e.g., "BTCUSDT").
14 ///
15 /// Optionally specifies a single trading pair. If unset, the API returns data for all instruments in the category, which may be voluminous. Bots should set this for specific pairs to reduce response size and latency.
16 pub symbol: Option<Cow<'a, str>>,
17
18 /// The trading status of the instrument (true for trading, false for not trading).
19 ///
20 /// Filters instruments by their trading status. Useful for bots to exclude delisted or inactive perpetual futures contracts. If unset, all statuses are returned.
21 pub status: Option<bool>,
22
23 /// The base coin of the instrument (e.g., "BTC").
24 ///
25 /// Filters instruments by their base asset. For example, setting `base_coin` to `"BTC"` returns all BTC-based perpetuals (e.g., `BTCUSDT`, `BTCUSD`). Useful for bots targeting specific assets.
26 pub base_coin: Option<Cow<'a, str>>,
27
28 /// The maximum number of instruments to return (1-1000, default: 500).
29 ///
30 /// Controls the response size. Bots should set a reasonable limit to balance data completeness and performance, especially when querying all instruments in a category.
31 pub limit: Option<u64>,
32}
33
34impl<'a> InstrumentRequest<'a> {
35 /// Creates a default Instrument request.
36 ///
37 /// Returns a request with `category` set to `Linear` and `symbol` set to `"BTCUSDT"`. Suitable for testing but should be customized for production to match specific trading needs.
38 pub fn default() -> InstrumentRequest<'a> {
39 InstrumentRequest::new(Category::Linear, Some("BTCUSDT"), None, None, None)
40 }
41 /// Constructs a new Instrument request with specified parameters.
42 ///
43 /// Allows full customization. Bots should use this to tailor requests to their strategy, ensuring `category` and `symbol` align with the perpetual futures being traded.
44 pub fn new(
45 category: Category,
46 symbol: Option<&'a str>,
47 status: Option<bool>,
48 base_coin: Option<&'a str>,
49 limit: Option<u64>,
50 ) -> InstrumentRequest<'a> {
51 InstrumentRequest {
52 category,
53 symbol: symbol.map(Cow::Borrowed),
54 status,
55 base_coin: base_coin.map(Cow::Borrowed),
56 limit,
57 }
58 }
59}