Skip to main content

TradingStopRequest

Struct TradingStopRequest 

Source
pub struct TradingStopRequest<'a> {
Show 16 fields pub category: Category, pub symbol: Cow<'a, str>, pub tpsl_mode: Cow<'a, str>, pub position_idx: i32, pub take_profit: Option<f64>, pub stop_loss: Option<f64>, pub trailing_stop: Option<f64>, pub tp_trigger_by: Option<Cow<'a, str>>, pub sl_trigger_by: Option<Cow<'a, str>>, pub active_price: Option<f64>, pub tp_size: Option<f64>, pub sl_size: Option<f64>, pub tp_limit_price: Option<f64>, pub sl_limit_price: Option<f64>, pub tp_order_type: Option<OrderType>, pub sl_order_type: Option<OrderType>,
}
Expand description

Parameters for setting trading stop conditions (take-profit/stop-loss/trailing-stop).

Used to construct a request to the /v5/position/trading-stop endpoint to set take-profit, stop-loss, and trailing-stop conditions for a position. Bots use this to implement automated exit strategies and manage risk in perpetual futures trading. This struct supports both full and partial take-profit/stop-loss modes, allowing precise control over position exits.

§Bybit API Reference

According to the Bybit V5 API documentation:

  • New version of TP/SL function supports both holding entire position TP/SL orders and holding partial position TP/SL orders.
  • Full position TP/SL orders: This API can be used to modify parameters of existing TP/SL orders.
  • Partial position TP/SL orders: This API can only add partial position TP/SL orders.
  • Under the new version of TP/SL function, when calling this API to perform one-sided take profit or stop loss modification on existing TP/SL orders on the holding position, it will cause the paired tp/sl orders to lose binding relationship.

Fields§

§category: Category

The product category (e.g., Linear, Inverse).

Specifies the instrument type, such as Linear for USDT-margined perpetual futures. Bots must set this correctly to target the desired contract type.

§symbol: Cow<'a, str>

The trading pair symbol (e.g., “BTCUSDT”).

Identifies the perpetual futures contract for which trading stops are being set. Bots must specify a valid symbol to ensure the request targets the correct position.

§tpsl_mode: Cow<'a, str>

The take-profit/stop-loss mode (e.g., “Full”, “Partial”).

Specifies whether the trading stops apply to the entire position (Full) or a portion (Partial). Bots use this to implement granular exit strategies, such as scaling out of positions. This parameter is required according to the Bybit API documentation.

§position_idx: i32

The position index (e.g., 0 for one-way mode, 1 or 2 for hedge mode).

Used to identify positions in different position modes.

  • 0: one-way mode
  • 1: hedge-mode Buy side
  • 2: hedge-mode Sell side This parameter is required according to the Bybit API documentation.
§take_profit: Option<f64>

The take-profit price (optional).

The price at which the position will close for a profit. Bots use this to lock in gains automatically, typically based on technical indicators or predefined targets. Cannot be less than 0, 0 means cancel TP.

§stop_loss: Option<f64>

The stop-loss price (optional).

The price at which the position will close to limit losses. Bots use this to manage downside risk, protecting capital during adverse market movements. Cannot be less than 0, 0 means cancel SL.

§trailing_stop: Option<f64>

The trailing stop by price distance (optional).

Trailing stop by price distance. Cannot be less than 0, 0 means cancel TS. Bots use this to implement dynamic stop-loss strategies that follow favorable price movements.

§tp_trigger_by: Option<Cow<'a, str>>

The trigger type for take-profit (optional).

Specifies the price type used to trigger the take-profit order (e.g., LastPrice, MarkPrice, IndexPrice). Bots should choose a trigger type that aligns with their strategy to balance responsiveness and stability.

§sl_trigger_by: Option<Cow<'a, str>>

The trigger type for stop-loss (optional).

Specifies the price type used to trigger the stop-loss order. Bots should select a trigger type that minimizes slippage while ensuring timely execution in volatile markets.

§active_price: Option<f64>

The trailing stop trigger price (optional).

Trailing stop will be triggered when this price is reached only. Bots use this to set an activation price for trailing stops, ensuring they only become active after a certain profit level is reached.

§tp_size: Option<f64>

The size of the take-profit order (optional).

The quantity of the position to close when the take-profit is triggered, used in TP/SL partial mode. Note: the value of tp_size and sl_size must equal. Bots use this to scale out of positions incrementally, optimizing profit capture.

§sl_size: Option<f64>

The size of the stop-loss order (optional).

The quantity of the position to close when the stop-loss is triggered, used in TP/SL partial mode. Note: the value of tp_size and sl_size must equal. Bots use this to limit losses on specific portions of a position.

§tp_limit_price: Option<f64>

The limit price for the take-profit order (optional).

The specific price for a Limit take-profit order. Only works when tpslMode=Partial and tpOrderType=Limit. Bots use this to ensure the take-profit order executes at a favorable price, avoiding slippage in stable markets.

§sl_limit_price: Option<f64>

The limit price for the stop-loss order (optional).

The specific price for a Limit stop-loss order. Only works when tpslMode=Partial and slOrderType=Limit. Bots use this cautiously, as limit orders may not execute in fast-moving markets, increasing risk exposure.

§tp_order_type: Option<OrderType>

The order type when take profit is triggered (optional).

The order type when take profit is triggered. Market (default), Limit. For tpslMode=Full, it only supports tpOrderType=“Market”. Bots can use Limit orders to target specific exit prices, reducing slippage.

§sl_order_type: Option<OrderType>

The order type when stop loss is triggered (optional).

The order type when stop loss is triggered. Market (default), Limit. For tpslMode=Full, it only supports slOrderType=“Market”. Bots typically use Market orders for stop-losses to ensure execution.

Implementations§

Source§

impl<'a> TradingStopRequest<'a>

Source

pub fn new( category: Category, symbol: &'a str, tpsl_mode: &'a str, position_idx: i32, take_profit: Option<f64>, stop_loss: Option<f64>, trailing_stop: Option<f64>, tp_trigger_by: Option<&'a str>, sl_trigger_by: Option<&'a str>, active_price: Option<f64>, tp_size: Option<f64>, sl_size: Option<f64>, tp_limit_price: Option<f64>, sl_limit_price: Option<f64>, tp_order_type: Option<OrderType>, sl_order_type: Option<OrderType>, ) -> Self

Constructs a new TradingStop request with specified parameters.

Allows full customization of the trading stop request. Bots should use this to define the exact symbol, category, and trading stop parameters to align with their risk management strategy.

§Arguments
  • category - The product category (Linear, Inverse)
  • symbol - The trading pair symbol (e.g., “BTCUSDT”)
  • tpsl_mode - The TP/SL mode (“Full” or “Partial”)
  • position_idx - The position index (0: one-way, 1: hedge buy, 2: hedge sell)
  • take_profit - The take-profit price (optional, 0 means cancel)
  • stop_loss - The stop-loss price (optional, 0 means cancel)
  • trailing_stop - The trailing stop distance (optional, 0 means cancel)
  • tp_trigger_by - The trigger type for take-profit (optional)
  • sl_trigger_by - The trigger type for stop-loss (optional)
  • active_price - The trailing stop trigger price (optional)
  • tp_size - The take-profit size for partial mode (optional)
  • sl_size - The stop-loss size for partial mode (optional)
  • tp_limit_price - The limit price for take-profit (optional)
  • sl_limit_price - The limit price for stop-loss (optional)
  • tp_order_type - The order type for take-profit (optional)
  • sl_order_type - The order type for stop-loss (optional)
Source

pub fn default() -> TradingStopRequest<'a>

Creates a default TradingStop request.

Returns a request with category set to Linear, symbol set to "BTCUSDT", tpsl_mode set to "Full", position_idx set to 0 (one-way mode), and all other fields unset. Suitable for testing but should be customized for production to match specific trading needs.

Source

pub fn validate(&self) -> Result<(), String>

Validates the request parameters according to Bybit API constraints.

Bots should call this method before sending the request to ensure compliance with API limits and requirements.

§Returns
  • Ok(()) if validation passes
  • Err(String) with error message if validation fails

Trait Implementations§

Source§

impl<'a> Clone for TradingStopRequest<'a>

Source§

fn clone(&self) -> TradingStopRequest<'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> Default for TradingStopRequest<'a>

Source§

fn default() -> TradingStopRequest<'a>

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

Auto Trait Implementations§

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