Skip to main content

BinanceSpotWsTradingClient

Struct BinanceSpotWsTradingClient 

Source
pub struct BinanceSpotWsTradingClient { /* private fields */ }
Expand description

Binance Spot WebSocket API client for SBE trading.

This client provides order management via WebSocket with SBE-encoded responses, complementing the HTTP client with lower-latency order submission.

Implementations§

Source§

impl BinanceSpotWsTradingClient

Source

pub fn new( url: Option<String>, api_key: String, api_secret: String, heartbeat: Option<u64>, transport_backend: TransportBackend, ) -> Self

Creates a new BinanceSpotWsTradingClient instance.

Source

pub fn with_proxy(self, proxy_url: Option<String>) -> Self

Configures the proxy used by the WebSocket connection.

Source

pub fn with_socket_control(self, control: SocketControl) -> Self

Configures socket state reporting and reconnect control.

Source

pub const fn with_recv_window(self, recv_window_ms: Option<u64>) -> Self

Configures the receive window added to signed WebSocket API requests.

Source

pub fn with_env( url: Option<String>, api_key: Option<String>, api_secret: Option<String>, heartbeat: Option<u64>, transport_backend: TransportBackend, ) -> Result<Self>

Creates a new client with credentials sourced from environment variables.

Falls back to env vars if api_key or api_secret are None:

  • BINANCE_API_KEY for the API key
  • BINANCE_API_SECRET for the API secret
§Errors

Returns an error if credentials are missing from environment.

Source

pub fn from_env(url: Option<String>, heartbeat: Option<u64>) -> Result<Self>

Creates a new client with credentials loaded entirely from environment variables.

Reads:

  • BINANCE_API_KEY for the API key
  • BINANCE_API_SECRET for the API secret
§Errors

Returns an error if environment variables are missing.

Source

pub fn is_active(&self) -> bool

Returns whether the client is actively connected.

Source

pub fn is_user_data_active(&self) -> bool

Returns whether the private user data stream is active on the current connection.

Source

pub fn mark_user_data_active(&self)

Marks the private user data stream active on the current connection.

Source

pub fn mark_user_data_inactive(&self)

Marks the private user data stream inactive.

Source

pub fn is_closed(&self) -> bool

Returns whether the client is closed.

Source

pub fn next_request_id(&self) -> String

Generates the next request ID.

Source

pub async fn connect(&mut self) -> BinanceWsApiResult<()>

Connects to the WebSocket API server.

§Errors

Returns an error if connection fails.

Source

pub async fn disconnect(&mut self) -> BinanceWsApiResult<()>

Disconnects from the WebSocket API server.

§Errors

Returns an error if the handler task fails or does not stop after abort.

Source

pub async fn place_order( &self, params: NewOrderParams, ) -> BinanceWsApiResult<String>

Places a new order via WebSocket API.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn place_order_with_id( &self, id: String, params: NewOrderParams, ) -> BinanceWsApiResult<()>

Places a new order via WebSocket API using a pre-generated request ID.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn cancel_order( &self, params: CancelOrderParams, ) -> BinanceWsApiResult<String>

Cancels an order via WebSocket API.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn cancel_order_with_id( &self, id: String, params: CancelOrderParams, ) -> BinanceWsApiResult<()>

Cancels an order via WebSocket API using a pre-generated request ID.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn cancel_replace_order( &self, params: CancelReplaceOrderParams, ) -> BinanceWsApiResult<String>

Cancels and replaces an order atomically via WebSocket API.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn cancel_replace_order_with_id( &self, id: String, params: CancelReplaceOrderParams, ) -> BinanceWsApiResult<()>

Cancels and replaces an order atomically via WebSocket API using a pre-generated request ID.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn cancel_all_orders( &self, symbol: impl Into<String>, ) -> BinanceWsApiResult<String>

Cancels all open orders for a symbol via WebSocket API.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn recv(&self) -> Option<BinanceSpotWsTradingMessage>

Receives the next message from the handler.

Returns None if the receiver is closed or not initialized.

Source

pub async fn session_logon(&self) -> BinanceWsApiResult<()>

Authenticates the WebSocket session via session.logon.

§Errors

Returns an error if the handler is unavailable.

Source

pub async fn subscribe_user_data(&self) -> BinanceWsApiResult<()>

Subscribes to the user data stream via userDataStream.subscribe.

§Errors

Returns an error if the handler is unavailable.

Trait Implementations§

Source§

impl Clone for BinanceSpotWsTradingClient

Source§

fn clone(&self) -> BinanceSpotWsTradingClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BinanceSpotWsTradingClient

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: Sized + 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: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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<T> Ungil for T
where T: Send,

§

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