pub struct BybitClient { /* private fields */ }Expand description
Bybit HTTP API client.
Implementations§
Source§impl BybitClient
impl BybitClient
Sourcepub fn new(config: ClientConfig) -> Result<Self>
pub fn new(config: ClientConfig) -> Result<Self>
Create a new client with the given configuration.
Sourcepub fn with_credentials(
api_key: impl Into<String>,
api_secret: impl Into<String>,
) -> Result<Self>
pub fn with_credentials( api_key: impl Into<String>, api_secret: impl Into<String>, ) -> Result<Self>
Create a new client with API credentials using default settings.
Sourcepub fn testnet(
api_key: impl Into<String>,
api_secret: impl Into<String>,
) -> Result<Self>
pub fn testnet( api_key: impl Into<String>, api_secret: impl Into<String>, ) -> Result<Self>
Create a new client for testnet.
Sourcepub fn demo(
api_key: impl Into<String>,
api_secret: impl Into<String>,
) -> Result<Self>
pub fn demo( api_key: impl Into<String>, api_secret: impl Into<String>, ) -> Result<Self>
Create a new client for demo environment.
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get the client configuration.
Sourcepub async fn get_public<T: DeserializeOwned>(
&self,
endpoint: &str,
params: &[(&str, &str)],
) -> Result<T>
pub async fn get_public<T: DeserializeOwned>( &self, endpoint: &str, params: &[(&str, &str)], ) -> Result<T>
Send a public GET request (no authentication).
Source§impl BybitClient
impl BybitClient
Sourcepub async fn get_wallet_balance(
&self,
account_type: AccountType,
) -> Result<WalletBalance>
pub async fn get_wallet_balance( &self, account_type: AccountType, ) -> Result<WalletBalance>
Sourcepub async fn get_account_info(&self) -> Result<AccountInfo>
pub async fn get_account_info(&self) -> Result<AccountInfo>
Get account info.
Sourcepub async fn get_fee_rate(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<FeeRates>
pub async fn get_fee_rate( &self, category: Category, symbol: Option<&str>, ) -> Result<FeeRates>
Sourcepub async fn get_transaction_log(
&self,
category: Option<Category>,
limit: Option<u32>,
) -> Result<TransactionLogs>
pub async fn get_transaction_log( &self, category: Option<Category>, limit: Option<u32>, ) -> Result<TransactionLogs>
Get transaction log.
§Arguments
category- Optional category filterlimit- Optional limit (default 20)
Sourcepub async fn set_margin_mode(&self, margin_mode: MarginMode) -> Result<Value>
pub async fn set_margin_mode(&self, margin_mode: MarginMode) -> Result<Value>
Sourcepub async fn get_collateral_info(
&self,
currency: Option<&str>,
) -> Result<CollateralInfo>
pub async fn get_collateral_info( &self, currency: Option<&str>, ) -> Result<CollateralInfo>
Sourcepub async fn get_borrow_history(
&self,
currency: Option<&str>,
limit: Option<u32>,
) -> Result<BorrowHistory>
pub async fn get_borrow_history( &self, currency: Option<&str>, limit: Option<u32>, ) -> Result<BorrowHistory>
Get borrow history.
§Arguments
currency- Optional currency filterlimit- Optional limit (default 20)
Source§impl BybitClient
impl BybitClient
Sourcepub async fn get_coin_info(
&self,
coin: Option<&str>,
) -> Result<CoinInfoResponse>
pub async fn get_coin_info( &self, coin: Option<&str>, ) -> Result<CoinInfoResponse>
Sourcepub async fn internal_transfer(
&self,
coin: &str,
amount: &str,
from_account: &str,
to_account: &str,
) -> Result<TransferResponse>
pub async fn internal_transfer( &self, coin: &str, amount: &str, from_account: &str, to_account: &str, ) -> Result<TransferResponse>
Internal transfer between accounts.
§Arguments
coin- Coin to transferamount- Amount to transferfrom_account- Source account typeto_account- Destination account type
Sourcepub async fn get_internal_transfer_list(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<TransferList>
pub async fn get_internal_transfer_list( &self, coin: Option<&str>, limit: Option<u32>, ) -> Result<TransferList>
Get internal transfer list.
§Arguments
coin- Optional coin filterlimit- Optional limit (default 20)
Sourcepub async fn get_deposit_address(
&self,
coin: &str,
chain_type: Option<&str>,
) -> Result<DepositAddressResponse>
pub async fn get_deposit_address( &self, coin: &str, chain_type: Option<&str>, ) -> Result<DepositAddressResponse>
Sourcepub async fn get_deposit_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<DepositRecords>
pub async fn get_deposit_records( &self, coin: Option<&str>, limit: Option<u32>, ) -> Result<DepositRecords>
Sourcepub async fn withdraw(&self, params: WithdrawParams) -> Result<WithdrawResponse>
pub async fn withdraw(&self, params: WithdrawParams) -> Result<WithdrawResponse>
Sourcepub async fn cancel_withdraw(&self, withdraw_id: &str) -> Result<Value>
pub async fn cancel_withdraw(&self, withdraw_id: &str) -> Result<Value>
Sourcepub async fn get_withdraw_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<WithdrawRecords>
pub async fn get_withdraw_records( &self, coin: Option<&str>, limit: Option<u32>, ) -> Result<WithdrawRecords>
Sourcepub async fn get_withdrawable_amount(
&self,
coin: &str,
) -> Result<WithdrawableAmount>
pub async fn get_withdrawable_amount( &self, coin: &str, ) -> Result<WithdrawableAmount>
Source§impl BybitClient
impl BybitClient
Sourcepub async fn get_server_time(&self) -> Result<ServerTime>
pub async fn get_server_time(&self) -> Result<ServerTime>
Get server time.
§Example
let client = BybitClient::testnet("key", "secret")?;
let time = client.get_server_time().await?;
println!("Server time: {}", time.time_second);Sourcepub async fn get_instruments_info(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<InstrumentsInfo>
pub async fn get_instruments_info( &self, category: Category, symbol: Option<&str>, ) -> Result<InstrumentsInfo>
Sourcepub async fn get_orderbook(
&self,
category: Category,
symbol: &str,
limit: Option<u32>,
) -> Result<Orderbook>
pub async fn get_orderbook( &self, category: Category, symbol: &str, limit: Option<u32>, ) -> Result<Orderbook>
Get orderbook.
§Arguments
category- Product categorysymbol- Symbol namelimit- Optional depth limit (1-500, default 25)
Sourcepub async fn get_tickers(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<Tickers>
pub async fn get_tickers( &self, category: Category, symbol: Option<&str>, ) -> Result<Tickers>
Get tickers.
§Arguments
category- Product categorysymbol- Optional symbol filter (returns all if None)
Sourcepub async fn get_klines(
&self,
category: Category,
symbol: &str,
interval: Interval,
limit: Option<u32>,
) -> Result<Klines>
pub async fn get_klines( &self, category: Category, symbol: &str, interval: Interval, limit: Option<u32>, ) -> Result<Klines>
Get klines (candlestick data).
§Arguments
category- Product categorysymbol- Symbol nameinterval- Kline intervallimit- Optional limit (1-1000, default 200)
Sourcepub async fn get_funding_history(
&self,
category: Category,
symbol: &str,
limit: Option<u32>,
) -> Result<FundingHistory>
pub async fn get_funding_history( &self, category: Category, symbol: &str, limit: Option<u32>, ) -> Result<FundingHistory>
Get funding rate history.
§Arguments
category- Product category (linear or inverse)symbol- Symbol namelimit- Optional limit (default 200)
Sourcepub async fn get_recent_trades(
&self,
category: Category,
symbol: &str,
limit: Option<u32>,
) -> Result<RecentTrades>
pub async fn get_recent_trades( &self, category: Category, symbol: &str, limit: Option<u32>, ) -> Result<RecentTrades>
Get recent trades.
§Arguments
category- Product categorysymbol- Symbol namelimit- Optional limit (1-1000, default 500)
Sourcepub async fn get_open_interest(
&self,
category: Category,
symbol: &str,
interval_time: &str,
limit: Option<u32>,
) -> Result<OpenInterest>
pub async fn get_open_interest( &self, category: Category, symbol: &str, interval_time: &str, limit: Option<u32>, ) -> Result<OpenInterest>
Get open interest.
§Arguments
category- Product category (linear or inverse)symbol- Symbol nameinterval_time- Interval (5min, 15min, 30min, 1h, 4h, 1d)limit- Optional limit (default 50)
Sourcepub async fn get_risk_limit(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<RiskLimits>
pub async fn get_risk_limit( &self, category: Category, symbol: Option<&str>, ) -> Result<RiskLimits>
Get risk limit info.
§Arguments
category- Product category (linear or inverse)symbol- Optional symbol filter
Sourcepub async fn get_mark_price_kline(
&self,
category: Category,
symbol: &str,
interval: Interval,
limit: Option<u32>,
) -> Result<Klines>
pub async fn get_mark_price_kline( &self, category: Category, symbol: &str, interval: Interval, limit: Option<u32>, ) -> Result<Klines>
Get mark price kline.
Sourcepub async fn get_index_price_kline(
&self,
category: Category,
symbol: &str,
interval: Interval,
limit: Option<u32>,
) -> Result<Klines>
pub async fn get_index_price_kline( &self, category: Category, symbol: &str, interval: Interval, limit: Option<u32>, ) -> Result<Klines>
Get index price kline.
Get premium index price kline.
Source§impl BybitClient
impl BybitClient
Sourcepub async fn get_positions(
&self,
category: Category,
symbol: Option<&str>,
settle_coin: Option<&str>,
) -> Result<PositionList>
pub async fn get_positions( &self, category: Category, symbol: Option<&str>, settle_coin: Option<&str>, ) -> Result<PositionList>
Get position list.
§Arguments
category- Product categorysymbol- Optional symbol filtersettle_coin- Optional settle coin filter (e.g., “USDT”)
Sourcepub async fn set_leverage(
&self,
category: Category,
symbol: &str,
buy_leverage: &str,
sell_leverage: &str,
) -> Result<Value>
pub async fn set_leverage( &self, category: Category, symbol: &str, buy_leverage: &str, sell_leverage: &str, ) -> Result<Value>
Set leverage.
§Arguments
category- Product categorysymbol- Symbol namebuy_leverage- Buy leveragesell_leverage- Sell leverage
Sourcepub async fn set_trading_stop(&self, params: TradingStopParams) -> Result<Value>
pub async fn set_trading_stop(&self, params: TradingStopParams) -> Result<Value>
Sourcepub async fn switch_position_mode(
&self,
category: Category,
mode: PositionMode,
) -> Result<Value>
pub async fn switch_position_mode( &self, category: Category, mode: PositionMode, ) -> Result<Value>
Switch position mode.
§Arguments
category- Product categorymode- Position mode (0=merged, 3=both sides)
Sourcepub async fn set_risk_limit(
&self,
category: Category,
symbol: &str,
risk_id: i32,
) -> Result<Value>
pub async fn set_risk_limit( &self, category: Category, symbol: &str, risk_id: i32, ) -> Result<Value>
Sourcepub async fn add_margin(
&self,
category: Category,
symbol: &str,
margin: &str,
) -> Result<Value>
pub async fn add_margin( &self, category: Category, symbol: &str, margin: &str, ) -> Result<Value>
Add or reduce margin.
§Arguments
category- Product categorysymbol- Symbol namemargin- Margin amount (positive to add, negative to reduce)
Sourcepub async fn get_closed_pnl(
&self,
category: Category,
symbol: Option<&str>,
limit: Option<u32>,
) -> Result<ClosedPnlList>
pub async fn get_closed_pnl( &self, category: Category, symbol: Option<&str>, limit: Option<u32>, ) -> Result<ClosedPnlList>
Get closed PnL history.
§Arguments
category- Product categorysymbol- Optional symbol filterlimit- Optional limit (default 20)
Sourcepub async fn get_executions(
&self,
category: Category,
symbol: Option<&str>,
limit: Option<u32>,
) -> Result<ExecutionList>
pub async fn get_executions( &self, category: Category, symbol: Option<&str>, limit: Option<u32>, ) -> Result<ExecutionList>
Get execution list (trade history).
§Arguments
category- Product categorysymbol- Optional symbol filterlimit- Optional limit (default 50)
Source§impl BybitClient
impl BybitClient
Sourcepub async fn place_order(
&self,
params: PlaceOrderParams,
) -> Result<OrderResponse>
pub async fn place_order( &self, params: PlaceOrderParams, ) -> Result<OrderResponse>
Sourcepub async fn amend_order(
&self,
params: AmendOrderParams,
) -> Result<OrderResponse>
pub async fn amend_order( &self, params: AmendOrderParams, ) -> Result<OrderResponse>
Amend an existing order.
Sourcepub async fn cancel_order(
&self,
params: CancelOrderParams,
) -> Result<OrderResponse>
pub async fn cancel_order( &self, params: CancelOrderParams, ) -> Result<OrderResponse>
Cancel an order.
Sourcepub async fn cancel_all_orders(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<CancelAllResponse>
pub async fn cancel_all_orders( &self, category: Category, symbol: Option<&str>, ) -> Result<CancelAllResponse>
Cancel all orders.
§Arguments
category- Product categorysymbol- Optional symbol filter (cancel all if None)
Sourcepub async fn place_batch_order(
&self,
category: Category,
orders: Vec<PlaceOrderParams>,
) -> Result<BatchOrderResponse>
pub async fn place_batch_order( &self, category: Category, orders: Vec<PlaceOrderParams>, ) -> Result<BatchOrderResponse>
Place batch orders (up to 10 orders).
§Arguments
category- Product categoryorders- List of orders to place
Sourcepub async fn amend_batch_order(
&self,
category: Category,
orders: Vec<AmendOrderParams>,
) -> Result<BatchOrderResponse>
pub async fn amend_batch_order( &self, category: Category, orders: Vec<AmendOrderParams>, ) -> Result<BatchOrderResponse>
Amend batch orders.
Sourcepub async fn cancel_batch_order(
&self,
category: Category,
orders: Vec<CancelOrderParams>,
) -> Result<BatchOrderResponse>
pub async fn cancel_batch_order( &self, category: Category, orders: Vec<CancelOrderParams>, ) -> Result<BatchOrderResponse>
Cancel batch orders.
Sourcepub async fn get_open_orders(
&self,
category: Category,
symbol: Option<&str>,
) -> Result<OrdersList>
pub async fn get_open_orders( &self, category: Category, symbol: Option<&str>, ) -> Result<OrdersList>
Sourcepub async fn get_order_history(
&self,
category: Category,
symbol: Option<&str>,
limit: Option<u32>,
) -> Result<OrdersList>
pub async fn get_order_history( &self, category: Category, symbol: Option<&str>, limit: Option<u32>, ) -> Result<OrdersList>
Get order history.
§Arguments
category- Product categorysymbol- Optional symbol filterlimit- Optional limit (default 20)
Trait Implementations§
Source§impl Clone for BybitClient
impl Clone for BybitClient
Source§fn clone(&self) -> BybitClient
fn clone(&self) -> BybitClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more