Skip to main content

DcpRequest

Struct DcpRequest 

Source
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 only
  • DERIVATIVES: 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: i32

Disconnection 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>

Source

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.

Source

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”.

Source

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”.

Source

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”.

Source

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 valid
  • Err(String) - If time_window is outside valid range

Trait Implementations§

Source§

impl<'a> Clone for DcpRequest<'a>

Source§

fn clone(&self) -> DcpRequest<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for DcpRequest<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for DcpRequest<'a>

Source§

fn default() -> DcpRequest<'a>

Returns the “default value” for a type. Read more
Source§

impl<'de, 'a> Deserialize<'de> for DcpRequest<'a>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> Serialize for DcpRequest<'a>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for DcpRequest<'a>

§

impl<'a> RefUnwindSafe for DcpRequest<'a>

§

impl<'a> Send for DcpRequest<'a>

§

impl<'a> Sync for DcpRequest<'a>

§

impl<'a> Unpin for DcpRequest<'a>

§

impl<'a> UnsafeUnpin for DcpRequest<'a>

§

impl<'a> UnwindSafe for DcpRequest<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,