Skip to main content

Trader

Struct Trader 

Source
pub struct Trader {
    pub client: Client,
    pub recv_window: u16,
}

Fields§

§client: Client§recv_window: u16

Implementations§

Source§

impl Trader

Source

pub async fn place_custom_order<'b>( &self, req: OrderRequest<'_>, ) -> Result<OrderResponse, BybitError>

Source

pub async fn place_futures_limit_order( &self, category: Category, symbol: &str, side: Side, qty: f64, price: f64, mode: u8, ) -> Result<OrderResponse, BybitError>

Source

pub async fn amend_order<'b>( &self, req: AmendOrderRequest<'_>, ) -> Result<AmendOrderResponse, BybitError>

Source

pub async fn cancel_order<'b>( &self, req: CancelOrderRequest<'_>, ) -> Result<CancelOrderResponse, BybitError>

Source

pub async fn get_open_orders<'b>( &self, req: OpenOrdersRequest<'_>, ) -> Result<OpenOrdersResponse, BybitError>

Source

pub async fn cancel_all_orders<'b>( &self, req: CancelAllRequest<'_>, ) -> Result<CancelAllResponse, BybitError>

Source

pub async fn get_order_history<'b>( &self, req: OrderHistoryRequest<'_>, ) -> Result<OrderHistoryResponse, BybitError>

Retrieves the order history based on the given request parameters.

§Arguments
  • req - An instance of OrderHistoryRequest containing the request parameters.
§Returns

A Result wrapping OrderHistory which contains the historical orders’ data. If the operation fails, it returns an error.

Source

pub async fn get_trade_history<'b>( &self, req: TradeHistoryRequest<'_>, ) -> Result<TradeHistoryResponse, BybitError>

Retrieves the trade history for a specific trading pair, order, or time range.

§Arguments
  • req - A TradeHistoryRequest containing the parameters for the trade history query.
§Returns

Returns a Result<TradeHistoryResponse, BybitError> containing the trade history data if the query is successful, or an error detailing the problem if the query fails.

Source

pub async fn batch_place_order<'b>( &self, req: BatchPlaceRequest<'_>, ) -> Result<BatchPlaceResponse, BybitError>

Asynchronously places a batch of orders using the Bybit API.

§Arguments
  • req - The BatchPlaceRequest containing the orders to be placed.
§Returns

Returns a Result containing a BatchPlaceResponse on success or a BybitError on failure.

Source

pub async fn batch_amend_order<'b>( &self, req: BatchAmendRequest<'_>, ) -> Result<BatchAmendResponse, BybitError>

Sends a batch request to amend multiple orders at once.

§Arguments
  • req - The BatchAmendRequest containing the orders to amend.
§Returns

A Result containing a BatchAmendResponse on success or a BybitError on failure.

Source

pub async fn batch_cancel_order<'b>( &self, req: BatchCancelRequest<'_>, ) -> Result<BatchCancelResponse, BybitError>

Cancel a batch of orders from the Bybit API

This function will send a signed POST request to the Bybit API to cancel a batch of orders. The request should contain the category, symbol, order_id, and order_link_id for each order to be cancelled.

§Arguments
  • req - A BatchCancelRequest containing the details of the orders to be cancelled.
§Returns

A BatchCancelResponse containing the result of the request.

§Errors

Returns an error if the request fails or if the Bybit API returns an error response.

Source

pub async fn get_borrow_quota_spot<'b>( &self, req: BorrowQuotaRequest<'_>, ) -> Result<BorrowQuotaResponse, BybitError>

Query the available balance for Spot trading and Margin trading.

This endpoint returns information about maximum trade quantities and amounts available for spot trading, including both actual balances and borrowable amounts. It helps bots determine available trading capacity before placing orders.

§Arguments
  • req - The borrow quota request containing symbol and side
§Returns
  • Ok(BorrowQuotaResponse) - The borrow quota information
  • Err(BybitError) - If the request fails or API returns an error
§Notes
  • Only supports category=spot
  • During periods of extreme market volatility, this interface may experience increased latency or temporary delays in data delivery
Source

pub async fn set_dcp_options<'b>( &self, req: DcpRequest<'_>, ) -> Result<DcpResponse, BybitError>

Configure Disconnection Protection (DCP) parameters.

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.

§Arguments
  • req - The DCP configuration request containing time window and product type
§Returns
  • Ok(DcpResponse) - Confirmation that DCP was configured successfully
  • Err(BybitError) - If the request fails or API returns an error
§Notes
  • After the request is successfully sent, the system needs a certain time to take effect
  • It is recommended to query or set again after 10 seconds
  • Your private websocket connection must subscribe to “dcp” topic to trigger DCP successfully
  • Valid time window range: 3 to 300 seconds
  • Default product is “OPTIONS” if not specified
Source

pub async fn pre_check_order<'b>( &self, req: OrderRequest<'_>, ) -> Result<PreCheckOrderResponse, BybitError>

Pre-check an order to calculate margin impact before placement.

This endpoint calculates the changes in Initial Margin Requirement (IMR) and Maintenance Margin Requirement (MMR) before and after placing an order. It supports categories: inverse, linear, and option.

§Arguments
  • req - The order request to pre-check
§Returns
  • Ok(PreCheckOrderResponse) - The pre-check results with margin calculations
  • Err(BybitError) - If the request fails or API returns an error
§Notes
  • Only Cross Margin mode and Portfolio Margin mode are supported
  • Isolated margin mode is not supported
  • Conditional orders are not supported
  • For inverse category, Cross Margin mode is not supported
Source

pub fn build_orders<'b>(action: Action<'_>) -> BTreeMap<String, Value>

Trait Implementations§

Source§

impl Bybit for Trader

Source§

fn new(api_key: Option<String>, secret_key: Option<String>) -> Trader

Creates a new instance of the module with default configuration. Read more
Source§

fn new_with_config( config: &Config, api_key: Option<String>, secret_key: Option<String>, ) -> Trader

Creates a new instance of the module with custom configuration. Read more
Source§

impl Clone for Trader

Source§

fn clone(&self) -> Trader

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

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