pub struct BybitRawHttpClient { /* private fields */ }Expand description
Raw HTTP client for low-level Bybit API operations.
This client handles request/response operations with the Bybit API, returning venue-specific response types. It does not parse to Nautilus domain types.
Implementations§
Source§impl BybitRawHttpClient
impl BybitRawHttpClient
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancels all pending HTTP requests.
Sourcepub fn reset_cancellation_token(&self)
pub fn reset_cancellation_token(&self)
Replaces the cancelled token with a fresh one so subsequent requests are not immediately short-circuited.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Returns a clone of the current cancellation token.
Sourcepub fn new(
base_url: Option<String>,
timeout_secs: u64,
max_retries: u32,
retry_delay_ms: u64,
retry_delay_max_ms: u64,
recv_window_ms: u64,
proxy_url: Option<String>,
) -> Result<Self, BybitHttpError>
pub fn new( base_url: Option<String>, timeout_secs: u64, max_retries: u32, retry_delay_ms: u64, retry_delay_max_ms: u64, recv_window_ms: u64, proxy_url: Option<String>, ) -> Result<Self, BybitHttpError>
Creates a new BybitRawHttpClient using the default Bybit HTTP URL.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub fn with_credentials(
api_key: String,
api_secret: String,
base_url: Option<String>,
timeout_secs: u64,
max_retries: u32,
retry_delay_ms: u64,
retry_delay_max_ms: u64,
recv_window_ms: u64,
proxy_url: Option<String>,
) -> Result<Self, BybitHttpError>
pub fn with_credentials( api_key: String, api_secret: String, base_url: Option<String>, timeout_secs: u64, max_retries: u32, retry_delay_ms: u64, retry_delay_max_ms: u64, recv_window_ms: u64, proxy_url: Option<String>, ) -> Result<Self, BybitHttpError>
Creates a new BybitRawHttpClient configured with credentials.
§Errors
Returns an error if the HTTP client cannot be created.
Sourcepub fn new_with_env(
api_key: Option<String>,
api_secret: Option<String>,
base_url: Option<String>,
demo: bool,
testnet: bool,
timeout_secs: u64,
max_retries: u32,
retry_delay_ms: u64,
retry_delay_max_ms: u64,
recv_window_ms: u64,
proxy_url: Option<String>,
) -> Result<Self, BybitHttpError>
pub fn new_with_env( api_key: Option<String>, api_secret: Option<String>, base_url: Option<String>, demo: bool, testnet: bool, timeout_secs: u64, max_retries: u32, retry_delay_ms: u64, retry_delay_max_ms: u64, recv_window_ms: u64, proxy_url: Option<String>, ) -> Result<Self, BybitHttpError>
Creates a new BybitRawHttpClient with environment variable credential resolution.
If api_key or api_secret are not provided, they will be loaded from
environment variables based on the environment flags:
- Demo:
BYBIT_DEMO_API_KEY,BYBIT_DEMO_API_SECRET - Testnet:
BYBIT_TESTNET_API_KEY,BYBIT_TESTNET_API_SECRET - Mainnet:
BYBIT_API_KEY,BYBIT_API_SECRET
§Errors
Returns an error if the HTTP client cannot be created.
Sourcepub async fn get_server_time(
&self,
) -> Result<BybitServerTimeResponse, BybitHttpError>
pub async fn get_server_time( &self, ) -> Result<BybitServerTimeResponse, BybitHttpError>
Sourcepub async fn get_instruments<T: DeserializeOwned + BybitResponseCheck>(
&self,
params: &BybitInstrumentsInfoParams,
) -> Result<T, BybitHttpError>
pub async fn get_instruments<T: DeserializeOwned + BybitResponseCheck>( &self, params: &BybitInstrumentsInfoParams, ) -> Result<T, BybitHttpError>
Sourcepub async fn get_instruments_spot(
&self,
params: &BybitInstrumentsInfoParams,
) -> Result<BybitInstrumentSpotResponse, BybitHttpError>
pub async fn get_instruments_spot( &self, params: &BybitInstrumentsInfoParams, ) -> Result<BybitInstrumentSpotResponse, BybitHttpError>
Sourcepub async fn get_instruments_linear(
&self,
params: &BybitInstrumentsInfoParams,
) -> Result<BybitInstrumentLinearResponse, BybitHttpError>
pub async fn get_instruments_linear( &self, params: &BybitInstrumentsInfoParams, ) -> Result<BybitInstrumentLinearResponse, BybitHttpError>
Sourcepub async fn get_instruments_inverse(
&self,
params: &BybitInstrumentsInfoParams,
) -> Result<BybitInstrumentInverseResponse, BybitHttpError>
pub async fn get_instruments_inverse( &self, params: &BybitInstrumentsInfoParams, ) -> Result<BybitInstrumentInverseResponse, BybitHttpError>
Sourcepub async fn get_instruments_option(
&self,
params: &BybitInstrumentsInfoParams,
) -> Result<BybitInstrumentOptionResponse, BybitHttpError>
pub async fn get_instruments_option( &self, params: &BybitInstrumentsInfoParams, ) -> Result<BybitInstrumentOptionResponse, BybitHttpError>
Sourcepub async fn get_klines(
&self,
params: &BybitKlinesParams,
) -> Result<BybitKlinesResponse, BybitHttpError>
pub async fn get_klines( &self, params: &BybitKlinesParams, ) -> Result<BybitKlinesResponse, BybitHttpError>
Sourcepub async fn get_recent_trades(
&self,
params: &BybitTradesParams,
) -> Result<BybitTradesResponse, BybitHttpError>
pub async fn get_recent_trades( &self, params: &BybitTradesParams, ) -> Result<BybitTradesResponse, BybitHttpError>
Sourcepub async fn get_funding_history(
&self,
params: &BybitFundingParams,
) -> Result<BybitFundingResponse, BybitHttpError>
pub async fn get_funding_history( &self, params: &BybitFundingParams, ) -> Result<BybitFundingResponse, BybitHttpError>
Sourcepub async fn get_orderbook(
&self,
params: &BybitOrderbookParams,
) -> Result<BybitOrderbookResponse, BybitHttpError>
pub async fn get_orderbook( &self, params: &BybitOrderbookParams, ) -> Result<BybitOrderbookResponse, BybitHttpError>
Sourcepub async fn get_open_orders(
&self,
category: BybitProductType,
symbol: Option<String>,
base_coin: Option<String>,
settle_coin: Option<String>,
order_id: Option<String>,
order_link_id: Option<String>,
open_only: Option<BybitOpenOnly>,
order_filter: Option<BybitOrderFilter>,
limit: Option<u32>,
cursor: Option<String>,
) -> Result<BybitOpenOrdersResponse, BybitHttpError>
pub async fn get_open_orders( &self, category: BybitProductType, symbol: Option<String>, base_coin: Option<String>, settle_coin: Option<String>, order_id: Option<String>, order_link_id: Option<String>, open_only: Option<BybitOpenOnly>, order_filter: Option<BybitOrderFilter>, limit: Option<u32>, cursor: Option<String>, ) -> Result<BybitOpenOrdersResponse, BybitHttpError>
Sourcepub async fn place_order(
&self,
request: &Value,
) -> Result<BybitPlaceOrderResponse, BybitHttpError>
pub async fn place_order( &self, request: &Value, ) -> Result<BybitPlaceOrderResponse, BybitHttpError>
Sourcepub async fn get_wallet_balance(
&self,
params: &BybitWalletBalanceParams,
) -> Result<BybitWalletBalanceResponse, BybitHttpError>
pub async fn get_wallet_balance( &self, params: &BybitWalletBalanceParams, ) -> Result<BybitWalletBalanceResponse, BybitHttpError>
Sourcepub async fn get_account_info(
&self,
) -> Result<BybitAccountInfoResponse, BybitHttpError>
pub async fn get_account_info( &self, ) -> Result<BybitAccountInfoResponse, BybitHttpError>
Sourcepub async fn get_account_details(
&self,
) -> Result<BybitAccountDetailsResponse, BybitHttpError>
pub async fn get_account_details( &self, ) -> Result<BybitAccountDetailsResponse, BybitHttpError>
Sourcepub async fn update_sub_api_key(
&self,
params: &BybitUpdateSubApiParams,
) -> Result<BybitUpdateSubApiResponse, BybitHttpError>
pub async fn update_sub_api_key( &self, params: &BybitUpdateSubApiParams, ) -> Result<BybitUpdateSubApiResponse, BybitHttpError>
Sourcepub async fn update_master_api_key(
&self,
params: &BybitUpdateMasterApiParams,
) -> Result<BybitUpdateMasterApiResponse, BybitHttpError>
pub async fn update_master_api_key( &self, params: &BybitUpdateMasterApiParams, ) -> Result<BybitUpdateMasterApiResponse, BybitHttpError>
Sourcepub async fn get_sub_members(
&self,
) -> Result<BybitSubMembersResponse, BybitHttpError>
pub async fn get_sub_members( &self, ) -> Result<BybitSubMembersResponse, BybitHttpError>
Sourcepub async fn get_sub_members_paged(
&self,
params: &BybitSubMembersPageParams,
) -> Result<BybitSubMembersPagedResponse, BybitHttpError>
pub async fn get_sub_members_paged( &self, params: &BybitSubMembersPageParams, ) -> Result<BybitSubMembersPagedResponse, BybitHttpError>
Sourcepub async fn get_escrow_sub_members(
&self,
params: &BybitSubMembersPageParams,
) -> Result<BybitEscrowSubMembersResponse, BybitHttpError>
pub async fn get_escrow_sub_members( &self, params: &BybitSubMembersPageParams, ) -> Result<BybitEscrowSubMembersResponse, BybitHttpError>
Sourcepub async fn get_sub_api_keys(
&self,
params: &BybitSubApiKeysParams,
) -> Result<BybitSubApiKeysResponse, BybitHttpError>
pub async fn get_sub_api_keys( &self, params: &BybitSubApiKeysParams, ) -> Result<BybitSubApiKeysResponse, BybitHttpError>
Sourcepub async fn fetch_all_sub_members_paged(
&self,
page_size: Option<u32>,
) -> Result<Vec<BybitSubMember>, BybitHttpError>
pub async fn fetch_all_sub_members_paged( &self, page_size: Option<u32>, ) -> Result<Vec<BybitSubMember>, BybitHttpError>
Fetches every sub-account page via /v5/user/submembers and returns the
flattened list. Walks the cursor until Bybit signals end-of-pages.
§Errors
Returns an error if any page request fails or the response cannot be parsed.
Sourcepub async fn fetch_all_escrow_sub_members(
&self,
page_size: Option<u32>,
) -> Result<Vec<BybitSubMember>, BybitHttpError>
pub async fn fetch_all_escrow_sub_members( &self, page_size: Option<u32>, ) -> Result<Vec<BybitSubMember>, BybitHttpError>
Fetches every fund-custodial page via /v5/user/escrow_sub_members and
returns the flattened list. Walks the cursor until Bybit signals
end-of-pages.
§Errors
Returns an error if any page request fails or the response cannot be parsed.
Sourcepub async fn fetch_all_sub_api_keys(
&self,
sub_member_id: impl Into<String>,
limit: Option<u32>,
) -> Result<Vec<BybitSubApiKeyInfo>, BybitHttpError>
pub async fn fetch_all_sub_api_keys( &self, sub_member_id: impl Into<String>, limit: Option<u32>, ) -> Result<Vec<BybitSubApiKeyInfo>, BybitHttpError>
Fetches every page of sub-account API keys for sub_member_id and
returns the flattened list. Walks the cursor until Bybit signals
end-of-pages.
§Errors
Returns an error if any page request fails or the response cannot be parsed.
Sourcepub async fn get_fee_rate(
&self,
params: &BybitFeeRateParams,
) -> Result<BybitFeeRateResponse, BybitHttpError>
pub async fn get_fee_rate( &self, params: &BybitFeeRateParams, ) -> Result<BybitFeeRateResponse, BybitHttpError>
Sourcepub async fn set_margin_mode(
&self,
margin_mode: BybitMarginMode,
) -> Result<BybitSetMarginModeResponse, BybitHttpError>
pub async fn set_margin_mode( &self, margin_mode: BybitMarginMode, ) -> Result<BybitSetMarginModeResponse, BybitHttpError>
Sourcepub async fn set_leverage(
&self,
product_type: BybitProductType,
symbol: &str,
buy_leverage: &str,
sell_leverage: &str,
) -> Result<BybitSetLeverageResponse, BybitHttpError>
pub async fn set_leverage( &self, product_type: BybitProductType, symbol: &str, buy_leverage: &str, sell_leverage: &str, ) -> Result<BybitSetLeverageResponse, BybitHttpError>
Sourcepub async fn switch_mode(
&self,
product_type: BybitProductType,
mode: BybitPositionMode,
symbol: Option<String>,
coin: Option<String>,
) -> Result<BybitSwitchModeResponse, BybitHttpError>
pub async fn switch_mode( &self, product_type: BybitProductType, mode: BybitPositionMode, symbol: Option<String>, coin: Option<String>, ) -> Result<BybitSwitchModeResponse, BybitHttpError>
Sourcepub async fn set_trading_stop(
&self,
params: &BybitSetTradingStopParams,
) -> Result<BybitSetTradingStopResponse, BybitHttpError>
pub async fn set_trading_stop( &self, params: &BybitSetTradingStopParams, ) -> Result<BybitSetTradingStopResponse, BybitHttpError>
Sourcepub async fn borrow(
&self,
coin: &str,
amount: &str,
) -> Result<BybitBorrowResponse, BybitHttpError>
pub async fn borrow( &self, coin: &str, amount: &str, ) -> Result<BybitBorrowResponse, BybitHttpError>
Sourcepub async fn no_convert_repay(
&self,
coin: &str,
amount: Option<&str>,
) -> Result<BybitNoConvertRepayResponse, BybitHttpError>
pub async fn no_convert_repay( &self, coin: &str, amount: Option<&str>, ) -> Result<BybitNoConvertRepayResponse, BybitHttpError>
Manually repays borrowed coins without asset conversion.
§Errors
Returns an error if:
- Credentials are missing.
- The request fails.
- Called during the hourly interest-calculation window (mm:04:00-mm:05:30 UTC each hour).
- Insufficient spot balance for repayment.
§Panics
Panics if the parameter builder fails (should never happen with valid inputs).
§References
Sourcepub async fn repay(
&self,
coin: Option<&str>,
amount: Option<&str>,
) -> Result<BybitRepayResponse, BybitHttpError>
pub async fn repay( &self, coin: Option<&str>, amount: Option<&str>, ) -> Result<BybitRepayResponse, BybitHttpError>
Manually repays borrowed coins, converting other assets if required.
§Errors
Returns an error if:
- Credentials are missing.
- The request fails.
- Called during the hourly interest-calculation window (mm:04:00-mm:05:30 UTC each hour).
- Insufficient balance for repayment.
§Panics
Panics if the parameter builder fails (should never happen with valid inputs).
§References
Sourcepub async fn withdraw(
&self,
params: &BybitWithdrawParams,
) -> Result<BybitWithdrawResponse, BybitHttpError>
pub async fn withdraw( &self, params: &BybitWithdrawParams, ) -> Result<BybitWithdrawResponse, BybitHttpError>
Withdraws coins from the account.
The request is sent once. Bybit’s requestId is a client identifier, not
a proven duplicate-detection window, so it is not a retry key.
§Errors
Returns an error if:
- Credentials are missing.
- The request fails.
- The API key lacks withdrawal permission or is not a master UID key.
- The address is not in the account’s withdrawal address book.
§References
Sourcepub async fn get_withdrawal_records(
&self,
params: &BybitWithdrawalRecordsParams,
) -> Result<BybitWithdrawalRecordsResponse, BybitHttpError>
pub async fn get_withdrawal_records( &self, params: &BybitWithdrawalRecordsParams, ) -> Result<BybitWithdrawalRecordsResponse, BybitHttpError>
Sourcepub async fn fetch_all_withdrawal_records(
&self,
params: &BybitWithdrawalRecordsParams,
) -> Result<Vec<BybitWithdrawalRecord>, BybitHttpError>
pub async fn fetch_all_withdrawal_records( &self, params: &BybitWithdrawalRecordsParams, ) -> Result<Vec<BybitWithdrawalRecord>, BybitHttpError>
Fetches every page of withdrawal records matching params and returns
the flattened list. Walks the cursor until Bybit signals end-of-pages.
§Errors
Returns an error if any page request fails or the response cannot be parsed.
Sourcepub async fn get_tickers<T: DeserializeOwned + BybitResponseCheck>(
&self,
params: &BybitTickersParams,
) -> Result<T, BybitHttpError>
pub async fn get_tickers<T: DeserializeOwned + BybitResponseCheck>( &self, params: &BybitTickersParams, ) -> Result<T, BybitHttpError>
Sourcepub async fn get_trade_history(
&self,
params: &BybitTradeHistoryParams,
) -> Result<BybitTradeHistoryResponse, BybitHttpError>
pub async fn get_trade_history( &self, params: &BybitTradeHistoryParams, ) -> Result<BybitTradeHistoryResponse, BybitHttpError>
Sourcepub async fn get_positions(
&self,
params: &BybitPositionListParams,
) -> Result<BybitPositionListResponse, BybitHttpError>
pub async fn get_positions( &self, params: &BybitPositionListParams, ) -> Result<BybitPositionListResponse, BybitHttpError>
Sourcepub fn recv_window_ms(&self) -> u64
pub fn recv_window_ms(&self) -> u64
Returns the configured receive window in milliseconds.
Sourcepub fn credential(&self) -> Option<&Credential>
pub fn credential(&self) -> Option<&Credential>
Returns the API credential if configured.