pub struct BinanceRawSpotHttpClient { /* private fields */ }Expand description
Low-level HTTP client for Binance Spot REST API with SBE encoding.
Handles:
- Base URL resolution by environment.
- Optional HMAC SHA256 signing for private endpoints.
- Rate limiting using Spot API quotas.
- SBE decoding to Binance-specific response types.
Methods are named to match Binance API endpoints and return venue-specific types (decoded from SBE).
Implementations§
Source§impl BinanceRawSpotHttpClient
impl BinanceRawSpotHttpClient
Sourcepub fn new(
environment: BinanceEnvironment,
api_key: Option<String>,
api_secret: Option<String>,
base_url_override: Option<String>,
recv_window: Option<u64>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
) -> BinanceSpotHttpResult<Self>
pub fn new( environment: BinanceEnvironment, api_key: Option<String>, api_secret: Option<String>, base_url_override: Option<String>, recv_window: Option<u64>, timeout_secs: Option<u64>, proxy_url: Option<String>, ) -> BinanceSpotHttpResult<Self>
Creates a new Binance Spot raw HTTP client.
§Errors
Returns an error if the underlying [HttpClient] fails to build.
Sourcepub const fn schema_version() -> u16
pub const fn schema_version() -> u16
Returns the SBE schema version.
Sourcepub async fn get<P>(
&self,
path: &str,
params: Option<&P>,
) -> BinanceSpotHttpResult<Vec<u8>>
pub async fn get<P>( &self, path: &str, params: Option<&P>, ) -> BinanceSpotHttpResult<Vec<u8>>
Performs a GET request and returns raw response bytes.
§Errors
Returns an error if the request fails.
Sourcepub async fn get_signed<P>(
&self,
path: &str,
params: Option<&P>,
) -> BinanceSpotHttpResult<Vec<u8>>
pub async fn get_signed<P>( &self, path: &str, params: Option<&P>, ) -> BinanceSpotHttpResult<Vec<u8>>
Performs a signed GET request and returns raw response bytes.
§Errors
Returns an error if credentials are missing or the request fails.
Sourcepub async fn ping(&self) -> BinanceSpotHttpResult<()>
pub async fn ping(&self) -> BinanceSpotHttpResult<()>
Sourcepub async fn server_time(&self) -> BinanceSpotHttpResult<i64>
pub async fn server_time(&self) -> BinanceSpotHttpResult<i64>
Returns the server time in microseconds since epoch.
Note: SBE provides microsecond precision vs JSON’s milliseconds.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn exchange_info(
&self,
) -> BinanceSpotHttpResult<BinanceExchangeInfoSbe>
pub async fn exchange_info( &self, ) -> BinanceSpotHttpResult<BinanceExchangeInfoSbe>
Returns exchange information including trading symbols.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn depth(
&self,
params: &DepthParams,
) -> BinanceSpotHttpResult<BinanceDepth>
pub async fn depth( &self, params: &DepthParams, ) -> BinanceSpotHttpResult<BinanceDepth>
Returns order book depth for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn trades(
&self,
symbol: &str,
limit: Option<u32>,
) -> BinanceSpotHttpResult<BinanceTrades>
pub async fn trades( &self, symbol: &str, limit: Option<u32>, ) -> BinanceSpotHttpResult<BinanceTrades>
Returns recent trades for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn klines(
&self,
symbol: &str,
interval: &str,
start_time: Option<i64>,
end_time: Option<i64>,
limit: Option<u32>,
) -> BinanceSpotHttpResult<BinanceKlines>
pub async fn klines( &self, symbol: &str, interval: &str, start_time: Option<i64>, end_time: Option<i64>, limit: Option<u32>, ) -> BinanceSpotHttpResult<BinanceKlines>
Returns kline (candlestick) data for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn ticker_24hr(
&self,
symbol: Option<&str>,
) -> BinanceSpotHttpResult<Vec<Ticker24hr>>
pub async fn ticker_24hr( &self, symbol: Option<&str>, ) -> BinanceSpotHttpResult<Vec<Ticker24hr>>
Returns 24-hour ticker price change statistics.
If symbol is None, returns statistics for all symbols.
§Errors
Returns an error if the request fails.
Sourcepub async fn ticker_price(
&self,
symbol: Option<&str>,
) -> BinanceSpotHttpResult<Vec<TickerPrice>>
pub async fn ticker_price( &self, symbol: Option<&str>, ) -> BinanceSpotHttpResult<Vec<TickerPrice>>
Returns latest price for a symbol or all symbols.
If symbol is None, returns prices for all symbols.
§Errors
Returns an error if the request fails.
Sourcepub async fn ticker_book(
&self,
symbol: Option<&str>,
) -> BinanceSpotHttpResult<Vec<BookTicker>>
pub async fn ticker_book( &self, symbol: Option<&str>, ) -> BinanceSpotHttpResult<Vec<BookTicker>>
Returns best bid/ask price for a symbol or all symbols.
If symbol is None, returns book ticker for all symbols.
§Errors
Returns an error if the request fails.
Sourcepub async fn avg_price(&self, symbol: &str) -> BinanceSpotHttpResult<AvgPrice>
pub async fn avg_price(&self, symbol: &str) -> BinanceSpotHttpResult<AvgPrice>
Sourcepub async fn get_trade_fee(
&self,
symbol: Option<&str>,
) -> BinanceSpotHttpResult<Vec<TradeFee>>
pub async fn get_trade_fee( &self, symbol: Option<&str>, ) -> BinanceSpotHttpResult<Vec<TradeFee>>
Returns trading fee rates for symbols.
If symbol is None, returns fee rates for all symbols.
Uses SAPI endpoint (requires authentication).
§Errors
Returns an error if credentials are missing or the request fails.
Sourcepub async fn batch_submit_orders(
&self,
orders: &[BatchOrderItem],
) -> BinanceSpotHttpResult<Vec<BatchOrderResult>>
pub async fn batch_submit_orders( &self, orders: &[BatchOrderItem], ) -> BinanceSpotHttpResult<Vec<BatchOrderResult>>
Submits multiple orders in a single request (up to 5 orders).
Each order in the batch is processed independently. The response contains the result for each order, which can be either a success or an error.
§Errors
Returns an error if credentials are missing, the request fails, or
JSON parsing fails. Individual order failures are returned in the
response array as BatchOrderResult::Error.
Sourcepub async fn batch_cancel_orders(
&self,
cancels: &[BatchCancelItem],
) -> BinanceSpotHttpResult<Vec<BatchCancelResult>>
pub async fn batch_cancel_orders( &self, cancels: &[BatchCancelItem], ) -> BinanceSpotHttpResult<Vec<BatchCancelResult>>
Cancels multiple orders in a single request (up to 5 orders).
Each cancel in the batch is processed independently. The response contains the result for each cancel, which can be either a success or an error.
§Errors
Returns an error if credentials are missing, the request fails, or
JSON parsing fails. Individual cancel failures are returned in the
response array as BatchCancelResult::Error.
Sourcepub async fn account(
&self,
params: &AccountInfoParams,
) -> BinanceSpotHttpResult<BinanceAccountInfo>
pub async fn account( &self, params: &AccountInfoParams, ) -> BinanceSpotHttpResult<BinanceAccountInfo>
Returns account information including balances.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn account_trades(
&self,
symbol: &str,
order_id: Option<i64>,
start_time: Option<i64>,
end_time: Option<i64>,
limit: Option<u32>,
) -> BinanceSpotHttpResult<Vec<BinanceAccountTrade>>
pub async fn account_trades( &self, symbol: &str, order_id: Option<i64>, start_time: Option<i64>, end_time: Option<i64>, limit: Option<u32>, ) -> BinanceSpotHttpResult<Vec<BinanceAccountTrade>>
Returns account trade history for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn query_order(
&self,
symbol: &str,
order_id: Option<i64>,
client_order_id: Option<&str>,
) -> BinanceSpotHttpResult<BinanceOrderResponse>
pub async fn query_order( &self, symbol: &str, order_id: Option<i64>, client_order_id: Option<&str>, ) -> BinanceSpotHttpResult<BinanceOrderResponse>
Queries an order’s status.
Either order_id or client_order_id must be provided.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn open_orders(
&self,
symbol: Option<&str>,
) -> BinanceSpotHttpResult<Vec<BinanceOrderResponse>>
pub async fn open_orders( &self, symbol: Option<&str>, ) -> BinanceSpotHttpResult<Vec<BinanceOrderResponse>>
Returns all open orders for a symbol or all symbols.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn all_orders(
&self,
symbol: &str,
start_time: Option<i64>,
end_time: Option<i64>,
limit: Option<u32>,
) -> BinanceSpotHttpResult<Vec<BinanceOrderResponse>>
pub async fn all_orders( &self, symbol: &str, start_time: Option<i64>, end_time: Option<i64>, limit: Option<u32>, ) -> BinanceSpotHttpResult<Vec<BinanceOrderResponse>>
Returns all orders (including closed) for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn new_order(
&self,
symbol: &str,
side: BinanceSide,
order_type: BinanceSpotOrderType,
time_in_force: Option<BinanceTimeInForce>,
quantity: Option<&str>,
price: Option<&str>,
client_order_id: Option<&str>,
stop_price: Option<&str>,
) -> BinanceSpotHttpResult<BinanceNewOrderResponse>
pub async fn new_order( &self, symbol: &str, side: BinanceSide, order_type: BinanceSpotOrderType, time_in_force: Option<BinanceTimeInForce>, quantity: Option<&str>, price: Option<&str>, client_order_id: Option<&str>, stop_price: Option<&str>, ) -> BinanceSpotHttpResult<BinanceNewOrderResponse>
Sourcepub async fn cancel_replace_order(
&self,
symbol: &str,
side: BinanceSide,
order_type: BinanceSpotOrderType,
time_in_force: Option<BinanceTimeInForce>,
quantity: Option<&str>,
price: Option<&str>,
cancel_order_id: Option<i64>,
cancel_client_order_id: Option<&str>,
new_client_order_id: Option<&str>,
) -> BinanceSpotHttpResult<BinanceNewOrderResponse>
pub async fn cancel_replace_order( &self, symbol: &str, side: BinanceSide, order_type: BinanceSpotOrderType, time_in_force: Option<BinanceTimeInForce>, quantity: Option<&str>, price: Option<&str>, cancel_order_id: Option<i64>, cancel_client_order_id: Option<&str>, new_client_order_id: Option<&str>, ) -> BinanceSpotHttpResult<BinanceNewOrderResponse>
Cancels an existing order and places a new order atomically.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn cancel_order(
&self,
symbol: &str,
order_id: Option<i64>,
client_order_id: Option<&str>,
) -> BinanceSpotHttpResult<BinanceCancelOrderResponse>
pub async fn cancel_order( &self, symbol: &str, order_id: Option<i64>, client_order_id: Option<&str>, ) -> BinanceSpotHttpResult<BinanceCancelOrderResponse>
Cancels an existing order.
Either order_id or client_order_id must be provided.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn cancel_open_orders(
&self,
symbol: &str,
) -> BinanceSpotHttpResult<Vec<BinanceCancelOrderResponse>>
pub async fn cancel_open_orders( &self, symbol: &str, ) -> BinanceSpotHttpResult<Vec<BinanceCancelOrderResponse>>
Cancels all open orders for a symbol.
§Errors
Returns an error if the request fails or SBE decoding fails.
Sourcepub async fn create_listen_key(
&self,
) -> BinanceSpotHttpResult<ListenKeyResponse>
pub async fn create_listen_key( &self, ) -> BinanceSpotHttpResult<ListenKeyResponse>
Creates a new listen key for the user data stream.
Listen keys are valid for 60 minutes. Use extend_listen_key to keep
the stream alive.
§Errors
Returns an error if credentials are missing or the request fails.
Sourcepub async fn extend_listen_key(
&self,
listen_key: &str,
) -> BinanceSpotHttpResult<()>
pub async fn extend_listen_key( &self, listen_key: &str, ) -> BinanceSpotHttpResult<()>
Extends the validity of a listen key by 60 minutes.
Should be called periodically to keep the user data stream alive.
§Errors
Returns an error if credentials are missing or the request fails.
Sourcepub async fn close_listen_key(
&self,
listen_key: &str,
) -> BinanceSpotHttpResult<()>
pub async fn close_listen_key( &self, listen_key: &str, ) -> BinanceSpotHttpResult<()>
Closes a listen key, terminating the user data stream.
§Errors
Returns an error if credentials are missing or the request fails.
Trait Implementations§
Source§impl Clone for BinanceRawSpotHttpClient
impl Clone for BinanceRawSpotHttpClient
Source§fn clone(&self) -> BinanceRawSpotHttpClient
fn clone(&self) -> BinanceRawSpotHttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinanceRawSpotHttpClient
impl !RefUnwindSafe for BinanceRawSpotHttpClient
impl Send for BinanceRawSpotHttpClient
impl Sync for BinanceRawSpotHttpClient
impl Unpin for BinanceRawSpotHttpClient
impl UnsafeUnpin for BinanceRawSpotHttpClient
impl !UnwindSafe for BinanceRawSpotHttpClient
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