Skip to main content

WebsocketApi

Struct WebsocketApi 

Source
pub struct WebsocketApi { /* private fields */ }

Implementations§

Source§

impl WebsocketApi

Source

pub fn subscribe_on_ws_events<F>(&self, callback: F) -> Subscription
where F: FnMut(WebsocketEvent) + Send + 'static,

Subscribes to WebSocket events with a provided callback function.

§Arguments
  • callback - A mutable function that will be called when a WebSocket event is received. The callback takes a WebsocketEvent as its parameter.
§Returns

A Subscription that can be used to manage the event subscription.

§Examples

let subscription = websocket_api.subscribe_on_ws_events(|event| { // Handle WebSocket event });

Source

pub fn unsubscribe_from_ws_events(&self, subscription: Subscription)

Unsubscribes from WebSocket events using the provided Subscription.

§Arguments
  • subscription - The Subscription to unsubscribe from WebSocket events.
§Examples

let subscription = websocket_api.subscribe_on_ws_events(|event| { // Handle WebSocket event }); websocket_api.unsubscribe_from_ws_events(subscription);

Source

pub async fn disconnect(&self) -> Result<()>

Disconnects the WebSocket connection.

§Returns

A Result indicating whether the disconnection was successful. Returns an error if the disconnection fails.

§Errors

Returns an anyhow::Error if the connection fails.

§Examples

let result = websocket_api.disconnect().await;

Source

pub async fn ping_server(&self)

Sends a ping message to the WebSocket server to check the connection status.

§Examples

websocket_api.ping_server().await;

This method sends a lightweight ping request to verify the WebSocket connection is still active.

Source

pub async fn is_connected(&self) -> bool

Checks if the WebSocket connection is currently active.

§Returns

A bool indicating whether the WebSocket connection is established and active.

§Examples

let is_active = websocket_api.is_connected().await; if is_active { // WebSocket connection is active }

This method provides a way to check the current status of the WebSocket connection.

Source

pub async fn send_message<R: DeserializeOwned + Send + Sync + 'static>( &self, method: &str, payload: BTreeMap<String, Value>, ) -> Result<WebsocketApiResponse<R>, WebsocketError>

Sends an unsigned WebSocket message with the specified method and payload.

§Type Parameters
  • R - The response type to deserialize the message into.
§Arguments
  • method - The WebSocket method to invoke.
  • payload - A map of key-value pairs representing the message payload.
§Returns

A Result containing the deserialized response or a WebsocketError.

§Errors

Returns a WebsocketError if the WebSocket connection fails or the response cannot be deserialized.

§Examples

let response = websocket_api.send_message::(“method_name”, payload).await;

Source

pub async fn send_signed_message<R: DeserializeOwned + Send + Sync + 'static>( &self, method: &str, payload: BTreeMap<String, Value>, ) -> Result<WebsocketApiResponse<R>, WebsocketError>

Sends a signed WebSocket message with the specified method and payload.

§Type Parameters
  • R - The response type to deserialize the message into.
§Arguments
  • method - The WebSocket method to invoke.
  • payload - A map of key-value pairs representing the message payload.
§Returns

A Result containing the deserialized response or a WebsocketError.

§Errors

Returns a WebsocketError if the WebSocket connection fails or the response cannot be deserialized.

§Examples

let response = websocket_api.send_signed_message::(“method_name”, payload).await;

Source

pub async fn account_commission( &self, params: AccountCommissionParams, ) -> Result<WebsocketApiResponse<Box<AccountCommissionResponseResult>>>

WebSocket Account Commission Rates

Get current account commission rates. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Box<models::AccountCommissionResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn account_rate_limits_orders( &self, params: AccountRateLimitsOrdersParams, ) -> Result<WebsocketApiResponse<Vec<AccountRateLimitsOrdersResponseResultInner>>>

WebSocket Unfilled Order Count

Query your current unfilled order count for all intervals. Weight: 40

§Arguments
§Returns

WebsocketApiResponse<Vec<models::AccountRateLimitsOrdersResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn account_status( &self, params: AccountStatusParams, ) -> Result<WebsocketApiResponse<Box<AccountStatusResponseResult>>>

WebSocket Account information

Query information about your account. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Box<models::AccountStatusResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn all_order_lists( &self, params: AllOrderListsParams, ) -> Result<WebsocketApiResponse<Vec<AllOrderListsResponseResultInner>>>

WebSocket Account order list history

Query information about all your order lists, filtered by time range. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Vec<models::AllOrderListsResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn all_orders( &self, params: AllOrdersParams, ) -> Result<WebsocketApiResponse<Vec<AllOrdersResponseResultInner>>>

WebSocket Account order history

Query information about all your orders – active, canceled, filled – filtered by time range. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Vec<models::AllOrdersResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn my_allocations( &self, params: MyAllocationsParams, ) -> Result<WebsocketApiResponse<Vec<MyAllocationsResponseResultInner>>>

WebSocket Account allocations

Retrieves allocations resulting from SOR order placement. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Vec<models::MyAllocationsResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn my_filters( &self, params: MyFiltersParams, ) -> Result<WebsocketApiResponse<Box<MyFiltersResponseResult>>>

WebSocket Query Relevant Filters

Retrieves the list of filters relevant to an account on a given symbol. This is the only method that shows if an account has MAX_ASSET filters applied to it. Weight: 40

§Arguments
§Returns

WebsocketApiResponse<Box<models::MyFiltersResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn my_prevented_matches( &self, params: MyPreventedMatchesParams, ) -> Result<WebsocketApiResponse<Vec<MyPreventedMatchesResponseResultInner>>>

WebSocket Account prevented matches

Displays the list of orders that were expired due to STP.

These are the combinations supported:

  • symbol + preventedMatchId
  • symbol + orderId
  • symbol + orderId + fromPreventedMatchId (limit will default to 500)
  • symbol + orderId + fromPreventedMatchId + limit Weight: Case | Weight –– | —– If symbol is invalid | 2 Querying by preventedMatchId | 2 Querying by orderId | 20
§Arguments
§Returns

WebsocketApiResponse<Vec<models::MyPreventedMatchesResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn my_trades( &self, params: MyTradesParams, ) -> Result<WebsocketApiResponse<Vec<MyTradesResponseResultInner>>>

WebSocket Account trade history

Query information about all your trades, filtered by time range. Weight: Condition| Weight| —| — |Without orderId|20| |With orderId|5|

§Arguments
§Returns

WebsocketApiResponse<Vec<models::MyTradesResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn open_order_lists_status( &self, params: OpenOrderListsStatusParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrderListsStatusResponseResultInner>>>

WebSocket Current open Order lists

Query execution status of all open order lists.

If you need to continuously monitor order status updates, please consider using WebSocket Streams:

  • userDataStream.start request
  • executionReport user data stream event Weight: 6
§Arguments
§Returns

WebsocketApiResponse<Vec<models::OpenOrderListsStatusResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn open_orders_status( &self, params: OpenOrdersStatusParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrdersStatusResponseResultInner>>>

WebSocket Current open orders

Query execution status of all open orders.

If you need to continuously monitor order status updates, please consider using WebSocket Streams:

  • userDataStream.start request
  • executionReport user data stream event Weight: Adjusted based on the number of requested symbols:
ParameterWeight
symbol6
none80
§Arguments
§Returns

WebsocketApiResponse<Vec<models::OpenOrdersStatusResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_amendments( &self, params: OrderAmendmentsParams, ) -> Result<WebsocketApiResponse<Vec<OrderAmendmentsResponseResultInner>>>

WebSocket Query Order Amendments

Queries all amendments of a single order. Weight: 4

§Arguments
§Returns

WebsocketApiResponse<Vec<models::OrderAmendmentsResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_status( &self, params: OrderListStatusParams, ) -> Result<WebsocketApiResponse<Box<AllOrderListsResponseResultInner>>>

WebSocket Query Order list

Check execution status of an Order list.

For execution status of individual orders, use order.status. Weight: 4

§Arguments
§Returns

WebsocketApiResponse<Box<models::AllOrderListsResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_status( &self, params: OrderStatusParams, ) -> Result<WebsocketApiResponse<Box<OrderStatusResponseResult>>>

WebSocket Query order

Check execution status of an order. Weight: 4

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderStatusResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn session_logon( &self, params: SessionLogonParams, ) -> Result<Vec<WebsocketApiResponse<Box<SessionLogonResponseResult>>>>

WebSocket Log in with API key

Authenticate WebSocket connection using the provided API key.

After calling session.logon, you can omit apiKey and signature parameters for future requests that require them.

Note that only one API key can be authenticated. Calling session.logon multiple times changes the current authenticated API key. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::SessionLogonResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn session_logout( &self, params: SessionLogoutParams, ) -> Result<Vec<WebsocketApiResponse<Box<SessionLogoutResponseResult>>>>

WebSocket Log out of the session

Forget the API key previously authenticated. If the connection is not authenticated, this request does nothing.

Note that the WebSocket connection stays open after session.logout request. You can continue using the connection, but now you will have to explicitly provide the apiKey and signature parameters where needed. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::SessionLogoutResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn session_status( &self, params: SessionStatusParams, ) -> Result<WebsocketApiResponse<Box<SessionStatusResponseResult>>>

WebSocket Query session status

Query the status of the WebSocket connection, inspecting which API key (if any) is used to authorize requests. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::SessionStatusResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn exchange_info( &self, params: ExchangeInfoParams, ) -> Result<WebsocketApiResponse<Box<ExchangeInfoResponseResult>>>

WebSocket Exchange information

Query current exchange trading rules, rate limits, and symbol information. Weight: 20

§Arguments
§Returns

WebsocketApiResponse<Box<models::ExchangeInfoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn execution_rules( &self, params: ExecutionRulesParams, ) -> Result<WebsocketApiResponse<Box<ExecutionRulesResponseResult>>>

WebSocket Query Execution Rules

Weight: ParameterWeight
symbol2
symbols2 for each symbol, capped at a max of 40
symbolStatus40
None40
§Arguments
§Returns

WebsocketApiResponse<Box<models::ExecutionRulesResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ping( &self, params: PingParams, ) -> Result<WebsocketApiResponse<Value>>

WebSocket Test connectivity

Test connectivity to the WebSocket API. Weight: 1

§Arguments
  • params: PingParams The parameters for this operation.
§Returns

WebsocketApiResponse<serde_json::Value> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn time( &self, params: TimeParams, ) -> Result<WebsocketApiResponse<Box<TimeResponseResult>>>

WebSocket Check server time

Test connectivity to the WebSocket API and get the current server time. Weight: 1

§Arguments
  • params: TimeParams The parameters for this operation.
§Returns

WebsocketApiResponse<Box<models::TimeResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn avg_price( &self, params: AvgPriceParams, ) -> Result<WebsocketApiResponse<Box<AvgPriceResponseResult>>>

WebSocket Current average price

Get current average price for a symbol. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::AvgPriceResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn block_trades_historical( &self, params: BlockTradesHistoricalParams, ) -> Result<WebsocketApiResponse<Vec<BlockTradesHistoricalResponseResultInner>>>

WebSocket Historical Block Trades

Get block trades. Weight: 25

§Arguments
§Returns

WebsocketApiResponse<Vec<models::BlockTradesHistoricalResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn depth( &self, params: DepthParams, ) -> Result<WebsocketApiResponse<Box<DepthResponseResult>>>

WebSocket Order book

Get current order book.

Note that this request returns limited market depth.

If you need to continuously monitor order book updates, please consider using WebSocket Streams:

  • <symbol>@depth<levels>
  • <symbol>@depth

You can use depth request together with <symbol>@depth streams to maintain a local order book. Weight: Adjusted based on the limit:

LimitWeight
1–1005
101–50025
501–100050
1001–5000250
§Arguments
  • params: DepthParams The parameters for this operation.
§Returns

WebsocketApiResponse<Box<models::DepthResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn klines( &self, params: KlinesParams, ) -> Result<WebsocketApiResponse<Vec<Vec<KlinesItemInner>>>>

WebSocket Klines

Get klines (candlestick bars).

Klines are uniquely identified by their open & close time.

If you need access to real-time kline updates, please consider using WebSocket Streams:

  • <symbol>@kline_<interval>

If you need historical kline data, please consider using data.binance.vision. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn reference_price( &self, params: ReferencePriceParams, ) -> Result<WebsocketApiResponse<Box<ReferencePriceResponseResult>>>

WebSocket Query Reference Price

Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::ReferencePriceResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn reference_price_calculation( &self, params: ReferencePriceCalculationParams, ) -> Result<WebsocketApiResponse<Box<ReferencePriceCalculationResponseResult>>>

WebSocket Query Reference Price Calculation

Describes how reference price is calculated for a given symbol. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::ReferencePriceCalculationResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ticker( &self, params: TickerParams, ) -> Result<WebsocketApiResponse<TickerResponse>>

WebSocket Rolling window price change statistics

Get rolling window price change statistics with a custom window.

This request is similar to ticker.24hr, but statistics are computed on demand using the arbitrary window you specify. Weight: Adjusted based on the number of requested symbols:

SymbolsWeight
1–504 per symbol
51–100200
§Arguments
§Returns

WebsocketApiResponse<models::TickerResponse> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ticker24hr( &self, params: Ticker24hrParams, ) -> Result<WebsocketApiResponse<Ticker24hrResponse>>

WebSocket 24hr ticker price change statistics

Get 24-hour rolling window price change statistics.

If you need to continuously monitor trading statistics, please consider using WebSocket Streams:

  • <symbol>@ticker or !ticker@arr
  • <symbol>@miniTicker or !miniTicker@arr

If you need different window sizes, use the ticker request. Weight: Adjusted based on the number of requested symbols:

SymbolsWeight
1–202
21–10040
101 or more80
all symbols80
§Arguments
§Returns

WebsocketApiResponse<models::Ticker24hrResponse> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ticker_book( &self, params: TickerBookParams, ) -> Result<WebsocketApiResponse<TickerBookResponse>>

WebSocket Symbol order book ticker

Get the current best price and quantity on the order book.

If you need access to real-time order book ticker updates, please consider using WebSocket Streams:

  • <symbol>@bookTicker Weight: Adjusted based on the number of requested symbols:
ParameterWeight
symbol2
symbols4
none4
§Arguments
§Returns

WebsocketApiResponse<models::TickerBookResponse> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ticker_price( &self, params: TickerPriceParams, ) -> Result<WebsocketApiResponse<TickerPriceResponse>>

WebSocket Symbol price ticker

Get the latest market price for a symbol.

If you need access to real-time price updates, please consider using WebSocket Streams:

  • <symbol>@aggTrade
  • <symbol>@trade Weight: Adjusted based on the number of requested symbols:
ParameterWeight
symbol2
symbols4
none4
§Arguments
§Returns

WebsocketApiResponse<models::TickerPriceResponse> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ticker_trading_day( &self, params: TickerTradingDayParams, ) -> Result<WebsocketApiResponse<Vec<TickerTradingDayResponseResultInner>>>

WebSocket Trading Day Ticker

Price change statistics for a trading day. Weight: 4 for each requested symbol.

The weight for this request will cap at 200 once the number of symbols in the request is more than 50.

§Arguments
§Returns

WebsocketApiResponse<Vec<models::TickerTradingDayResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn trades_aggregate( &self, params: TradesAggregateParams, ) -> Result<WebsocketApiResponse<Vec<TradesAggregateResponseResultInner>>>

WebSocket Aggregate trades

Get aggregate trades.

An aggregate trade (aggtrade) represents one or more individual trades. Trades that fill at the same time, from the same taker order, with the same price – those trades are collected into an aggregate trade with total quantity of the individual trades.

If you need access to real-time trading activity, please consider using WebSocket Streams:

  • <symbol>@aggTrade

If you need historical aggregate trade data, please consider using data.binance.vision. Weight: 4

§Arguments
§Returns

WebsocketApiResponse<Vec<models::TradesAggregateResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn trades_historical( &self, params: TradesHistoricalParams, ) -> Result<WebsocketApiResponse<Vec<TradesHistoricalResponseResultInner>>>

WebSocket Historical trades

Get historical trades. Weight: 25

§Arguments
§Returns

WebsocketApiResponse<Vec<models::TradesHistoricalResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn trades_recent( &self, params: TradesRecentParams, ) -> Result<WebsocketApiResponse<Vec<TradesRecentResponseResultInner>>>

WebSocket Recent trades

Get recent trades.

If you need access to real-time trading activity, please consider using WebSocket Streams:

  • <symbol>@trade Weight: 25
§Arguments
§Returns

WebsocketApiResponse<Vec<models::TradesRecentResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn ui_klines( &self, params: UiKlinesParams, ) -> Result<WebsocketApiResponse<Vec<Vec<KlinesItemInner>>>>

WebSocket UI Klines

Get klines (candlestick bars) optimized for presentation.

This request is similar to klines, having the same parameters and response. uiKlines return modified kline data, optimized for presentation of candlestick charts. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn open_orders_cancel_all( &self, params: OpenOrdersCancelAllParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrdersCancelAllResponseResultInner>>>

WebSocket Cancel open orders

Cancel all open orders on a symbol. This includes orders that are part of an order list. Weight: 1

§Arguments
§Returns

WebsocketApiResponse<Vec<models::OpenOrdersCancelAllResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_amend_keep_priority( &self, params: OrderAmendKeepPriorityParams, ) -> Result<WebsocketApiResponse<Box<OrderAmendKeepPriorityResponseResult>>>

WebSocket Order Amend Keep Priority

Reduce the quantity of an existing open order.

This adds 0 orders to the EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter.

Read Order Amend Keep Priority FAQ to learn more. Weight: 4

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderAmendKeepPriorityResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_cancel( &self, params: OrderCancelParams, ) -> Result<WebsocketApiResponse<Box<OrderCancelResponseResult>>>

WebSocket Cancel order

Cancel an active order. Weight: 1

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderCancelResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_cancel_replace( &self, params: OrderCancelReplaceParams, ) -> Result<WebsocketApiResponse<Box<OrderCancelReplaceResponseResult>>>

WebSocket Cancel and replace order

  • Cancel an existing order and immediately place a new order instead of the canceled one.
  • A new order that was not attempted (i.e. when newOrderResult: NOT_ATTEMPTED), will still increase the unfilled order count by 1.
  • You can only cancel an individual order from an orderList using this method, but the result is the same as canceling the entire orderList. Weight: 1
§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderCancelReplaceResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_cancel( &self, params: OrderListCancelParams, ) -> Result<WebsocketApiResponse<Box<OrderListCancelResponseResult>>>

WebSocket Cancel Order list

Cancel an active order list. Weight: 1

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListCancelResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_place( &self, params: OrderListPlaceParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceResponseResult>>>

👎Deprecated

WebSocket Place new OCO - Deprecated

Send in a new one-cancels-the-other (OCO) pair: LIMIT_MAKER + STOP_LOSS/STOP_LOSS_LIMIT orders (called legs), where activation of one order immediately cancels the other.

This adds 1 order to EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter Weight: 1

Unfilled Order Count: 1

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

§Deprecation

Deprecated: This method may be removed in a future version.

Source

pub async fn order_list_place_oco( &self, params: OrderListPlaceOcoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOcoResponseResult>>>

WebSocket Place new Order list - OCO

Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.

  • An OCO has 2 orders called the above order and below order.
  • One of the orders must be a LIMIT_MAKER/TAKE_PROFIT/TAKE_PROFIT_LIMIT order and the other must be STOP_LOSS or STOP_LOSS_LIMIT order.
  • Price restrictions:
  • If the OCO is on the SELL side:
  • LIMIT_MAKER/TAKE_PROFIT_LIMIT price > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice
  • TAKE_PROFIT stopPrice > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice
  • If the OCO is on the BUY side:
  • LIMIT_MAKER price < Last Traded Price < STOP_LOSS/STOP_LOSS_LIMIT stopPrice
  • TAKE_PROFIT stopPrice > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice
  • OCOs add 2 orders to the EXCHANGE_MAX_ORDERS filter and MAX_NUM_ORDERS filter. Weight: 1

Unfilled Order Count: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceOcoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_place_opo( &self, params: OrderListPlaceOpoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpoResponseResult>>>

WebSocket OPO

Place an OPO.

  • OPOs add 2 orders to the EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter. Weight: 1

Unfilled Order Count: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceOpoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_place_opoco( &self, params: OrderListPlaceOpocoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpocoResponseResult>>>

WebSocket OPOCO

Place an OPOCO. Weight: 1

Unfilled Order Count: 3

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceOpocoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_place_oto( &self, params: OrderListPlaceOtoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtoResponseResult>>>

WebSocket Place new Order list - OTO

Places an OTO.

  • An OTO (One-Triggers-the-Other) is an order list comprised of 2 orders.
  • The first order is called the working order and must be LIMIT or LIMIT_MAKER. Initially, only the working order goes on the order book.
  • The second order is called the pending order. It can be any order type except for MARKET orders using parameter quoteOrderQty. The pending order is only placed on the order book when the working order gets fully filled.
  • If either the working order or the pending order is cancelled individually, the other order in the order list will also be canceled or expired.
  • When the order list is placed, if the working order gets immediately fully filled, the placement response will show the working order as FILLED but the pending order will still appear as PENDING_NEW. You need to query the status of the pending order again to see its updated status.
  • OTOs add 2 orders to the EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter. Weight: 1

Unfilled Order Count: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceOtoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_list_place_otoco( &self, params: OrderListPlaceOtocoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtocoResponseResult>>>

WebSocket Place new Order list - OTOCO

Place an OTOCO.

  • An OTOCO (One-Triggers-One-Cancels-the-Other) is an order list comprised of 3 orders.
  • The first order is called the working order and must be LIMIT or LIMIT_MAKER. Initially, only the working order goes on the order book.
  • The behavior of the working order is the same as the OTO.
  • OTOCO has 2 pending orders (pending above and pending below), forming an OCO pair. The pending orders are only placed on the order book when the working order gets fully filled.
  • The rules of the pending above and pending below follow the same rules as the Order list OCO.
  • OTOCOs add 3 orders to the EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter. Weight: 1

Unfilled Order Count: 3

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderListPlaceOtocoResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_place( &self, params: OrderPlaceParams, ) -> Result<WebsocketApiResponse<Box<OrderPlaceResponseResult>>>

WebSocket Place new order

Send in a new order.

This adds 1 order to the EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter. Weight: 1

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderPlaceResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn order_test( &self, params: OrderTestParams, ) -> Result<WebsocketApiResponse<Box<OrderTestResponseResult>>>

WebSocket Test new order

Test order placement.

Validates new order parameters and verifies your signature but does not send the order into the matching engine. Weight: |Condition| Request Weight| |———— | ———— | |Without computeCommissionRates| 1| |With computeCommissionRates|20|

§Arguments
§Returns

WebsocketApiResponse<Box<models::OrderTestResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn sor_order_place( &self, params: SorOrderPlaceParams, ) -> Result<WebsocketApiResponse<Vec<SorOrderPlaceResponseResultInner>>>

WebSocket Place new order using SOR

Places an order using smart order routing (SOR).

This adds 1 order to the EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter.

Read SOR FAQ to learn more. Weight: 1

Unfilled Order Count: 1

§Arguments
§Returns

WebsocketApiResponse<Vec<models::SorOrderPlaceResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn sor_order_test( &self, params: SorOrderTestParams, ) -> Result<WebsocketApiResponse<Box<SorOrderTestResponseResult>>>

WebSocket Test new order using SOR

Test new order creation and signature/recvWindow using smart order routing (SOR). Creates and validates a new order but does not send it into the matching engine. Weight: |Condition | Request Weight| |———— | ———— | |Without computeCommissionRates| 1 | |With computeCommissionRates |20 |

§Arguments
§Returns

WebsocketApiResponse<Box<models::SorOrderTestResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn session_subscriptions( &self, params: SessionSubscriptionsParams, ) -> Result<WebsocketApiResponse<Vec<SessionSubscriptionsResponseResultInner>>>

WebSocket Listing all subscriptions

Weight: 2

Data Source: Memory

§Arguments
§Returns

WebsocketApiResponse<Vec<models::SessionSubscriptionsResponseResultInner>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn user_data_stream_subscribe( &self, params: UserDataStreamSubscribeParams, ) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>

WebSocket Subscribe to User Data Stream

Subscribe to the User Data Stream in the current WebSocket connection. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn user_data_stream_subscribe_signature( &self, params: UserDataStreamSubscribeSignatureParams, ) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>

WebSocket Subscribe to User Data Stream through signature subscription

Weight: 2

§Arguments
§Returns

WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Source

pub async fn user_data_stream_unsubscribe( &self, params: UserDataStreamUnsubscribeParams, ) -> Result<WebsocketApiResponse<Value>>

WebSocket Unsubscribe from User Data Stream

Stop listening to the User Data Stream in the current WebSocket connection.

Note that session.logout will only close the subscription created with userDataStream.subscribe but not subscriptions opened with userDataStream.subscribe.signature. Weight: 2

§Arguments
§Returns

WebsocketApiResponse<serde_json::Value> on success.

§Errors

Returns an anyhow::Error if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.

For full API details, see the Binance API Documentation.

Trait Implementations§

Source§

impl Clone for WebsocketApi

Source§

fn clone(&self) -> WebsocketApi

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

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

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

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 = 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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