pub struct DcpRequest<'a> {
pub product: Option<Cow<'a, str>>,
pub time_window: i32,
}Expand description
Represents a request to set Disconnection Protection (DCP) parameters on Bybit.
Disconnection Protection (DCP) automatically cancels all active orders if the client remains disconnected from Bybit’s WebSocket for longer than the specified time window. This helps prevent unintended order execution during connection issues. Bots should configure DCP based on their reconnection strategy and risk tolerance.
Fields§
§product: Option<Cow<'a, str>>Product type for which DCP applies.
Specifies which product category’s orders should be cancelled on disconnection:
OPTIONS(default): Options orders onlyDERIVATIVES: Futures and perpetual orders (Inverse Perp, Inverse Futures, USDT Perp, USDT Futures, USDC Perp, USDC Futures)SPOT: Spot orders only
Bots should set this based on which markets they are actively trading. The default is “OPTIONS” if not specified.
time_window: i32Disconnection timing window in seconds.
The time window (in seconds) after disconnection before orders are cancelled. Valid range: 3 to 300 seconds. Default is 10 seconds if not configured. Bots should set this based on their expected reconnection time and risk appetite. Shorter windows provide faster protection but may trigger unnecessarily during brief network interruptions.
Implementations§
Source§impl<'a> DcpRequest<'a>
impl<'a> DcpRequest<'a>
Sourcepub fn new(time_window: i32, product: Option<&'a str>) -> Self
pub fn new(time_window: i32, product: Option<&'a str>) -> Self
Constructs a new DcpRequest with specified parameters.
Creates a request to configure Disconnection Protection with a specific time window and optional product filter.
§Arguments
time_window- Disconnection timing window in seconds (3-300)product- Optional product type (“OPTIONS”, “DERIVATIVES”, or “SPOT”)
§Returns
A new DcpRequest instance.
§Panics
This function does not panic, but Bybit API will reject time_window values outside the 3-300 range.
Sourcepub fn derivatives_default() -> Self
pub fn derivatives_default() -> Self
Constructs a DcpRequest for derivatives with default 10-second window.
Creates a request with 10-second time window for derivatives products. This is a common configuration for futures and perpetual trading bots.
§Returns
A DcpRequest with time_window=10 and product=“DERIVATIVES”.
Sourcepub fn spot_default() -> Self
pub fn spot_default() -> Self
Constructs a DcpRequest for spot with default 10-second window.
Creates a request with 10-second time window for spot products. This is a common configuration for spot trading bots.
§Returns
A DcpRequest with time_window=10 and product=“SPOT”.
Sourcepub fn options_default() -> Self
pub fn options_default() -> Self
Constructs a DcpRequest for options with default 10-second window.
Creates a request with 10-second time window for options products. This is the default configuration used by Bybit.
§Returns
A DcpRequest with time_window=10 and product=“OPTIONS”.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates the DcpRequest parameters.
Checks if the time_window is within the valid range (3-300 seconds). Bots should call this before sending the request to avoid API errors.
§Returns
Ok(())- If parameters are validErr(String)- If time_window is outside valid range
Trait Implementations§
Source§impl<'a> Clone for DcpRequest<'a>
impl<'a> Clone for DcpRequest<'a>
Source§fn clone(&self) -> DcpRequest<'a>
fn clone(&self) -> DcpRequest<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more