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
impl BinanceSpotWsTradingClient
Sourcepub fn new(
url: Option<String>,
api_key: String,
api_secret: String,
heartbeat: Option<u64>,
transport_backend: TransportBackend,
) -> Self
pub fn new( url: Option<String>, api_key: String, api_secret: String, heartbeat: Option<u64>, transport_backend: TransportBackend, ) -> Self
Creates a new BinanceSpotWsTradingClient instance.
Sourcepub fn with_proxy(self, proxy_url: Option<String>) -> Self
pub fn with_proxy(self, proxy_url: Option<String>) -> Self
Configures the proxy used by the WebSocket connection.
Sourcepub fn with_socket_control(self, control: SocketControl) -> Self
pub fn with_socket_control(self, control: SocketControl) -> Self
Configures socket state reporting and reconnect control.
Sourcepub const fn with_recv_window(self, recv_window_ms: Option<u64>) -> Self
pub const fn with_recv_window(self, recv_window_ms: Option<u64>) -> Self
Configures the receive window added to signed WebSocket API requests.
Sourcepub fn with_env(
url: Option<String>,
api_key: Option<String>,
api_secret: Option<String>,
heartbeat: Option<u64>,
transport_backend: TransportBackend,
) -> Result<Self>
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_KEYfor the API keyBINANCE_API_SECRETfor the API secret
§Errors
Returns an error if credentials are missing from environment.
Sourcepub fn from_env(url: Option<String>, heartbeat: Option<u64>) -> Result<Self>
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_KEYfor the API keyBINANCE_API_SECRETfor the API secret
§Errors
Returns an error if environment variables are missing.
Sourcepub fn is_user_data_active(&self) -> bool
pub fn is_user_data_active(&self) -> bool
Returns whether the private user data stream is active on the current connection.
Sourcepub fn mark_user_data_active(&self)
pub fn mark_user_data_active(&self)
Marks the private user data stream active on the current connection.
Sourcepub fn mark_user_data_inactive(&self)
pub fn mark_user_data_inactive(&self)
Marks the private user data stream inactive.
Sourcepub fn next_request_id(&self) -> String
pub fn next_request_id(&self) -> String
Generates the next request ID.
Sourcepub async fn connect(&mut self) -> BinanceWsApiResult<()>
pub async fn connect(&mut self) -> BinanceWsApiResult<()>
Sourcepub async fn disconnect(&mut self) -> BinanceWsApiResult<()>
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.
Sourcepub async fn place_order(
&self,
params: NewOrderParams,
) -> BinanceWsApiResult<String>
pub async fn place_order( &self, params: NewOrderParams, ) -> BinanceWsApiResult<String>
Sourcepub async fn place_order_with_id(
&self,
id: String,
params: NewOrderParams,
) -> BinanceWsApiResult<()>
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.
Sourcepub async fn cancel_order(
&self,
params: CancelOrderParams,
) -> BinanceWsApiResult<String>
pub async fn cancel_order( &self, params: CancelOrderParams, ) -> BinanceWsApiResult<String>
Sourcepub async fn cancel_order_with_id(
&self,
id: String,
params: CancelOrderParams,
) -> BinanceWsApiResult<()>
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.
Sourcepub async fn cancel_replace_order(
&self,
params: CancelReplaceOrderParams,
) -> BinanceWsApiResult<String>
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.
Sourcepub async fn cancel_replace_order_with_id(
&self,
id: String,
params: CancelReplaceOrderParams,
) -> BinanceWsApiResult<()>
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.
Sourcepub async fn cancel_all_orders(
&self,
symbol: impl Into<String>,
) -> BinanceWsApiResult<String>
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.
Sourcepub async fn recv(&self) -> Option<BinanceSpotWsTradingMessage>
pub async fn recv(&self) -> Option<BinanceSpotWsTradingMessage>
Receives the next message from the handler.
Returns None if the receiver is closed or not initialized.
Sourcepub async fn session_logon(&self) -> BinanceWsApiResult<()>
pub async fn session_logon(&self) -> BinanceWsApiResult<()>
Authenticates the WebSocket session via session.logon.
§Errors
Returns an error if the handler is unavailable.
Sourcepub async fn subscribe_user_data(&self) -> BinanceWsApiResult<()>
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
impl Clone for BinanceSpotWsTradingClient
Source§fn clone(&self) -> BinanceSpotWsTradingClient
fn clone(&self) -> BinanceSpotWsTradingClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for BinanceSpotWsTradingClient
impl !RefUnwindSafe for BinanceSpotWsTradingClient
impl !UnwindSafe for BinanceSpotWsTradingClient
impl Send for BinanceSpotWsTradingClient
impl Sync for BinanceSpotWsTradingClient
impl Unpin for BinanceSpotWsTradingClient
impl UnsafeUnpin for BinanceSpotWsTradingClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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