pub struct BitmexRawHttpClient { /* private fields */ }Expand description
Provides a lower-level HTTP client for connecting to the BitMEX REST API.
This client wraps the underlying HttpClient to handle functionality
specific to BitMEX, such as request signing (for authenticated endpoints),
forming request URLs, and deserializing responses into specific data models.
§Connection Management
The client uses HTTP keep-alive for connection pooling with a 90-second idle timeout, which matches BitMEX’s server-side keep-alive timeout. Connections are automatically reused for subsequent requests to minimize latency.
§Rate Limiting
BitMEX enforces the following rate limits:
- 120 requests per minute for authenticated users (30 for unauthenticated).
- 10 requests per second burst limit for certain endpoints (order management).
The client automatically respects these limits through the configured quota.
Implementations§
Source§impl BitmexRawHttpClient
impl BitmexRawHttpClient
Sourcepub fn new(
base_url: Option<String>,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
recv_window_ms: Option<u64>,
max_requests_per_second: Option<u32>,
max_requests_per_minute: Option<u32>,
proxy_url: Option<String>,
) -> Result<Self, BitmexHttpError>
pub fn new( base_url: Option<String>, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, recv_window_ms: Option<u64>, max_requests_per_second: Option<u32>, max_requests_per_minute: Option<u32>, proxy_url: Option<String>, ) -> Result<Self, BitmexHttpError>
Creates a new BitmexRawHttpClient using the default BitMEX HTTP URL,
optionally overridden with a custom base URL.
This version of the client has no credentials, so it can only call publicly accessible endpoints.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub fn with_credentials(
api_key: String,
api_secret: String,
base_url: String,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
recv_window_ms: Option<u64>,
max_requests_per_second: Option<u32>,
max_requests_per_minute: Option<u32>,
proxy_url: Option<String>,
) -> Result<Self, BitmexHttpError>
pub fn with_credentials( api_key: String, api_secret: String, base_url: String, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, recv_window_ms: Option<u64>, max_requests_per_second: Option<u32>, max_requests_per_minute: Option<u32>, proxy_url: Option<String>, ) -> Result<Self, BitmexHttpError>
Creates a new BitmexRawHttpClient configured with credentials
for authenticated requests, optionally using a custom base URL.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancel all pending HTTP requests.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Get the cancellation token for this client.
Sourcepub async fn get_instruments(
&self,
active_only: bool,
) -> Result<Vec<BitmexInstrument>, BitmexHttpError>
pub async fn get_instruments( &self, active_only: bool, ) -> Result<Vec<BitmexInstrument>, BitmexHttpError>
Get all instruments.
§Errors
Returns an error if the request fails, the response cannot be parsed, or the API returns an error.
Sourcepub async fn get_server_time(&self) -> Result<u64, BitmexHttpError>
pub async fn get_server_time(&self) -> Result<u64, BitmexHttpError>
Requests the current server time from BitMEX.
Retrieves the BitMEX API info including the system time in Unix timestamp (milliseconds). This is useful for synchronizing local clocks with the exchange server and logging time drift.
§Errors
Returns an error if the HTTP request fails or if the response body
cannot be parsed into BitmexApiInfo.
Sourcepub async fn get_instrument(
&self,
symbol: &str,
) -> Result<Option<BitmexInstrument>, BitmexHttpError>
pub async fn get_instrument( &self, symbol: &str, ) -> Result<Option<BitmexInstrument>, BitmexHttpError>
Get the instrument definition for the specified symbol.
BitMEX responds to /instrument?symbol=... with an array, even when
a single symbol is requested. This helper returns the first element of
that array and yields Ok(None) when the venue returns an empty list
(e.g. unknown symbol).
§Errors
Returns an error if the request fails or the payload cannot be deserialized.
Sourcepub async fn get_wallet(&self) -> Result<BitmexWallet, BitmexHttpError>
pub async fn get_wallet(&self) -> Result<BitmexWallet, BitmexHttpError>
Get user wallet information.
§Errors
Returns an error if credentials are missing, the request fails, or the API returns an error.
Sourcepub async fn get_margin(
&self,
currency: &str,
) -> Result<BitmexMargin, BitmexHttpError>
pub async fn get_margin( &self, currency: &str, ) -> Result<BitmexMargin, BitmexHttpError>
Get user margin information.
§Errors
Returns an error if credentials are missing, the request fails, or the API returns an error.
Sourcepub async fn get_trades(
&self,
params: GetTradeParams,
) -> Result<Vec<BitmexTrade>, BitmexHttpError>
pub async fn get_trades( &self, params: GetTradeParams, ) -> Result<Vec<BitmexTrade>, BitmexHttpError>
Sourcepub async fn get_trade_bucketed(
&self,
params: GetTradeBucketedParams,
) -> Result<Vec<BitmexTradeBin>, BitmexHttpError>
pub async fn get_trade_bucketed( &self, params: GetTradeBucketedParams, ) -> Result<Vec<BitmexTradeBin>, BitmexHttpError>
Get bucketed (aggregated) trade data.
§Errors
Returns an error if credentials are missing, the request fails, or the API returns an error.
Sourcepub async fn get_orders(
&self,
params: GetOrderParams,
) -> Result<Vec<BitmexOrder>, BitmexHttpError>
pub async fn get_orders( &self, params: GetOrderParams, ) -> Result<Vec<BitmexOrder>, BitmexHttpError>
Sourcepub async fn place_order(
&self,
params: PostOrderParams,
) -> Result<Value, BitmexHttpError>
pub async fn place_order( &self, params: PostOrderParams, ) -> Result<Value, BitmexHttpError>
Sourcepub async fn cancel_orders(
&self,
params: DeleteOrderParams,
) -> Result<Value, BitmexHttpError>
pub async fn cancel_orders( &self, params: DeleteOrderParams, ) -> Result<Value, BitmexHttpError>
Sourcepub async fn amend_order(
&self,
params: PutOrderParams,
) -> Result<Value, BitmexHttpError>
pub async fn amend_order( &self, params: PutOrderParams, ) -> Result<Value, BitmexHttpError>
Sourcepub async fn cancel_all_orders(
&self,
params: DeleteAllOrdersParams,
) -> Result<Value, BitmexHttpError>
pub async fn cancel_all_orders( &self, params: DeleteAllOrdersParams, ) -> Result<Value, BitmexHttpError>
Cancel all orders.
§Errors
Returns an error if credentials are missing, the request fails, or the API returns an error.
§Panics
Panics if the parameters cannot be serialized (should never happen with valid builder-generated params).
§References
https://www.bitmex.com/api/explorer/#!/Order/Order_cancelAll
Sourcepub async fn get_executions(
&self,
params: GetExecutionParams,
) -> Result<Vec<BitmexExecution>, BitmexHttpError>
pub async fn get_executions( &self, params: GetExecutionParams, ) -> Result<Vec<BitmexExecution>, BitmexHttpError>
Sourcepub async fn get_positions(
&self,
params: GetPositionParams,
) -> Result<Vec<BitmexPosition>, BitmexHttpError>
pub async fn get_positions( &self, params: GetPositionParams, ) -> Result<Vec<BitmexPosition>, BitmexHttpError>
Sourcepub async fn update_position_leverage(
&self,
params: PostPositionLeverageParams,
) -> Result<BitmexPosition, BitmexHttpError>
pub async fn update_position_leverage( &self, params: PostPositionLeverageParams, ) -> Result<BitmexPosition, BitmexHttpError>
Trait Implementations§
Source§impl Clone for BitmexRawHttpClient
impl Clone for BitmexRawHttpClient
Source§fn clone(&self) -> BitmexRawHttpClient
fn clone(&self) -> BitmexRawHttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BitmexRawHttpClient
impl Debug for BitmexRawHttpClient
Auto Trait Implementations§
impl Freeze for BitmexRawHttpClient
impl !RefUnwindSafe for BitmexRawHttpClient
impl Send for BitmexRawHttpClient
impl Sync for BitmexRawHttpClient
impl Unpin for BitmexRawHttpClient
impl !UnwindSafe for BitmexRawHttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more