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_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 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)
pub async fn disconnect(&mut self)
Disconnects from the WebSocket API server.
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.
§Panics
Panics if the internal output receiver mutex is poisoned.
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 · 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 Send for BinanceSpotWsTradingClient
impl Sync for BinanceSpotWsTradingClient
impl Unpin for BinanceSpotWsTradingClient
impl UnsafeUnpin for BinanceSpotWsTradingClient
impl !UnwindSafe 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
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