pub struct Trader {
pub client: Client,
pub recv_window: u16,
}Fields§
§client: Client§recv_window: u16Implementations§
Source§impl Trader
impl Trader
pub async fn place_custom_order<'b>( &self, req: OrderRequest<'_>, ) -> Result<OrderResponse, BybitError>
pub async fn place_futures_limit_order( &self, category: Category, symbol: &str, side: Side, qty: f64, price: f64, mode: u8, ) -> Result<OrderResponse, BybitError>
pub async fn amend_order<'b>( &self, req: AmendOrderRequest<'_>, ) -> Result<AmendOrderResponse, BybitError>
pub async fn cancel_order<'b>( &self, req: CancelOrderRequest<'_>, ) -> Result<CancelOrderResponse, BybitError>
pub async fn get_open_orders<'b>( &self, req: OpenOrdersRequest<'_>, ) -> Result<OpenOrdersResponse, BybitError>
pub async fn cancel_all_orders<'b>( &self, req: CancelAllRequest<'_>, ) -> Result<CancelAllResponse, BybitError>
Sourcepub async fn get_order_history<'b>(
&self,
req: OrderHistoryRequest<'_>,
) -> Result<OrderHistoryResponse, BybitError>
pub async fn get_order_history<'b>( &self, req: OrderHistoryRequest<'_>, ) -> Result<OrderHistoryResponse, BybitError>
Sourcepub async fn get_trade_history<'b>(
&self,
req: TradeHistoryRequest<'_>,
) -> Result<TradeHistoryResponse, BybitError>
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- ATradeHistoryRequestcontaining 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.
Sourcepub async fn batch_place_order<'b>(
&self,
req: BatchPlaceRequest<'_>,
) -> Result<BatchPlaceResponse, BybitError>
pub async fn batch_place_order<'b>( &self, req: BatchPlaceRequest<'_>, ) -> Result<BatchPlaceResponse, BybitError>
Sourcepub async fn batch_amend_order<'b>(
&self,
req: BatchAmendRequest<'_>,
) -> Result<BatchAmendResponse, BybitError>
pub async fn batch_amend_order<'b>( &self, req: BatchAmendRequest<'_>, ) -> Result<BatchAmendResponse, BybitError>
Sourcepub async fn batch_cancel_order<'b>(
&self,
req: BatchCancelRequest<'_>,
) -> Result<BatchCancelResponse, BybitError>
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- ABatchCancelRequestcontaining 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.
Sourcepub async fn get_borrow_quota_spot<'b>(
&self,
req: BorrowQuotaRequest<'_>,
) -> Result<BorrowQuotaResponse, BybitError>
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 informationErr(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
Sourcepub async fn set_dcp_options<'b>(
&self,
req: DcpRequest<'_>,
) -> Result<DcpResponse, BybitError>
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 successfullyErr(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
Sourcepub async fn pre_check_order<'b>(
&self,
req: OrderRequest<'_>,
) -> Result<PreCheckOrderResponse, BybitError>
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 calculationsErr(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
inversecategory, Cross Margin mode is not supported