Skip to main content

BinanceRawSpotHttpClient

Struct BinanceRawSpotHttpClient 

Source
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

Source

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.

Source

pub const fn schema_id() -> u16

Returns the SBE schema ID.

Source

pub const fn schema_version() -> u16

Returns the SBE schema version.

Source

pub async fn get<P>( &self, path: &str, params: Option<&P>, ) -> BinanceSpotHttpResult<Vec<u8>>
where P: Serialize + ?Sized,

Performs a GET request and returns raw response bytes.

§Errors

Returns an error if the request fails.

Source

pub async fn get_signed<P>( &self, path: &str, params: Option<&P>, ) -> BinanceSpotHttpResult<Vec<u8>>
where P: Serialize + ?Sized,

Performs a signed GET request and returns raw response bytes.

§Errors

Returns an error if credentials are missing or the request fails.

Source

pub async fn ping(&self) -> BinanceSpotHttpResult<()>

Tests connectivity to the API.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn avg_price(&self, symbol: &str) -> BinanceSpotHttpResult<AvgPrice>

Returns current average price for a symbol.

§Errors

Returns an error if the request fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Creates a new order.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> BinanceRawSpotHttpClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BinanceRawSpotHttpClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,