pub struct WebsocketApi { /* private fields */ }Implementations§
Source§impl WebsocketApi
impl WebsocketApi
Sourcepub fn subscribe_on_ws_events<F>(&self, callback: F) -> Subscription
pub fn subscribe_on_ws_events<F>(&self, callback: F) -> Subscription
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 aWebsocketEventas 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
});
Sourcepub fn unsubscribe_from_ws_events(&self, subscription: Subscription)
pub fn unsubscribe_from_ws_events(&self, subscription: Subscription)
Unsubscribes from WebSocket events using the provided Subscription.
§Arguments
subscription- TheSubscriptionto unsubscribe from WebSocket events.
§Examples
let subscription = websocket_api.subscribe_on_ws_events(|event| {
// Handle WebSocket event
});
websocket_api.unsubscribe_from_ws_events(subscription);
Sourcepub async fn disconnect(&self) -> Result<()>
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;
Sourcepub async fn ping_server(&self)
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.
Sourcepub async fn is_connected(&self) -> bool
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.
Sourcepub async fn send_message<R: DeserializeOwned + Send + Sync + 'static>(
&self,
method: &str,
payload: BTreeMap<String, Value>,
) -> Result<WebsocketApiResponse<R>, WebsocketError>
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;
Sourcepub async fn send_signed_message<R: DeserializeOwned + Send + Sync + 'static>(
&self,
method: &str,
payload: BTreeMap<String, Value>,
) -> Result<WebsocketApiResponse<R>, WebsocketError>
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;
Sourcepub async fn account_commission(
&self,
params: AccountCommissionParams,
) -> Result<WebsocketApiResponse<Box<AccountCommissionResponseResult>>>
pub async fn account_commission( &self, params: AccountCommissionParams, ) -> Result<WebsocketApiResponse<Box<AccountCommissionResponseResult>>>
Account Commission Rates (USER_DATA)
Get current account commission rates.
Weight(IP): 20
Security Type: USER_DATA
Notes: Data Source: Database
§Arguments
params:AccountCommissionParamsThe parameters for this operation.
§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.
Sourcepub async fn account_rate_limits_orders(
&self,
params: AccountRateLimitsOrdersParams,
) -> Result<WebsocketApiResponse<Vec<AccountRateLimitsOrdersResponseResultInner>>>
pub async fn account_rate_limits_orders( &self, params: AccountRateLimitsOrdersParams, ) -> Result<WebsocketApiResponse<Vec<AccountRateLimitsOrdersResponseResultInner>>>
Unfilled Order Count (USER_DATA)
Query your current unfilled order count for all intervals.
Weight(IP): 40
Security Type: USER_DATA
Notes: Data Source: Memory
§Arguments
params:AccountRateLimitsOrdersParamsThe parameters for this operation.
§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.
Sourcepub async fn account_status(
&self,
params: AccountStatusParams,
) -> Result<WebsocketApiResponse<Box<AccountStatusResponseResult>>>
pub async fn account_status( &self, params: AccountStatusParams, ) -> Result<WebsocketApiResponse<Box<AccountStatusResponseResult>>>
Account information (USER_DATA)
Query information about your account.
Weight(IP): 20
Security Type: USER_DATA
Notes: Data Source: Memory => Database
§Arguments
params:AccountStatusParamsThe parameters for this operation.
§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.
Sourcepub async fn all_order_lists(
&self,
params: AllOrderListsParams,
) -> Result<WebsocketApiResponse<Vec<AllOrderListsResponseResultInner>>>
pub async fn all_order_lists( &self, params: AllOrderListsParams, ) -> Result<WebsocketApiResponse<Vec<AllOrderListsResponseResultInner>>>
Account order list history (USER_DATA)
Query information about all your order lists, filtered by time range.
Weight(IP): 20
Security Type: USER_DATA
Notes: Data Source: Database
Notes:
- If
startTimeand/orendTimeare specified,fromIdis ignored. Order lists are filtered bytransactionTimeof the last order list execution status update. - If
fromIdis specified, return order lists with order list ID >=fromId. - If no condition is specified, the most recent order lists are returned.
- The time between
startTimeandendTimecan’t be longer than 24 hours.
§Arguments
params:AllOrderListsParamsThe parameters for this operation.
§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.
Sourcepub async fn all_orders(
&self,
params: AllOrdersParams,
) -> Result<WebsocketApiResponse<Vec<AllOrdersResponseResultInner>>>
pub async fn all_orders( &self, params: AllOrdersParams, ) -> Result<WebsocketApiResponse<Vec<AllOrdersResponseResultInner>>>
Account order history (USER_DATA)
Query information about all your orders – active, canceled, filled – filtered by time range.
Weight(IP): 20
Security Type: USER_DATA
Notes: Data Source: Database
Notes:
- If
startTimeand/orendTimeare specified,orderIdis ignored.
Orders are filtered by time of the last execution status update.
-
If
orderIdis specified, return orders with order ID >=orderId. -
If no condition is specified, the most recent orders are returned.
-
For some historical orders the
cummulativeQuoteQtyresponse field may be negative, meaning the data is not available at this time. -
The time between
startTimeandendTimecan’t be longer than 24 hours.
§Arguments
params:AllOrdersParamsThe parameters for this operation.
§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.
Sourcepub async fn my_allocations(
&self,
params: MyAllocationsParams,
) -> Result<WebsocketApiResponse<Vec<MyAllocationsResponseResultInner>>>
pub async fn my_allocations( &self, params: MyAllocationsParams, ) -> Result<WebsocketApiResponse<Vec<MyAllocationsResponseResultInner>>>
Account allocations (USER_DATA)
Retrieves allocations resulting from SOR order placement.
Weight(IP): 20
Security Type: USER_DATA
Notes: Data Source: Database
Supported parameter combinations:
| Parameters | Response |
|---|---|
symbol | allocations from oldest to newest |
symbol + startTime | oldest allocations since startTime |
symbol + endTime | newest allocations until endTime |
symbol + startTime + endTime | allocations within the time range |
symbol + fromAllocationId | allocations by allocation ID |
symbol + orderId | allocations related to an order starting with oldest |
symbol + orderId + fromAllocationId | allocations related to an order by allocation ID |
Note: The time between startTime and endTime can’t be longer than 24 hours.
§Arguments
params:MyAllocationsParamsThe parameters for this operation.
§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.
Sourcepub async fn my_filters(
&self,
params: MyFiltersParams,
) -> Result<WebsocketApiResponse<MyFiltersResponse>>
pub async fn my_filters( &self, params: MyFiltersParams, ) -> Result<WebsocketApiResponse<MyFiltersResponse>>
Query Relevant Filters (USER_DATA)
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(IP): 40
Security Type: USER_DATA
Notes: Data Source: Memory
§Arguments
params:MyFiltersParamsThe parameters for this operation.
§Returns
WebsocketApiResponse<models::MyFiltersResponse> 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.
Sourcepub async fn my_prevented_matches(
&self,
params: MyPreventedMatchesParams,
) -> Result<WebsocketApiResponse<Vec<MyPreventedMatchesResponseResultInner>>>
pub async fn my_prevented_matches( &self, params: MyPreventedMatchesParams, ) -> Result<WebsocketApiResponse<Vec<MyPreventedMatchesResponseResultInner>>>
Account prevented matches (USER_DATA)
Displays the list of orders that were expired due to STP.
These are the combinations supported:
symbol+preventedMatchIdsymbol+orderIdsymbol+orderId+fromPreventedMatchId(limitwill default to 500)symbol+orderId+fromPreventedMatchId+limit
| Weight: Case | Weight |
|---|---|
If symbol is invalid | 2 |
Querying by preventedMatchId | 2 |
Querying by orderId | 20 |
Security Type: USER_DATA
Notes: Data Source: Database
§Arguments
params:MyPreventedMatchesParamsThe parameters for this operation.
§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.
Sourcepub async fn my_trades(
&self,
params: MyTradesParams,
) -> Result<WebsocketApiResponse<Vec<MyTradesResponseResultInner>>>
pub async fn my_trades( &self, params: MyTradesParams, ) -> Result<WebsocketApiResponse<Vec<MyTradesResponseResultInner>>>
Account trade history (USER_DATA)
Query information about all your trades, filtered by time range.
| Weight: Condition | Weight |
|---|---|
| Without orderId | 20 |
| With orderId | 5 |
Security Type: USER_DATA
Notes: Data Source: Memory => Database
Notes:
- If
fromIdis specified, return trades with trade ID >=fromId. - If
startTimeand/orendTimeare specified, trades are filtered by execution time (time). fromIdcannot be used together withstartTimeandendTime.- If
orderIdis specified, only trades related to that order are returned. startTimeandendTimecannot be used together withorderId.- If no condition is specified, the most recent trades are returned.
- The time between
startTimeandendTimecan’t be longer than 24 hours.
§Arguments
params:MyTradesParamsThe parameters for this operation.
§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.
Sourcepub async fn open_order_lists_status(
&self,
params: OpenOrderListsStatusParams,
) -> Result<WebsocketApiResponse<Vec<OpenOrderListsStatusResponseResultInner>>>
pub async fn open_order_lists_status( &self, params: OpenOrderListsStatusParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrderListsStatusResponseResultInner>>>
Current open Order lists (USER_DATA)
Query execution status of all open order lists.
If you need to continuously monitor order status updates, please consider using WebSocket Streams:
userDataStream.subscribeif on an authenticated sessionuserDataStream.subscribe.signatureif subscribing through signature subscription
Weight(IP): 6
Security Type: USER_DATA
Notes: Data Source: Memory -> Database
§Arguments
params:OpenOrderListsStatusParamsThe parameters for this operation.
§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.
Sourcepub async fn open_orders_status(
&self,
params: OpenOrdersStatusParams,
) -> Result<WebsocketApiResponse<Vec<OpenOrdersStatusResponseResultInner>>>
pub async fn open_orders_status( &self, params: OpenOrdersStatusParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrdersStatusResponseResultInner>>>
Current open orders (USER_DATA)
Query execution status of all open orders.
If you need to continuously monitor order status updates, please consider using WebSocket Streams:
userDataStream.subscribeif on an authenticated sessionuserDataStream.subscribe.signatureif subscribing through signature subscription
Weight: | Parameter | Weight |
| ——— | —— |
| symbol | 6 |
| none | 80 |
Security Type: USER_DATA
Notes: Data Source: Memory => Database
§Arguments
params:OpenOrdersStatusParamsThe parameters for this operation.
§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.
Sourcepub async fn order_amendments(
&self,
params: OrderAmendmentsParams,
) -> Result<WebsocketApiResponse<Vec<OrderAmendmentsResponseResultInner>>>
pub async fn order_amendments( &self, params: OrderAmendmentsParams, ) -> Result<WebsocketApiResponse<Vec<OrderAmendmentsResponseResultInner>>>
Query Order Amendments (USER_DATA)
Queries all amendments of a single order.
Weight(IP): 4
Security Type: USER_DATA
Notes: Data Source: Database
§Arguments
params:OrderAmendmentsParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_status(
&self,
params: OrderListStatusParams,
) -> Result<WebsocketApiResponse<Box<OrderListStatusResponseResult>>>
pub async fn order_list_status( &self, params: OrderListStatusParams, ) -> Result<WebsocketApiResponse<Box<OrderListStatusResponseResult>>>
Query Order list (USER_DATA)
Check execution status of an Order list.
For execution status of individual orders, use order.status.
Weight(IP): 4
Security Type: USER_DATA
Notes: Data Source: Database
Notes:
-
origClientOrderIdrefers tolistClientOrderIdof the order list itself. -
If both
origClientOrderIdandorderListIdparameters are specified, onlyorigClientOrderIdis used andorderListIdis ignored.
§Arguments
params:OrderListStatusParamsThe parameters for this operation.
§Returns
WebsocketApiResponse<Box<models::OrderListStatusResponseResult>> 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.
Sourcepub async fn order_status(
&self,
params: OrderStatusParams,
) -> Result<WebsocketApiResponse<Box<OrderStatusResponseResult>>>
pub async fn order_status( &self, params: OrderStatusParams, ) -> Result<WebsocketApiResponse<Box<OrderStatusResponseResult>>>
Query order (USER_DATA)
Check execution status of an order.
Weight(IP): 4
Security Type: USER_DATA
Notes: Data Source: Memory => Database
Notes:
-
If both
orderIdandorigClientOrderIdare provided, theorderIdis searched first, then theorigClientOrderIdfrom that result is checked against that order. If both conditions are not met the request will be rejected. -
For some historical orders the
cummulativeQuoteQtyresponse field may be negative, meaning the data is not available at this time.
§Arguments
params:OrderStatusParamsThe parameters for this operation.
§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.
Sourcepub async fn session_logon(
&self,
params: SessionLogonParams,
) -> Result<Vec<WebsocketApiResponse<Box<SessionLogonResponseResult>>>>
pub async fn session_logon( &self, params: SessionLogonParams, ) -> Result<Vec<WebsocketApiResponse<Box<SessionLogonResponseResult>>>>
Log in with API key (USER_DATA)
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.
Note: Only Ed25519 keys are supported for this feature.
Weight(IP): 2
Security Type: USER_DATA
Notes: Data Source: Memory
§Arguments
params:SessionLogonParamsThe parameters for this operation.
§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.
Sourcepub async fn session_logout(
&self,
params: SessionLogoutParams,
) -> Result<Vec<WebsocketApiResponse<Box<SessionLogoutResponseResult>>>>
pub async fn session_logout( &self, params: SessionLogoutParams, ) -> Result<Vec<WebsocketApiResponse<Box<SessionLogoutResponseResult>>>>
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(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:SessionLogoutParamsThe parameters for this operation.
§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.
Sourcepub async fn session_status(
&self,
params: SessionStatusParams,
) -> Result<WebsocketApiResponse<Box<SessionStatusResponseResult>>>
pub async fn session_status( &self, params: SessionStatusParams, ) -> Result<WebsocketApiResponse<Box<SessionStatusResponseResult>>>
Query session status
Query the status of the WebSocket connection, inspecting which API key (if any) is used to authorize requests.
Weight(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:SessionStatusParamsThe parameters for this operation.
§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.
Sourcepub async fn exchange_info(
&self,
params: ExchangeInfoParams,
) -> Result<WebsocketApiResponse<ExchangeInfoResponse>>
pub async fn exchange_info( &self, params: ExchangeInfoParams, ) -> Result<WebsocketApiResponse<ExchangeInfoResponse>>
Exchange information
Query current exchange trading rules, rate limits, and symbol information.
Weight(IP): 20
Security Type: NONE
Notes: Data Source: Memory
Notes:
- If the value provided to
symbolorsymbolsdo not exist, the endpoint will throw an error saying the symbol is invalid. - All parameters are optional.
- Only one of
symbol,symbols,permissionsparameters can be specified. - Without parameters,
exchangeInfodisplays all symbols with["SPOT", "MARGIN", "LEVERAGED"]permissions. - In order to list all active symbols on the exchange, you need to explicitly request all permissions.
permissionsaccepts either a list of permissions, or a single permission name. E.g."SPOT".
Examples of Symbol Permissions Interpretation from the Response:
[["A","B"]]means you may place an order if your account has either permission “A” or permission “B”.[["A"],["B"]]means you can place an order if your account has permission “A” and permission “B”.[["A"],["B","C"]]means you can place an order if your account has permission “A” and permission “B” or permission “C”. (Inclusive or is applied here, not exclusive or, so your account may have both permission “B” and permission “C”.)
§Arguments
params:ExchangeInfoParamsThe parameters for this operation.
§Returns
WebsocketApiResponse<models::ExchangeInfoResponse> 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.
Sourcepub async fn execution_rules(
&self,
params: ExecutionRulesParams,
) -> Result<WebsocketApiResponse<Box<ExecutionRulesResponseResult>>>
pub async fn execution_rules( &self, params: ExecutionRulesParams, ) -> Result<WebsocketApiResponse<Box<ExecutionRulesResponseResult>>>
Query Execution Rules
Query execution rules for symbols.
| Weight: Parameter | Weight |
|---|---|
symbol | 2 |
symbols | 2 for each symbol, capped at a max of 40 |
symbolStatus | 40 |
| None | 40 |
Security Type: NONE
Notes: Data Source: Memory
Note: No combination of multiple parameters is allowed.
§Arguments
params:ExecutionRulesParamsThe parameters for this operation.
§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.
Sourcepub async fn ping(
&self,
params: PingParams,
) -> Result<WebsocketApiResponse<Value>>
pub async fn ping( &self, params: PingParams, ) -> Result<WebsocketApiResponse<Value>>
Test connectivity
Test connectivity to the WebSocket API.
Note: You can use regular WebSocket ping frames to test connectivity as well, WebSocket API will respond with pong frames as soon as possible. ping request along with time is a safe way to test request-response handling in your application.
Weight(IP): 1
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:PingParamsThe 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.
Sourcepub async fn time(
&self,
params: TimeParams,
) -> Result<WebsocketApiResponse<Box<TimeResponseResult>>>
pub async fn time( &self, params: TimeParams, ) -> Result<WebsocketApiResponse<Box<TimeResponseResult>>>
Check server time
Test connectivity to the WebSocket API and get the current server time.
Weight(IP): 1
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:TimeParamsThe 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.
Sourcepub async fn avg_price(
&self,
params: AvgPriceParams,
) -> Result<WebsocketApiResponse<Box<AvgPriceResponseResult>>>
pub async fn avg_price( &self, params: AvgPriceParams, ) -> Result<WebsocketApiResponse<Box<AvgPriceResponseResult>>>
Current average price
Get current average price for a symbol.
Weight(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:AvgPriceParamsThe parameters for this operation.
§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.
Sourcepub async fn block_trades_historical(
&self,
params: BlockTradesHistoricalParams,
) -> Result<WebsocketApiResponse<Vec<BlockTradesHistoricalResponseResultInner>>>
pub async fn block_trades_historical( &self, params: BlockTradesHistoricalParams, ) -> Result<WebsocketApiResponse<Vec<BlockTradesHistoricalResponseResultInner>>>
Historical Block Trades
Get block trades.
Weight(IP): 25
Security Type: NONE
Notes:
- Data Source: Database
§Arguments
params:BlockTradesHistoricalParamsThe parameters for this operation.
§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.
Sourcepub async fn depth(
&self,
params: DepthParams,
) -> Result<WebsocketApiResponse<Box<DepthResponseResult>>>
pub async fn depth( &self, params: DepthParams, ) -> Result<WebsocketApiResponse<Box<DepthResponseResult>>>
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:
| Limit | Request Weight |
|---|---|
| 1-100 | 5 |
| 101-500 | 25 |
| 501-1000 | 50 |
| 1001-5000 | 250 |
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:DepthParamsThe 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.
Sourcepub async fn klines(
&self,
params: KlinesParams,
) -> Result<WebsocketApiResponse<Vec<Vec<KlinesResponseResultInnerInner>>>>
pub async fn klines( &self, params: KlinesParams, ) -> Result<WebsocketApiResponse<Vec<Vec<KlinesResponseResultInnerInner>>>>
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(IP): 2
Security Type: NONE
Notes: Data Source: Database
Supported kline intervals (case-sensitive):
| Interval | interval value |
|---|---|
| seconds | 1s |
| minutes | 1m, 3m, 5m, 15m, 30m |
| hours | 1h, 2h, 4h, 6h, 8h, 12h |
| days | 1d, 3d |
| weeks | 1w |
| months | 1M |
Notes:
- If
startTimeandendTimeare not sent, the most recent klines are returned. - Supported values for
timeZone: - Hours and minutes (e.g.
-1:00,05:45) - Only hours (e.g.
0,8,4) - Accepted range is strictly [-12:00 to +14:00] inclusive
- If
timeZoneprovided, kline intervals are interpreted in that timezone instead of UTC. - Note that
startTimeandendTimeare always interpreted in UTC, regardless oftimeZone.
§Arguments
params:KlinesParamsThe parameters for this operation.
§Returns
WebsocketApiResponse<Vec<Vec<models::KlinesResponseResultInnerInner>>> 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.
Sourcepub async fn reference_price(
&self,
params: ReferencePriceParams,
) -> Result<WebsocketApiResponse<Box<ReferencePriceResponseResult>>>
pub async fn reference_price( &self, params: ReferencePriceParams, ) -> Result<WebsocketApiResponse<Box<ReferencePriceResponseResult>>>
Query Reference Price
Query Reference Price
Weight(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:ReferencePriceParamsThe parameters for this operation.
§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.
Sourcepub async fn reference_price_calculation(
&self,
params: ReferencePriceCalculationParams,
) -> Result<WebsocketApiResponse<Box<ReferencePriceCalculationResponseResult>>>
pub async fn reference_price_calculation( &self, params: ReferencePriceCalculationParams, ) -> Result<WebsocketApiResponse<Box<ReferencePriceCalculationResponseResult>>>
Query Reference Price Calculation
Query Reference Price Calculation
Weight(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:ReferencePriceCalculationParamsThe parameters for this operation.
§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.
Sourcepub async fn ticker(
&self,
params: TickerParams,
) -> Result<WebsocketApiResponse<TickerResponse>>
pub async fn ticker( &self, params: TickerParams, ) -> Result<WebsocketApiResponse<TickerResponse>>
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.
Note: Window size precision is limited to 1 minute.
While the closeTime is the current time of the request, openTime always start on a minute boundary.
As such, the effective window might be up to 59999 ms wider than the requested windowSize.
Window computation example
For example, a request for "windowSize": "7d" might result in the following window:
{
"openTime": 1659580020000,
"closeTime": 1660184865291
}Time of the request – closeTime – is 1660184865291 (August 11, 2022 02:27:45.291).
Requested window size should put the openTime 7 days before that – August 4, 02:27:45.291 –
but due to limited precision it ends up a bit earlier: 1659580020000 (August 4, 2022 02:27:00),
exactly at the start of a minute.
If you need to continuously monitor trading statistics, please consider using WebSocket Streams:
<symbol>@ticker_<window_size>or!ticker_<window-size>@arr
Weight: Adjusted based on the number of requested symbols:
| Symbols | Weight |
|---|---|
| 1–50 | 4 per symbol |
| 51–100 | 200 |
Security Type: NONE
Notes: Data Source: Database
Supported window sizes:
| Unit | windowSize value |
|---|---|
| minutes | 1m, 2m … 59m |
| hours | 1h, 2h … 23h |
| days | 1d, 2d … 7d |
Notes:
-
Either
symbolorsymbolsmust be specified. -
Maximum number of symbols in one request: 200.
-
Window size units cannot be combined. E.g.,
1d 2his not supported.
§Arguments
params:TickerParamsThe parameters for this operation.
§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.
Sourcepub async fn ticker24hr(
&self,
params: Ticker24hrParams,
) -> Result<WebsocketApiResponse<Ticker24hrResponse>>
pub async fn ticker24hr( &self, params: Ticker24hrParams, ) -> Result<WebsocketApiResponse<Ticker24hrResponse>>
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>@tickeror!ticker@arr -
<symbol>@miniTickeror!miniTicker@arr
If you need different window sizes,
use the ticker request.
Weight: Adjusted based on the number of requested symbols:
| Parameter | Symbols Provided | Weight |
|---|---|---|
| symbol | 1 | 2 |
| omitted | 80 | |
| symbols | 1-20 | 2 |
| 21-100 | 40 | |
| 101+ | 80 | |
| omitted | 80 |
Security Type: NONE
Notes: Data Source: Memory
Notes:
-
symbolandsymbolscannot be used together. -
If no symbol is specified, returns information about all symbols currently trading on the exchange.
§Arguments
params:Ticker24hrParamsThe parameters for this operation.
§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.
Sourcepub async fn ticker_book(
&self,
params: TickerBookParams,
) -> Result<WebsocketApiResponse<TickerBookResponse>>
pub async fn ticker_book( &self, params: TickerBookParams, ) -> Result<WebsocketApiResponse<TickerBookResponse>>
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:
| Parameter | Symbols Provided | Weight |
|---|---|---|
| symbol | 1 | 2 |
| omitted | 4 | |
| symbols | Any | 4 |
Security Type: NONE
Notes: Data Source: Memory
Notes:
-
symbolandsymbolscannot be used together. -
If no symbol is specified, returns information about all symbols currently trading on the exchange.
§Arguments
params:TickerBookParamsThe parameters for this operation.
§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.
Sourcepub async fn ticker_price(
&self,
params: TickerPriceParams,
) -> Result<WebsocketApiResponse<TickerPriceResponse>>
pub async fn ticker_price( &self, params: TickerPriceParams, ) -> Result<WebsocketApiResponse<TickerPriceResponse>>
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:
| Parameter | Symbols Provided | Weight |
|---|---|---|
| symbol | 1 | 2 |
| omitted | 4 | |
| symbols | Any | 4 |
Security Type: NONE
Notes: Data Source: Memory
Notes:
-
symbolandsymbolscannot be used together. -
If no symbol is specified, returns information about all symbols currently trading on the exchange.
§Arguments
params:TickerPriceParamsThe parameters for this operation.
§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.
Sourcepub async fn ticker_trading_day(
&self,
params: TickerTradingDayParams,
) -> Result<WebsocketApiResponse<Vec<TickerTradingDayResponseResultInner>>>
pub async fn ticker_trading_day( &self, params: TickerTradingDayParams, ) -> Result<WebsocketApiResponse<Vec<TickerTradingDayResponseResultInner>>>
Trading Day Ticker
Price change statistics for a trading day.
Weight: 4 for each requested symbol regardless of windowSize. The weight for this request will cap at 200 once the number of symbols in the request is more than 50.
Security Type: NONE
Notes: Data Source: Database
Notes:
- Supported values for
timeZone: - Hours and minutes (e.g.
-1:00,05:45) - Only hours (e.g.
0,8,4)
§Arguments
params:TickerTradingDayParamsThe parameters for this operation.
§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.
Sourcepub async fn trades_aggregate(
&self,
params: TradesAggregateParams,
) -> Result<WebsocketApiResponse<Vec<TradesAggregateResponseResultInner>>>
pub async fn trades_aggregate( &self, params: TradesAggregateParams, ) -> Result<WebsocketApiResponse<Vec<TradesAggregateResponseResultInner>>>
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(IP): 4
Security Type: NONE
Notes: Data Source: Database
- If
fromIdis specified, return aggtrades with aggregate trade ID >=fromId. UsefromIdandlimitto page through all aggtrades. - If
startTimeand/orendTimeare specified, aggtrades are filtered by execution time (T).fromIdcannot be used together withstartTimeandendTime. - If no condition is specified, the most recent aggregate trades are returned.
§Arguments
params:TradesAggregateParamsThe parameters for this operation.
§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.
Sourcepub async fn trades_historical(
&self,
params: TradesHistoricalParams,
) -> Result<WebsocketApiResponse<Vec<TradesHistoricalResponseResultInner>>>
pub async fn trades_historical( &self, params: TradesHistoricalParams, ) -> Result<WebsocketApiResponse<Vec<TradesHistoricalResponseResultInner>>>
Historical trades
Get historical trades.
Weight(IP): 25
Security Type: NONE
Notes: Data Source: Database
Notes:
- If
fromIdis not specified, the most recent trades are returned.
§Arguments
params:TradesHistoricalParamsThe parameters for this operation.
§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.
Sourcepub async fn trades_recent(
&self,
params: TradesRecentParams,
) -> Result<WebsocketApiResponse<Vec<TradesRecentResponseResultInner>>>
pub async fn trades_recent( &self, params: TradesRecentParams, ) -> Result<WebsocketApiResponse<Vec<TradesRecentResponseResultInner>>>
Recent trades
Get recent trades.
If you need access to real-time trading activity, please consider using WebSocket Streams:
<symbol>@trade
Weight(IP): 25
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:TradesRecentParamsThe parameters for this operation.
§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.
Sourcepub async fn ui_klines(
&self,
params: UiKlinesParams,
) -> Result<WebsocketApiResponse<Vec<Vec<KlinesResponseResultInnerInner>>>>
pub async fn ui_klines( &self, params: UiKlinesParams, ) -> Result<WebsocketApiResponse<Vec<Vec<KlinesResponseResultInnerInner>>>>
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(IP): 2
Security Type: NONE
Notes: Data Source: Database
- If
startTimeandendTimeare not sent, the most recent klines are returned. - Supported values for
timeZone: - Hours and minutes (e.g.
-1:00,05:45) - Only hours (e.g.
0,8,4) - Accepted range is strictly [-12:00 to +14:00] inclusive
- If
timeZoneprovided, kline intervals are interpreted in that timezone instead of UTC. - Note that
startTimeandendTimeare always interpreted in UTC, regardless oftimeZone.
§Arguments
params:UiKlinesParamsThe parameters for this operation.
§Returns
WebsocketApiResponse<Vec<Vec<models::KlinesResponseResultInnerInner>>> 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.
Sourcepub async fn open_orders_cancel_all(
&self,
params: OpenOrdersCancelAllParams,
) -> Result<WebsocketApiResponse<Vec<OpenOrdersCancelAllResponseResultInner>>>
pub async fn open_orders_cancel_all( &self, params: OpenOrdersCancelAllParams, ) -> Result<WebsocketApiResponse<Vec<OpenOrdersCancelAllResponseResultInner>>>
Cancel open orders (TRADE)
Cancel all open orders on a symbol. This includes orders that are part of an order list.
Weight(IP): 1
Security Type: TRADE
Notes: Data Source: Matching Engine
§Arguments
params:OpenOrdersCancelAllParamsThe parameters for this operation.
§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.
Sourcepub async fn order_amend_keep_priority(
&self,
params: OrderAmendKeepPriorityParams,
) -> Result<WebsocketApiResponse<Box<OrderAmendKeepPriorityResponseResult>>>
pub async fn order_amend_keep_priority( &self, params: OrderAmendKeepPriorityParams, ) -> Result<WebsocketApiResponse<Box<OrderAmendKeepPriorityResponseResult>>>
Order Amend Keep Priority (TRADE)
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(IP): 4
Unfilled Order Count: 0
Security Type: TRADE
Notes: Data Source: Matching Engine
§Arguments
params:OrderAmendKeepPriorityParamsThe parameters for this operation.
§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.
Sourcepub async fn order_cancel(
&self,
params: OrderCancelParams,
) -> Result<WebsocketApiResponse<Box<OrderCancelResponseResult>>>
pub async fn order_cancel( &self, params: OrderCancelParams, ) -> Result<WebsocketApiResponse<Box<OrderCancelResponseResult>>>
Cancel order (TRADE)
Cancel an active order.
Weight(IP): 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Notes:
-
If both
orderIdandorigClientOrderIdparameters are provided, theorderIdis searched first, then theorigClientOrderIdfrom that result is checked against that order. If both conditions are not met the request will be rejected. -
newClientOrderIdwill replaceclientOrderIdof the canceled order, freeing it up for new orders. -
If you cancel an order that is a part of an order list, the entire order list is canceled.
-
The performance for canceling an order (single cancel or as part of a cancel-replace) is always better when only
orderIdis sent. SendingorigClientOrderIdor bothorderId+origClientOrderIdwill be slower.
§Arguments
params:OrderCancelParamsThe parameters for this operation.
§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.
Sourcepub async fn order_cancel_replace(
&self,
params: OrderCancelReplaceParams,
) -> Result<WebsocketApiResponse<Box<OrderCancelReplaceResponseResult>>>
pub async fn order_cancel_replace( &self, params: OrderCancelReplaceParams, ) -> Result<WebsocketApiResponse<Box<OrderCancelReplaceResponseResult>>>
Cancel and replace order (TRADE)
- 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.not attempted (i.e. when
newOrderResult: NOT_ATTEMPTED), will still increase the unfilled order count by 1.
Weight(IP): 1
Unfilled Order Count: 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Similar to the order.place request,
additional mandatory parameters (*) are determined by the new order type.
Available cancelReplaceMode options:
STOP_ON_FAILURE– if cancellation request fails, new order placement will not be attempted.ALLOW_FAILURE– new order placement will be attempted even if the cancel request fails.
| Request | Response | ||||
|---|---|---|---|---|---|
cancelReplaceMode |
orderRateLimitExceededMode |
Unfilled Order Count | cancelResult |
newOrderResult |
status |
STOP_ON_FAILURE |
DO_NOTHING |
Within Limits | ✅ SUCCESS |
✅ SUCCESS |
200 |
❌ FAILURE |
➖ NOT_ATTEMPTED |
400 |
|||
✅ SUCCESS |
❌ FAILURE |
409 |
|||
| Exceeds Limits | ✅ SUCCESS |
✅ SUCCESS |
N/A | ||
❌ FAILURE |
➖ NOT_ATTEMPTED |
N/A | |||
✅ SUCCESS |
❌ FAILURE |
N/A | |||
CANCEL_ONLY |
Within Limits | ✅ SUCCESS |
✅ SUCCESS |
200 |
|
❌ FAILURE |
➖ NOT_ATTEMPTED |
400 |
|||
✅ SUCCESS |
❌ FAILURE |
409 |
|||
| Exceeds Limits | ❌ FAILURE |
➖ NOT_ATTEMPTED |
429 |
||
✅ SUCCESS |
❌ FAILURE |
429 |
|||
ALLOW_FAILURE |
DO_NOTHING |
Within Limits | ✅ SUCCESS |
✅ SUCCESS |
200 |
❌ FAILURE |
❌ FAILURE |
400 |
|||
❌ FAILURE |
✅ SUCCESS |
409 |
|||
✅ SUCCESS |
❌ FAILURE |
409 |
|||
| Exceeds Limits | ✅ SUCCESS |
✅ SUCCESS |
N/A | ||
❌ FAILURE |
❌ FAILURE |
N/A | |||
❌ FAILURE |
✅ SUCCESS |
N/A | |||
✅ SUCCESS |
❌ FAILURE |
N/A | |||
CANCEL_ONLY |
Within Limits | ✅ SUCCESS |
✅ SUCCESS |
200 |
|
❌ FAILURE |
❌ FAILURE |
400 |
|||
❌ FAILURE |
✅ SUCCESS |
409 |
|||
✅ SUCCESS |
❌ FAILURE |
409 |
|||
| Exceeds Limits | ✅ SUCCESS |
✅ SUCCESS |
200 |
||
❌ FAILURE |
❌ FAILURE |
400 |
|||
❌ FAILURE |
✅ SUCCESS |
N/A | |||
✅ SUCCESS |
❌ FAILURE |
409 |
|||
Notes:
-
If both
cancelOrderIdandcancelOrigClientOrderIdparameters are provided, thecancelOrderIdis searched first, then thecancelOrigClientOrderIdfrom that result is checked against that order. If both conditions are not met the request will be rejected. -
cancelNewClientOrderIdwill replaceclientOrderIdof the canceled order, freeing it up for new orders. -
newClientOrderIdspecifiesclientOrderIdvalue for the placed order.
A new order with the same clientOrderId is accepted only when the previous one is filled or expired.
The new order can reuse old clientOrderId of the canceled order.
- This cancel-replace operation is not transactional.
If one operation succeeds but the other one fails, the successful operation is still executed.
For example, in STOP_ON_FAILURE mode, if the new order placement fails, the old order is still canceled.
-
Filters and order count limits are evaluated before cancellation and order placement occurs.
-
If new order placement is not attempted, your order count is still incremented.
-
Like
order.cancel, if you cancel an individual order from an order list, the entire order list is canceled. -
The performance for canceling an order (single cancel or as part of a cancel-replace) is always better when only
orderIdis sent. SendingorigClientOrderIdor bothorderId+origClientOrderIdwill be slower.
§Arguments
params:OrderCancelReplaceParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_cancel(
&self,
params: OrderListCancelParams,
) -> Result<WebsocketApiResponse<Box<OrderListCancelResponseResult>>>
pub async fn order_list_cancel( &self, params: OrderListCancelParams, ) -> Result<WebsocketApiResponse<Box<OrderListCancelResponseResult>>>
Cancel Order list (TRADE)
Cancel an active order list.
Weight(IP): 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Notes:
-
If both
orderListIdandlistClientOrderIdparameters are provided, theorderListIdis searched first, then thelistClientOrderIdfrom that result is checked against that order. If both conditions are not met the request will be rejected. -
Canceling an individual order with
order.cancelwill cancel the entire order list as well.
§Arguments
params:OrderListCancelParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place(
&self,
params: OrderListPlaceParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceResponseResult>>>
👎Deprecated
pub async fn order_list_place( &self, params: OrderListPlaceParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceResponseResult>>>
Place new OCO - Deprecated (TRADE)
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(IP): 1
Unfilled Order Count: 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Notes:
listClientOrderIdparameter specifieslistClientOrderIdfor the OCO pair.
A new OCO with the same listClientOrderId is accepted only when the previous one is filled or completely expired.
listClientOrderId is distinct from clientOrderId of individual orders.
limitClientOrderIdandstopClientOrderIdspecifyclientOrderIdvalues for both legs of the OCO.
A new order with the same clientOrderId is accepted only when the previous one is filled or expired.
- Price restrictions on the legs:
side | Price relation |
|---|---|
BUY | price < market price < stopPrice |
SELL | price > market price > stopPrice |
- Both legs have the same
quantity.
However, you can set different iceberg quantity for individual legs.
If stopIcebergQty is used, stopLimitTimeInForce must be GTC.
trailingDeltaapplies only to theSTOP_LOSS/STOP_LOSS_LIMITleg of the OCO.
§Arguments
params:OrderListPlaceParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place_oco(
&self,
params: OrderListPlaceOcoParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceOcoResponseResult>>>
pub async fn order_list_place_oco( &self, params: OrderListPlaceOcoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOcoResponseResult>>>
Place new Order list - OCO (TRADE)
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_LIMITorder and the other must beSTOP_LOSSorSTOP_LOSS_LIMITorder. -
Price restrictions:
-
If the OCO is on the
SELLside: -
LIMIT_MAKER/TAKE_PROFIT_LIMITprice> Last Traded Price >STOP_LOSS/STOP_LOSS_LIMITstopPrice -
TAKE_PROFIT stopPrice> Last Traded Price >STOP_LOSS/STOP_LOSS_LIMIT stopPrice -
If the OCO is on the
BUYside: -
LIMIT_MAKERprice< Last Traded Price <STOP_LOSS/STOP_LOSS_LIMITstopPrice -
TAKE_PROFIT stopPrice> Last Traded Price >STOP_LOSS/STOP_LOSS_LIMIT stopPrice -
OCOs add 2 orders to the
EXCHANGE_MAX_ORDERSfilter andMAX_NUM_ORDERSfilter.
Weight(IP): 1
Unfilled Order Count: 2
Security Type: TRADE
Notes: Data Source: Matching Engine
§Arguments
params:OrderListPlaceOcoParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place_opo(
&self,
params: OrderListPlaceOpoParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpoResponseResult>>>
pub async fn order_list_place_opo( &self, params: OrderListPlaceOpoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpoResponseResult>>>
OPO (TRADE)
Place an OPO.
- OPOs add 2 orders to the
EXCHANGE_MAX_NUM_ORDERSfilter andMAX_NUM_ORDERSfilter.
Weight(IP): 1
Unfilled Order Count: 2
Security Type: TRADE
Notes: Data Source: Matching Engine
§Arguments
params:OrderListPlaceOpoParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place_opoco(
&self,
params: OrderListPlaceOpocoParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpocoResponseResult>>>
pub async fn order_list_place_opoco( &self, params: OrderListPlaceOpocoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOpocoResponseResult>>>
OPOCO (TRADE)
Place an OPOCO.
Weight(IP): 1
Unfilled Order Count: 3
Security Type: TRADE
Notes: Data Source: Matching Engine
§Arguments
params:OrderListPlaceOpocoParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place_oto(
&self,
params: OrderListPlaceOtoParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtoResponseResult>>>
pub async fn order_list_place_oto( &self, params: OrderListPlaceOtoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtoResponseResult>>>
Place new Order list - OTO (TRADE)
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
LIMITorLIMIT_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
MARKETorders using parameterquoteOrderQty. 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
FILLEDbut the pending order will still appear asPENDING_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_ORDERSfilter andMAX_NUM_ORDERSfilter.
Weight(IP): 1
Unfilled Order Count: 2
Security Type: TRADE
Notes: Data Source: Matching Engine
Mandatory parameters based on pendingType or workingType
Depending on the pendingType or workingType, some optional parameters will become mandatory.
| Type | Additional mandatory parameters | Additional information |
|---|---|---|
workingType = LIMIT | workingTimeInForce | |
pendingType = LIMIT | pendingPrice, pendingTimeInForce | |
pendingType = STOP_LOSS or TAKE_PROFIT | pendingStopPrice and/or pendingTrailingDelta | |
pendingType =STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT | pendingPrice, pendingStopPrice and/or pendingTrailingDelta, pendingTimeInForce |
§Arguments
params:OrderListPlaceOtoParamsThe parameters for this operation.
§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.
Sourcepub async fn order_list_place_otoco(
&self,
params: OrderListPlaceOtocoParams,
) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtocoResponseResult>>>
pub async fn order_list_place_otoco( &self, params: OrderListPlaceOtocoParams, ) -> Result<WebsocketApiResponse<Box<OrderListPlaceOtocoResponseResult>>>
Place new Order list - OTOCO (TRADE)
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
LIMITorLIMIT_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_ORDERSfilter andMAX_NUM_ORDERSfilter.
Weight(IP): 1
Unfilled Order Count: 3
Security Type: TRADE
Notes: Data Source: Matching Engine
Mandatory parameters based on pendingAboveType, pendingBelowType or workingType
Depending on the pendingAboveType/pendingBelowType or workingType, some optional parameters will become mandatory.
| Type | Additional mandatory parameters | Additional information |
|---|---|---|
workingType = LIMIT | workingTimeInForce | |
pendingAboveType= LIMIT_MAKER | pendingAbovePrice | |
pendingAboveType = STOP_LOSS/TAKE_PROFIT | pendingAboveStopPrice and/or pendingAboveTrailingDelta | |
pendingAboveType=STOP_LOSS_LIMIT/TAKE_PROFIT_LIMIT | pendingAbovePrice, pendingAboveStopPrice and/or pendingAboveTrailingDelta, pendingAboveTimeInForce | |
pendingBelowType= LIMIT_MAKER | pendingBelowPrice | |
pendingBelowType= STOP_LOSS/TAKE_PROFIT | pendingBelowStopPrice and/or pendingBelowTrailingDelta | |
pendingBelowType=STOP_LOSS_LIMIT/TAKE_PROFIT_LIMIT | pendingBelowPrice, pendingBelowStopPrice and/or pendingBelowTrailingDelta, pendingBelowTimeInForce |
§Arguments
params:OrderListPlaceOtocoParamsThe parameters for this operation.
§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.
Sourcepub async fn order_place(
&self,
params: OrderPlaceParams,
) -> Result<WebsocketApiResponse<Box<OrderPlaceResponseResult>>>
pub async fn order_place( &self, params: OrderPlaceParams, ) -> Result<WebsocketApiResponse<Box<OrderPlaceResponseResult>>>
Place new order (TRADE)
Send in a new order.
This adds 1 order to the EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter.
Weight(IP): 1
Unfilled Order Count: 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Certain parameters (*) become mandatory based on the order type:
Order type |
Mandatory parameters |
|---|---|
LIMIT |
|
LIMIT_MAKER |
|
MARKET |
|
STOP_LOSS |
|
STOP_LOSS_LIMIT |
|
TAKE_PROFIT |
|
TAKE_PROFIT_LIMIT |
|
Supported order types:
Order type |
Description |
|---|---|
LIMIT |
Buy or sell |
LIMIT_MAKER |
This order type is also known as a POST-ONLY order. |
MARKET |
Buy or sell at the best available market price.
|
STOP_LOSS |
Execute a
I.e., when |
STOP_LOSS_LIMIT |
Place a |
TAKE_PROFIT |
Like |
TAKE_PROFIT_LIMIT |
Like |
Notes on using parameters for Pegged Orders:
- These parameters are allowed for
LIMIT,LIMIT_MAKER,STOP_LOSS_LIMIT,TAKE_PROFIT_LIMITorders. - If
pegPriceTypeis specified,pricebecomes optional. Otherwise, it is still mandatory. pegPriceType=PRIMARY_PEGmeans the primary peg, that is the best price on the same side of the order book as your order.pegPriceType=MARKET_PEGmeans the market peg, that is the best price on the opposite side of the order book from your order.- Use
pegOffsetTypeandpegOffsetValueto request a price level other than the best one. These parameters must be specified together.
Available timeInForce options,
setting how long the order should be active before expiration:
| TIF | Description |
|---|---|
GTC | Good ’til Canceled – the order will remain on the book until you cancel it, or the order is completely filled. |
IOC | Immediate or Cancel – the order will be filled for as much as possible, the unfilled quantity immediately expires. |
FOK | Fill or Kill – the order will expire unless it cannot be immediately filled for the entire quantity. |
Notes:
newClientOrderIdspecifiesclientOrderIdvalue for the order.
A new order with the same clientOrderId is accepted only when the previous one is filled or expired.
- Any
LIMITorLIMIT_MAKERorder can be made into an iceberg order by specifying theicebergQty.
An order with an icebergQty must have timeInForce set to GTC.
-
Trigger order price rules for
STOP_LOSS/TAKE_PROFITorders: -
stopPricemust be above market price:STOP_LOSS BUY,TAKE_PROFIT SELL -
stopPricemust be below market price:STOP_LOSS SELL,TAKE_PROFIT BUY -
MARKETorders usingquoteOrderQtyfollowLOT_SIZEfilter rules.
The order will execute a quantity that has notional value as close as possible to requested quoteOrderQty.
§Arguments
params:OrderPlaceParamsThe parameters for this operation.
§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.
Sourcepub async fn order_test(
&self,
params: OrderTestParams,
) -> Result<WebsocketApiResponse<Box<OrderTestResponseResult>>>
pub async fn order_test( &self, params: OrderTestParams, ) -> Result<WebsocketApiResponse<Box<OrderTestResponseResult>>>
Test new order (TRADE)
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 |
Security Type: TRADE
Notes: Data Source: Memory
§Arguments
params:OrderTestParamsThe parameters for this operation.
§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.
Sourcepub async fn sor_order_place(
&self,
params: SorOrderPlaceParams,
) -> Result<WebsocketApiResponse<Vec<SorOrderPlaceResponseResultInner>>>
pub async fn sor_order_place( &self, params: SorOrderPlaceParams, ) -> Result<WebsocketApiResponse<Vec<SorOrderPlaceResponseResultInner>>>
Place new order using SOR (TRADE)
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(IP): 1
Unfilled Order Count: 1
Security Type: TRADE
Notes: Data Source: Matching Engine
Note: sor.order.place only supports LIMIT and MARKET orders. quoteOrderQty is not supported.
§Arguments
params:SorOrderPlaceParamsThe parameters for this operation.
§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.
Sourcepub async fn sor_order_test(
&self,
params: SorOrderTestParams,
) -> Result<WebsocketApiResponse<Box<SorOrderTestResponseResult>>>
pub async fn sor_order_test( &self, params: SorOrderTestParams, ) -> Result<WebsocketApiResponse<Box<SorOrderTestResponseResult>>>
Test new order using SOR (TRADE)
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 |
Security Type: TRADE
Notes: Data Source: Memory
§Arguments
params:SorOrderTestParamsThe parameters for this operation.
§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.
Sourcepub async fn session_subscriptions(
&self,
params: SessionSubscriptionsParams,
) -> Result<WebsocketApiResponse<Vec<SessionSubscriptionsResponseResultInner>>>
pub async fn session_subscriptions( &self, params: SessionSubscriptionsParams, ) -> Result<WebsocketApiResponse<Vec<SessionSubscriptionsResponseResultInner>>>
Listing all subscriptions
Note:
- Users should track the corresponding subscription status of related accounts as needed.
Weight(IP): 2
Security Type: NONE
Notes: Data Source: Memory
§Arguments
params:SessionSubscriptionsParamsThe parameters for this operation.
§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.
Sourcepub async fn user_data_stream_subscribe(
&self,
params: UserDataStreamSubscribeParams,
) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>
pub async fn user_data_stream_subscribe( &self, params: UserDataStreamSubscribeParams, ) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>
Subscribe to User Data Stream
Subscribe to the User Data Stream in the current WebSocket connection.
Notes:
- This method requires an authenticated WebSocket connection using Ed25519 keys. Please refer to
session.logon. - To check the subscription status, use
session.status, see theuserDataStreamflag indicating you have have an active subscription. - User Data Stream events are available in both JSON and SBE sessions.
- Please refer to User Data Streams for the event format details.
- For SBE, only SBE schema 2:1 or later is supported.
Weight(IP): 2
Security Type: NONE
§Arguments
params:UserDataStreamSubscribeParamsThe parameters for this operation.
§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.
Sourcepub async fn user_data_stream_subscribe_signature(
&self,
params: UserDataStreamSubscribeSignatureParams,
) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>
pub async fn user_data_stream_subscribe_signature( &self, params: UserDataStreamSubscribeSignatureParams, ) -> Result<(WebsocketApiResponse<Box<UserDataStreamSubscribeResponseResult>>, Arc<WebsocketStream<UserDataStreamEventsResponse>>)>
Subscribe to User Data Stream through signature subscription (USER_STREAM)
Weight(IP): 2
Security Type: USER_STREAM
Notes: Data Source: Memory
§Arguments
params:UserDataStreamSubscribeSignatureParamsThe parameters for this operation.
§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.
Sourcepub async fn user_data_stream_unsubscribe(
&self,
params: UserDataStreamUnsubscribeParams,
) -> Result<WebsocketApiResponse<Value>>
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(IP): 2
§Arguments
params:UserDataStreamUnsubscribeParamsThe 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.
Trait Implementations§
Source§impl Clone for WebsocketApi
impl Clone for WebsocketApi
Source§fn clone(&self) -> WebsocketApi
fn clone(&self) -> WebsocketApi
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more