pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub async fn get_server_time(&self) -> Result<Response<ServerTime>, Error>
pub async fn get_kline( &self, params: GetKLinesParams, ) -> Result<Response<KLine>, Error>
Sourcepub async fn get_tickers(
&self,
params: GetTickersParams,
) -> Result<Response<Ticker>, Error>
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.
pub async fn get_instruments_info( &self, params: GetInstrumentsInfoParams, ) -> Result<Response<InstrumentsInfo>, Error>
pub async fn get_public_recent_trading_history( &self, params: GetTradesParams, ) -> Result<Response<Trade>, Error>
Source§impl Client
impl Client
Sourcepub async fn place_order(
&self,
request: PlaceOrderRequest,
) -> Result<Response<PlaceOrderResponse>, Error>
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
Sourcepub async fn amend_order(
&self,
request: AmendOrderRequest,
) -> Result<Response<AmendOrderResponse>, Error>
pub async fn amend_order( &self, request: AmendOrderRequest, ) -> Result<Response<AmendOrderResponse>, Error>
Amend Order info You can only modify unfilled or partially filled orders.
Sourcepub async fn cancel_order(
&self,
request: CancelOrderRequest,
) -> Result<Response<CancelOrderResponse>, Error>
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.
Sourcepub async fn get_open_closed_orders(
&self,
params: GetOpenClosedOrdersParams,
) -> Result<Response<CursorPagination<Order>>, Error>
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.
Sourcepub async fn get_open_closed_orders_all(
&self,
params: GetOpenClosedOrdersParams,
) -> Result<Vec<Order>, Error>
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.
Sourcepub async fn cancel_all_orders(
&self,
request: CancelAllOrdersRequest,
) -> Result<Response<CancelAllOrdersResponse>, Error>
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.
Sourcepub async fn get_order_history(
&self,
params: GetOrderHistoryParams,
) -> Result<Response<CursorPagination<Order>>, Error>
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.
Sourcepub async fn get_order_history_all(
&self,
params: GetOrderHistoryParams,
) -> Result<Vec<Order>, Error>
pub async fn get_order_history_all( &self, params: GetOrderHistoryParams, ) -> Result<Vec<Order>, Error>
Collect all pages of order history into a single Vec.
Sourcepub async fn place_orders_batch(
&self,
request: PlaceOrderBatchRequest,
) -> Result<Response<List<PlaceOrderBatchResult>>, Error>
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).
Sourcepub async fn amend_orders_batch(
&self,
request: AmendOrderBatchRequest,
) -> Result<Response<List<AmendOrderBatchResult>>, Error>
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).
Sourcepub async fn cancel_orders_batch(
&self,
request: CancelOrderBatchRequest,
) -> Result<Response<List<CancelOrderBatchResult>>, Error>
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
impl Client
Sourcepub async fn get_position_info(
&self,
params: GetPositionInfoParams,
) -> Result<Response<CursorPagination<Position>>, Error>
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
Sourcepub async fn get_position_info_all(
&self,
params: GetPositionInfoParams,
) -> Result<Vec<Position>, Error>
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.
Sourcepub async fn set_leverage(
&self,
request: SetLeverageRequest,
) -> Result<Response<EmptyResult>, Error>
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.
Sourcepub async fn set_trading_stop(
&self,
request: SetTradingStopRequest,
) -> Result<Response<EmptyResult>, Error>
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.
Sourcepub async fn switch_cross_isolated_margin(
&self,
request: SwitchCrossIsolatedMarginRequest,
) -> Result<Response<EmptyResult>, Error>
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.
Sourcepub async fn switch_position_mode(
&self,
request: SwitchPositionModeRequest,
) -> Result<Response<EmptyResult>, Error>
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.
Sourcepub async fn set_auto_add_margin(
&self,
request: SetAutoAddMarginRequest,
) -> Result<Response<EmptyResult>, Error>
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.
Sourcepub async fn set_risk_limit(
&self,
request: SetRiskLimitRequest,
) -> Result<Response<SetRiskLimitResponse>, Error>
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.
Sourcepub async fn get_closed_pnl(
&self,
params: GetClosedPnlParams,
) -> Result<Response<CursorPagination<ClosedPnl>>, Error>
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.
Sourcepub async fn get_closed_pnl_all(
&self,
params: GetClosedPnlParams,
) -> Result<Vec<ClosedPnl>, Error>
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.
Sourcepub async fn get_execution_list(
&self,
params: GetExecutionListParams,
) -> Result<Response<CursorPagination<ExecutionEntry>>, Error>
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.
Sourcepub async fn get_execution_list_all(
&self,
params: GetExecutionListParams,
) -> Result<Vec<ExecutionEntry>, Error>
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
impl Client
Sourcepub async fn get_wallet_balance(
&self,
params: GetWalletBalanceParams,
) -> Result<Response<List<WalletBalance>>, Error>
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.
Sourcepub async fn get_transaction_log(
&self,
params: GetTransactionLogParams,
) -> Result<Response<CursorPagination<TransactionLog>>, Error>
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.
Sourcepub async fn get_transaction_log_all(
&self,
params: GetTransactionLogParams,
) -> Result<Vec<TransactionLog>, Error>
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.
Sourcepub async fn get_account_info(&self) -> Result<Response<AccountInfo>, Error>
pub async fn get_account_info(&self) -> Result<Response<AccountInfo>, Error>
Query the account information, like margin mode, account mode, etc.
Source§impl Client
impl Client
Sourcepub async fn get_api_key_information(
&self,
) -> Result<Response<APIKeyInformation>, Error>
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.