pub struct PriceLimitData {
pub symbol: String,
pub buy_lmt: f64,
pub sell_lmt: f64,
}Expand description
Represents the order price limits for a single trading symbol in a WebSocket update.
Contains the highest bid price (buyLmt) and lowest ask price (sellLmt) for a given symbol. These limits define the order price boundaries for derivative or spot trading and are important for risk management and order validation.
§Bybit API Reference
The Bybit WebSocket API (https://bybit-exchange.github.io/docs/v5/websocket/public/order-price-limit) provides real-time order price limit updates with a push frequency of 300ms.
Fields§
§symbol: StringThe trading pair symbol (e.g., “BTCUSDT”).
Identifies the specific instrument for which the price limits apply. Trading bots should verify this matches the requested symbol to ensure data integrity.
buy_lmt: f64The highest bid price allowed (buy limit) as a string.
Represents the maximum price at which buy orders can be placed. Orders with prices above this limit will be rejected. Trading bots must ensure buy order prices do not exceed this limit.
sell_lmt: f64The lowest ask price allowed (sell limit) as a string.
Represents the minimum price at which sell orders can be placed. Orders with prices below this limit will be rejected. Trading bots must ensure sell order prices are not below this limit.
Implementations§
Source§impl PriceLimitData
impl PriceLimitData
Sourcepub fn new(symbol: &str, buy_lmt: f64, sell_lmt: f64) -> Self
pub fn new(symbol: &str, buy_lmt: f64, sell_lmt: f64) -> Self
Constructs a new PriceLimitData with specified parameters.
Sourcepub fn is_buy_limit_valid(&self) -> bool
pub fn is_buy_limit_valid(&self) -> bool
Returns true if the buy limit is valid (positive value).
Sourcepub fn is_sell_limit_valid(&self) -> bool
pub fn is_sell_limit_valid(&self) -> bool
Returns true if the sell limit is valid (positive value).
Sourcepub fn price_range(&self) -> f64
pub fn price_range(&self) -> f64
Returns the price range between buy and sell limits.
Calculated as sell_lmt - buy_lmt. A positive value indicates normal market conditions
where sell limit is higher than buy limit. A negative value would indicate abnormal
market conditions.
Sourcepub fn mid_price(&self) -> f64
pub fn mid_price(&self) -> f64
Returns the mid price between buy and sell limits.
Calculated as (buy_lmt + sell_lmt) / 2.0. This represents the theoretical
fair value within the allowed trading range.
Sourcepub fn price_range_percentage(&self) -> f64
pub fn price_range_percentage(&self) -> f64
Returns the price range as a percentage of the mid price.
Useful for understanding the relative width of the allowed trading range.
Calculated as price_range() / mid_price() * 100.0.
Sourcepub fn is_buy_price_allowed(&self, price: f64) -> bool
pub fn is_buy_price_allowed(&self, price: f64) -> bool
Checks if a buy price is within the allowed limit.
Returns true if price <= buy_lmt, meaning the buy order price is acceptable.
Sourcepub fn is_sell_price_allowed(&self, price: f64) -> bool
pub fn is_sell_price_allowed(&self, price: f64) -> bool
Checks if a sell price is within the allowed limit.
Returns true if price >= sell_lmt, meaning the sell order price is acceptable.
Sourcepub fn buy_slippage_limit(&self, reference_price: f64) -> f64
pub fn buy_slippage_limit(&self, reference_price: f64) -> f64
Returns the maximum allowable slippage for buy orders.
Calculated as (buy_lmt - reference_price) / reference_price where reference_price
is typically the current market price or the price a bot intends to use.
Sourcepub fn sell_slippage_limit(&self, reference_price: f64) -> f64
pub fn sell_slippage_limit(&self, reference_price: f64) -> f64
Returns the maximum allowable slippage for sell orders.
Calculated as (reference_price - sell_lmt) / reference_price where reference_price
is typically the current market price or the price a bot intends to use.
Sourcepub fn limits(&self) -> (f64, f64)
pub fn limits(&self) -> (f64, f64)
Returns the price limits as a tuple (buy_limit, sell_limit).
Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Returns a string representation of the price limits.
Sourcepub fn expiry_timestamp(&self) -> Option<DateTime<Utc>>
pub fn expiry_timestamp(&self) -> Option<DateTime<Utc>>
Returns the timestamp from the symbol, if it contains expiry information.
For futures contracts with expiry dates in the symbol (e.g., “BTC-26DEC25”), this attempts to extract and parse the expiry date.
Sourcepub fn is_perpetual(&self) -> bool
pub fn is_perpetual(&self) -> bool
Returns true if this is a perpetual contract (no expiry).
Sourcepub fn is_futures(&self) -> bool
pub fn is_futures(&self) -> bool
Returns true if this is a futures contract (has expiry).
Trait Implementations§
Source§impl Clone for PriceLimitData
impl Clone for PriceLimitData
Source§fn clone(&self) -> PriceLimitData
fn clone(&self) -> PriceLimitData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more