pub struct OrderbookRequest<'a> {
pub symbol: Cow<'a, str>,
pub category: Category,
pub limit: Option<u64>,
}Expand description
Parameters for requesting order book data.
This struct defines the parameters for querying the order book via the /v5/market/orderbook endpoint.
The order book shows current bid and ask prices and quantities, critical for liquidity analysis
and order placement in perpetual futures.
Fields§
§symbol: Cow<'a, str>The trading pair symbol (e.g., “BTCUSDT”).
Identifies the perpetual futures contract. Bots must specify a valid symbol to fetch the correct order book.
category: CategoryThe product category (e.g., Linear, Inverse, Spot, Option).
Specifies the instrument type. For perpetual futures, use Linear or Inverse.
Bots must set this correctly to avoid errors.
limit: Option<u64>The maximum number of order book levels to return.
Controls the depth of the order book (number of bid/ask levels). The valid range depends on the category:
spot: [1, 200], default: 1linear&inverse: [1, 500], default: 25option: [1, 25], default: 1
Bots should balance depth with performance: deeper books provide more liquidity data but increase latency and memory usage.
Implementations§
Source§impl<'a> OrderbookRequest<'a>
impl<'a> OrderbookRequest<'a>
Sourcepub fn default() -> OrderbookRequest<'a>
pub fn default() -> OrderbookRequest<'a>
Creates a default Orderbook request.
Returns a request with symbol set to "BTCUSDT" and category set to Linear.
Suitable for testing but should be customized for production.
Sourcepub fn new(
symbol: &'a str,
category: Category,
limit: Option<u64>,
) -> OrderbookRequest<'a>
pub fn new( symbol: &'a str, category: Category, limit: Option<u64>, ) -> OrderbookRequest<'a>
Constructs a new Orderbook request with specified parameters.
Allows customization. Bots should use this to specify the exact symbol and category for their perpetual futures strategy.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates the request parameters according to API constraints.
Returns Ok(()) if the request is valid, or Err(String) with an error message.
Sourcepub fn default_limit(&self) -> u64
pub fn default_limit(&self) -> u64
Gets the default limit value for the category.
Returns the default limit value based on the category:
spot: 1linear&inverse: 25option: 1
Sourcepub fn effective_limit(&self) -> u64
pub fn effective_limit(&self) -> u64
Gets the effective limit value (either the specified limit or the default).
Returns the limit value to use for the API request.
Sourcepub fn spot(symbol: &'a str, limit: Option<u64>) -> OrderbookRequest<'a>
pub fn spot(symbol: &'a str, limit: Option<u64>) -> OrderbookRequest<'a>
Creates a request for spot trading pairs.
Convenience method for creating requests for spot markets.
Sourcepub fn linear(symbol: &'a str, limit: Option<u64>) -> OrderbookRequest<'a>
pub fn linear(symbol: &'a str, limit: Option<u64>) -> OrderbookRequest<'a>
Creates a request for linear perpetual futures.
Convenience method for creating requests for USDT-margined perpetual futures.
Trait Implementations§
Source§impl<'a> Clone for OrderbookRequest<'a>
impl<'a> Clone for OrderbookRequest<'a>
Source§fn clone(&self) -> OrderbookRequest<'a>
fn clone(&self) -> OrderbookRequest<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more