Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new(cfg: Config) -> Result<Self, Error>

Source§

impl Client

Source

pub async fn get_server_time(&self) -> Result<Response<ServerTime>, Error>

Source

pub async fn get_kline( &self, params: GetKLinesParams, ) -> Result<Response<KLine>, Error>

Source

pub async fn get_tickers( &self, params: GetTickersParams, ) -> Result<Response<Ticker>, Error>

Get Tickers Query for the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours. If category=option, symbol or baseCoin must be passed.

Source

pub async fn get_instruments_info( &self, params: GetInstrumentsInfoParams, ) -> Result<Response<InstrumentsInfo>, Error>

Source

pub async fn get_public_recent_trading_history( &self, params: GetTradesParams, ) -> Result<Response<Trade>, Error>

Source§

impl Client

Source

pub async fn place_order( &self, request: PlaceOrderRequest, ) -> Result<Response<PlaceOrderResponse>, Error>

Place Order This endpoint supports to create the order for Spot, Margin trading, USDT perpetual, USDT futures, USDC perpetual, USDC futures, Inverse Futures and Options.

INFO: Supported order type (orderType): Limit order: orderType=Limit, it is necessary to specify order qty and price.

Market order: orderType=Market, execute at the best price in the Bybit market until the transaction is completed. When selecting a market order, the “price” can be empty. In the futures trading system, in order to protect traders against the serious slippage of the Market order, Bybit trading engine will convert the market order into an IOC limit order for matching. If there are no orderbook entries within price slippage limit, the order will not be executed. If there is insufficient liquidity, the order will be cancelled. The slippage threshold refers to the percentage that the order price deviates from the mark price. You can learn more here: Adjustments to Bybit’s Derivative Trading Price Limit Mechanism Supported timeInForce strategy: GTC IOC FOK PostOnly: If the order would be filled immediately when submitted, it will be cancelled. The purpose of this is to protect your order during the submission process. If the matching system cannot entrust the order to the order book due to price changes on the market, it will be cancelled. RPI: Retail Price Improvement order. Assigned market maker can place this kind of order, and it is a post only order, only match with the order from Web or APP.

How to create a conditional order: When submitting an order, if triggerPrice is set, the order will be automatically converted into a conditional order. In addition, the conditional order does not occupy the margin. If the margin is insufficient after the conditional order is triggered, the order will be cancelled.

Take profit / Stop loss: You can set TP/SL while placing orders. Besides, you could modify the position’s TP/SL.

Order quantity: The quantity of perpetual contracts you are going to buy/sell. For the order quantity, Bybit only supports positive number at present.

Order price: Place a limit order, this parameter is required. If you have position, the price should be higher than the liquidation price. For the minimum unit of the price change, please refer to the priceFilter > tickSize field in the instruments-info endpoint.

orderLinkId: You can customize the active order ID. We can link this ID to the order ID in the system. Once the active order is successfully created, we will send the unique order ID in the system to you. Then, you can use this order ID to cancel active orders, and if both orderId and orderLinkId are entered in the parameter input, Bybit will prioritize the orderId to process the corresponding order. Meanwhile, your customized order ID should be no longer than 36 characters and should be unique.

Open orders up limit: Perps & Futures: a) Each account can hold a maximum of 500 active orders simultaneously per symbol. b) conditional orders: each account can hold a maximum of 10 active orders simultaneously per symbol. Spot: 500 orders in total, including a maximum of 30 open TP/SL orders, a maximum of 30 open conditional orders for each symbol per account Option: a maximum of 50 open orders per account

Rate limit: Please refer to rate limit table. If you need to raise the rate limit, please contact your client manager or submit an application via here

Risk control limit notice: Bybit will monitor on your API requests. When the total number of orders of a single user (aggregated the number of orders across main account and subaccounts) within a day (UTC 0 - UTC 24) exceeds a certain upper limit, the platform will reserve the right to remind, warn, and impose necessary restrictions. Customers who use API default to acceptance of these terms and have the obligation to cooperate with adjustments.

Reduce only orders: If reduceOnly=true and order qty > max order qty, the order will automatically be split up into multiple orders.

Spot Stop Order Spot supports TP/SL order, Conditional order, however, the system logic is different between classic account and Unified account classic account: When the stop order is created, you will get an order ID. After it is triggered, you will get a new order ID Unified account: When the stop order is created, you will get an order ID. After it is triggered, the order ID will not be changed

Source

pub async fn amend_order( &self, request: AmendOrderRequest, ) -> Result<Response<AmendOrderResponse>, Error>

Amend Order info You can only modify unfilled or partially filled orders.

Source

pub async fn cancel_order( &self, request: CancelOrderRequest, ) -> Result<Response<CancelOrderResponse>, Error>

Cancel Order important You must specify orderId or orderLinkId to cancel the order. If orderId and orderLinkId do not match, the system will process orderId first. You can only cancel unfilled or partially filled orders.

Source

pub async fn get_open_closed_orders( &self, params: GetOpenClosedOrdersParams, ) -> Result<Response<CursorPagination<Order>>, Error>

Get Open & Closed Orders. Primarily query unfilled or partially filled orders in real-time, but also supports querying recent 500 closed status (Cancelled, Filled) orders. Please see the usage of request param openOnly. And to query older order records, please use the order history interface.

Tip UTA2.0 can query filled, canceled, and rejected orders to the most recent 500 orders for spot, linear, inverse and option categories UTA1.0 can query filled, canceled, and rejected orders to the most recent 500 orders for spot, linear, and option categories. The inverse category is not subject to this limitation. You can query by symbol, baseCoin, orderId and orderLinkId, and if you pass multiple params, the system will process them according to this priority: orderId > orderLinkId > symbol > baseCoin. The records are sorted by the createdTime from newest to oldest.

info classic account spot can return open orders only After a server release or restart, filled, canceled, and rejected orders of Unified account should only be queried through order history.

Source

pub async fn get_open_closed_orders_all( &self, params: GetOpenClosedOrdersParams, ) -> Result<Vec<Order>, Error>

Collect all pages of open/closed orders into a single Vec. Repeatedly calls [get_open_closed_orders] following next_page_cursor until the last page is reached.

Source

pub async fn cancel_all_orders( &self, request: CancelAllOrdersRequest, ) -> Result<Response<CancelAllOrdersResponse>, Error>

Cancel All Orders. Cancel all open orders. Support linear, inverse, spot, and option.

Source

pub async fn get_order_history( &self, params: GetOrderHistoryParams, ) -> Result<Response<CursorPagination<Order>>, Error>

Get Order History. Query order history. As order creation/cancellation is asynchronous, the data returned may be delayed. Supports up to 2 years of data.

Source

pub async fn get_order_history_all( &self, params: GetOrderHistoryParams, ) -> Result<Vec<Order>, Error>

Collect all pages of order history into a single Vec.

Source

pub async fn place_orders_batch( &self, request: PlaceOrderBatchRequest, ) -> Result<Response<List<PlaceOrderBatchResult>>, Error>

Place Batch Orders. Supports up to 20 orders per request. Per-item results are in response.ret_ext_info.list (parallel to response.result.list).

Source

pub async fn amend_orders_batch( &self, request: AmendOrderBatchRequest, ) -> Result<Response<List<AmendOrderBatchResult>>, Error>

Amend Batch Orders. Supports up to 20 orders per request. Per-item results are in response.ret_ext_info.list (parallel to response.result.list).

Source

pub async fn cancel_orders_batch( &self, request: CancelOrderBatchRequest, ) -> Result<Response<List<CancelOrderBatchResult>>, Error>

Cancel Batch Orders. Supports up to 20 orders per request. Per-item results are in response.ret_ext_info.list (parallel to response.result.list).

Source§

impl Client

Source

pub async fn get_position_info( &self, params: GetPositionInfoParams, ) -> Result<Response<CursorPagination<Position>>, Error>

Query real-time position data, such as position size, cumulative realized PNL, etc. Query real-time position data, such as position size, cumulative realized PNL, etc.

INFO

Source

pub async fn get_position_info_all( &self, params: GetPositionInfoParams, ) -> Result<Vec<Position>, Error>

Collect all pages of position info into a single Vec. Repeatedly calls [get_position_info] following next_page_cursor until the last page is reached.

Source

pub async fn set_leverage( &self, request: SetLeverageRequest, ) -> Result<Response<EmptyResult>, Error>

Set Leverage. Set the leverage for a position. Only for isolated margin mode.

Source

pub async fn set_trading_stop( &self, request: SetTradingStopRequest, ) -> Result<Response<EmptyResult>, Error>

Set Trading Stop. Set take profit, stop loss, or trailing stop for a position.

Source

pub async fn switch_cross_isolated_margin( &self, request: SwitchCrossIsolatedMarginRequest, ) -> Result<Response<EmptyResult>, Error>

Switch Cross/Isolated Margin. Switch the margin mode for a symbol between cross and isolated.

Source

pub async fn switch_position_mode( &self, request: SwitchPositionModeRequest, ) -> Result<Response<EmptyResult>, Error>

Switch Position Mode. Switch between one-way (merged single) and hedge (both sides) position mode.

Source

pub async fn set_auto_add_margin( &self, request: SetAutoAddMarginRequest, ) -> Result<Response<EmptyResult>, Error>

Set Auto Add Margin. Turn on/off auto-add-margin for an isolated margin position.

Source

pub async fn set_risk_limit( &self, request: SetRiskLimitRequest, ) -> Result<Response<SetRiskLimitResponse>, Error>

Set Risk Limit. Set the risk limit for a position. The response includes the new risk limit and its value.

Source

pub async fn get_closed_pnl( &self, params: GetClosedPnlParams, ) -> Result<Response<CursorPagination<ClosedPnl>>, Error>

Get Closed P&L. Query the closed profit and loss records of positions.

Source

pub async fn get_closed_pnl_all( &self, params: GetClosedPnlParams, ) -> Result<Vec<ClosedPnl>, Error>

Collect all pages of closed P&L into a single Vec.

Source

pub async fn get_execution_list( &self, params: GetExecutionListParams, ) -> Result<Response<CursorPagination<ExecutionEntry>>, Error>

Get Execution List. Query users’ execution (trading) records, sorted by execTime descending.

Source

pub async fn get_execution_list_all( &self, params: GetExecutionListParams, ) -> Result<Vec<ExecutionEntry>, Error>

Collect all pages of execution list entries into a single Vec.

Source§

impl Client

Source

pub async fn get_wallet_balance( &self, params: GetWalletBalanceParams, ) -> Result<Response<List<WalletBalance>>, Error>

Obtain wallet balance, query asset information of each currency. By default, currency information with assets or liabilities of 0 is not returned.

Source

pub async fn get_transaction_log( &self, params: GetTransactionLogParams, ) -> Result<Response<CursorPagination<TransactionLog>>, Error>

Get Transaction Log Query for transaction logs in your Unified account. It supports up to 2 years worth of data.

Source

pub async fn get_transaction_log_all( &self, params: GetTransactionLogParams, ) -> Result<Vec<TransactionLog>, Error>

Collect all pages of transaction log entries into a single Vec. Repeatedly calls [get_transaction_log] following next_page_cursor until the last page is reached.

Source

pub async fn get_account_info(&self) -> Result<Response<AccountInfo>, Error>

Query the account information, like margin mode, account mode, etc.

Source§

impl Client

Source

pub async fn get_api_key_information( &self, ) -> Result<Response<APIKeyInformation>, Error>

Get API Key Information. Get the information of the api key. Use the api key pending to be checked to call the endpoint. Both master and sub user’s api key are applicable.

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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