/*
* Margin REST API
*
* Access account information, borrow and repay assets, and trade with Binance Margin.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#![allow(unused_imports)]
use http::Method;
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::collections::BTreeMap;
use crate::common::{config::ConfigurationRestApi, models::RestApiResponse, utils::send_request};
mod apis;
mod models;
pub use apis::*;
pub use models::*;
#[derive(Debug, Clone)]
pub struct RestApi {
configuration: ConfigurationRestApi,
account_api_client: AccountApiClient,
borrow_repay_api_client: BorrowRepayApiClient,
market_data_api_client: MarketDataApiClient,
trade_api_client: TradeApiClient,
transfer_api_client: TransferApiClient,
user_data_stream_api_client: UserDataStreamApiClient,
}
impl RestApi {
pub fn new(configuration: ConfigurationRestApi) -> Self {
let account_api_client = AccountApiClient::new(configuration.clone());
let borrow_repay_api_client = BorrowRepayApiClient::new(configuration.clone());
let market_data_api_client = MarketDataApiClient::new(configuration.clone());
let trade_api_client = TradeApiClient::new(configuration.clone());
let transfer_api_client = TransferApiClient::new(configuration.clone());
let user_data_stream_api_client = UserDataStreamApiClient::new(configuration.clone());
Self {
configuration,
account_api_client,
borrow_repay_api_client,
market_data_api_client,
trade_api_client,
transfer_api_client,
user_data_stream_api_client,
}
}
/// Send an unsigned request to the API
///
/// # Arguments
///
/// * `endpoint` - The API endpoint to send the request to
/// * `method` - The HTTP method to use for the request
/// * `query_params` - A map of query parameters to send with the request
/// * `body_params` - A map of body parameters to send with the request
///
/// # Returns
///
/// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
///
/// # Errors
///
/// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
pub async fn send_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
false,
)
.await
}
/// Send a signed request to the API
///
/// # Arguments
///
/// * `endpoint` - The API endpoint to send the request to
/// * `method` - The HTTP method to use for the request
/// * `query_params` - A map of query parameters to send with the request
/// * `body_params` - A map of body parameters to send with the request
///
/// # Returns
///
/// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
///
/// # Errors
///
/// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
true,
)
.await
}
/// Adjust cross margin max leverage (`USER_DATA`)
///
/// Adjust cross margin max leverage
///
/// Weight(UID): 3000, 1 times/min per IP
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - The margin level need higher than the initial risk ratio of adjusted leverage, the initial risk ratio of 3x is 1.5 , the initial risk ratio of 5x is 1.25; The detail conditions on how to switch between Cross Margin Classic and Cross Margin Pro can refer to [the FAQ](https://www.binance.com/en/support/faq/how-to-activate-the-cross-margin-pro-mode-on-binance-e27786da05e743a694b8c625b3bc475d).
///
/// # Arguments
///
/// - `params`: [`AdjustCrossMarginMaxLeverageParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::AdjustCrossMarginMaxLeverageResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#adjust-cross-margin-max-leverage).
///
pub async fn adjust_cross_margin_max_leverage(
&self,
params: AdjustCrossMarginMaxLeverageParams,
) -> anyhow::Result<RestApiResponse<models::AdjustCrossMarginMaxLeverageResponse>> {
self.account_api_client
.adjust_cross_margin_max_leverage(params)
.await
}
/// Disable Isolated Margin Account (TRADE)
///
/// Disable isolated margin account for a specific symbol. Each trading pair can only be deactivated once every 24 hours.
///
/// Weight(UID): 300
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`DisableIsolatedMarginAccountParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::DisableIsolatedMarginAccountResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#disable-isolated-margin-account).
///
pub async fn disable_isolated_margin_account(
&self,
params: DisableIsolatedMarginAccountParams,
) -> anyhow::Result<RestApiResponse<models::DisableIsolatedMarginAccountResponse>> {
self.account_api_client
.disable_isolated_margin_account(params)
.await
}
/// Enable Isolated Margin Account (TRADE)
///
/// Enable isolated margin account for a specific symbol(Only supports activation of previously disabled accounts).
///
/// Weight(UID): 300
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`EnableIsolatedMarginAccountParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::EnableIsolatedMarginAccountResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#enable-isolated-margin-account).
///
pub async fn enable_isolated_margin_account(
&self,
params: EnableIsolatedMarginAccountParams,
) -> anyhow::Result<RestApiResponse<models::EnableIsolatedMarginAccountResponse>> {
self.account_api_client
.enable_isolated_margin_account(params)
.await
}
/// Get BNB Burn Status (`USER_DATA`)
///
/// Get BNB Burn Status
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`GetBnbBurnStatusParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetBnbBurnStatusResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#get-bnb-burn-status).
///
pub async fn get_bnb_burn_status(
&self,
params: GetBnbBurnStatusParams,
) -> anyhow::Result<RestApiResponse<models::GetBnbBurnStatusResponse>> {
self.account_api_client.get_bnb_burn_status(params).await
}
/// Get Summary of Margin account (`USER_DATA`)
///
/// Get personal margin level information
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`GetSummaryOfMarginAccountParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetSummaryOfMarginAccountResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#get-summary-of-margin-account).
///
pub async fn get_summary_of_margin_account(
&self,
params: GetSummaryOfMarginAccountParams,
) -> anyhow::Result<RestApiResponse<models::GetSummaryOfMarginAccountResponse>> {
self.account_api_client
.get_summary_of_margin_account(params)
.await
}
/// Query Cross Isolated Margin Capital Flow (`USER_DATA`)
///
/// Query Cross Isolated Margin Capital Flow
///
/// Weight(IP): 100
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Only supports querying the data of the last 90 days
///
/// - The time between startTime and endTime cannot be longer than 7 days.
///
/// - If fromId is set, the data with id > fromId will be returned.
/// Otherwise the latest data will be returned
///
/// - To query isolated data, Symbol needs to be entered.
///
/// # Arguments
///
/// - `params`: [`QueryCrossIsolatedMarginCapitalFlowParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryCrossIsolatedMarginCapitalFlowResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-cross-isolated-margin-capital-flow).
///
pub async fn query_cross_isolated_margin_capital_flow(
&self,
params: QueryCrossIsolatedMarginCapitalFlowParams,
) -> anyhow::Result<
RestApiResponse<Vec<models::QueryCrossIsolatedMarginCapitalFlowResponseInner>>,
> {
self.account_api_client
.query_cross_isolated_margin_capital_flow(params)
.await
}
/// Query Cross Margin Account Details (`USER_DATA`)
///
/// Query Cross Margin Account Details
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryCrossMarginAccountDetailsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryCrossMarginAccountDetailsResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-cross-margin-account-details).
///
pub async fn query_cross_margin_account_details(
&self,
params: QueryCrossMarginAccountDetailsParams,
) -> anyhow::Result<RestApiResponse<models::QueryCrossMarginAccountDetailsResponse>> {
self.account_api_client
.query_cross_margin_account_details(params)
.await
}
/// Query Cross Margin Fee Data (`USER_DATA`)
///
/// Get cross margin fee data collection with any vip level or user's current specific data as <https://www.binance.com/en/margin-fee>
///
/// Weight: 1 when coin is specified;(IP) 5 when the coin parameter is omitted(IP)
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryCrossMarginFeeDataParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryCrossMarginFeeDataResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-cross-margin-fee-data).
///
pub async fn query_cross_margin_fee_data(
&self,
params: QueryCrossMarginFeeDataParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryCrossMarginFeeDataResponseInner>>> {
self.account_api_client
.query_cross_margin_fee_data(params)
.await
}
/// Query Enabled Isolated Margin Account Limit (`USER_DATA`)
///
/// Query enabled isolated margin account limit.
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryEnabledIsolatedMarginAccountLimitParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryEnabledIsolatedMarginAccountLimitResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-enabled-isolated-margin-account-limit).
///
pub async fn query_enabled_isolated_margin_account_limit(
&self,
params: QueryEnabledIsolatedMarginAccountLimitParams,
) -> anyhow::Result<RestApiResponse<models::QueryEnabledIsolatedMarginAccountLimitResponse>>
{
self.account_api_client
.query_enabled_isolated_margin_account_limit(params)
.await
}
/// Query Isolated Margin Account Info (`USER_DATA`)
///
/// Query Isolated Margin Account Info
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If "symbols" is not sent, all isolated assets will be returned.
///
/// - If "symbols" is sent, only the isolated assets of the sent symbols
/// will be returned.
///
/// # Arguments
///
/// - `params`: [`QueryIsolatedMarginAccountInfoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryIsolatedMarginAccountInfoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-isolated-margin-account-info).
///
pub async fn query_isolated_margin_account_info(
&self,
params: QueryIsolatedMarginAccountInfoParams,
) -> anyhow::Result<RestApiResponse<models::QueryIsolatedMarginAccountInfoResponse>> {
self.account_api_client
.query_isolated_margin_account_info(params)
.await
}
/// Query Isolated Margin Fee Data (`USER_DATA`)
///
/// Get isolated margin fee data collection with any vip level or user's current specific data as <https://www.binance.com/en/margin-fee>
///
/// Weight: 1 when a single is specified;(IP) 10 when the symbol parameter is omitted(IP)
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryIsolatedMarginFeeDataParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryIsolatedMarginFeeDataResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/account#query-isolated-margin-fee-data).
///
pub async fn query_isolated_margin_fee_data(
&self,
params: QueryIsolatedMarginFeeDataParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryIsolatedMarginFeeDataResponseInner>>> {
self.account_api_client
.query_isolated_margin_fee_data(params)
.await
}
/// Get future hourly interest rate (`USER_DATA`)
///
/// Get future hourly interest rate
///
/// Weight(IP): 100
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`GetFutureHourlyInterestRateParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetFutureHourlyInterestRateResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#get-future-hourly-interest-rate).
///
pub async fn get_future_hourly_interest_rate(
&self,
params: GetFutureHourlyInterestRateParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetFutureHourlyInterestRateResponseInner>>>
{
self.borrow_repay_api_client
.get_future_hourly_interest_rate(params)
.await
}
/// Get Interest History (`USER_DATA`)
///
/// Get Interest History
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Response in descending order
///
/// - If isolatedSymbol is not sent, crossed margin data will be returned
///
/// - The max interval between `startTime` and `endTime` is 30 days. It is a
/// MUST to ensure data correctness.
///
/// - If `startTime`and `endTime` not sent, return records of the last 7
/// days by default.
///
/// - If `startTime` is sent and `endTime` is not sent, return records of
/// [max(`startTime`, now-30d), now].
///
/// - If `startTime` is not sent and `endTime` is sent, return records of
/// [`endTime`-7, `endTime`]
///
/// - `type` in response has 4 enums:
///
/// - `PERIODIC` interest charged per hour
///
/// - `ON_BORROW` first interest charged on borrow
///
/// - `PERIODIC_CONVERTED` interest charged per hour converted into BNB
///
/// - `ON_BORROW_CONVERTED` first interest charged on borrow converted into
/// BNB
///
/// - `PORTFOLIO` interest charged daily on the portfolio margin negative
/// balance
///
/// # Arguments
///
/// - `params`: [`GetInterestHistoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetInterestHistoryResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#get-interest-history).
///
pub async fn get_interest_history(
&self,
params: GetInterestHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetInterestHistoryResponse>> {
self.borrow_repay_api_client
.get_interest_history(params)
.await
}
/// Margin account borrow/repay (`USER_DATA`)
///
/// Margin account borrow/repay
///
/// Weight(UID): 1500
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`MarginAccountBorrowRepayParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountBorrowRepayResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#margin-account-borrow-repay).
///
pub async fn margin_account_borrow_repay(
&self,
params: MarginAccountBorrowRepayParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountBorrowRepayResponse>> {
self.borrow_repay_api_client
.margin_account_borrow_repay(params)
.await
}
/// Query borrow/repay records in Margin account (`USER_DATA`)
///
/// Query borrow/repay records in Margin account
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - `txId` or `startTime` must be sent. `txId` takes precedence.
///
/// - Response in descending order
///
/// - If an asset is sent, data within 30 days before `endTime`; If an asset is not sent, data within 7 days before `endTime`
///
/// - If neither `startTime` nor `endTime` is sent, the recent 7-day data will be returned.
///
/// - `startTime` set as `endTime` - 7 days by default, `endTime` set as current time by default
///
/// # Arguments
///
/// - `params`: [`QueryBorrowRepayRecordsInMarginAccountParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryBorrowRepayRecordsInMarginAccountResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#query-borrow-repay-records-in-margin-account).
///
pub async fn query_borrow_repay_records_in_margin_account(
&self,
params: QueryBorrowRepayRecordsInMarginAccountParams,
) -> anyhow::Result<RestApiResponse<models::QueryBorrowRepayRecordsInMarginAccountResponse>>
{
self.borrow_repay_api_client
.query_borrow_repay_records_in_margin_account(params)
.await
}
/// Query Margin Interest Rate History (`USER_DATA`)
///
/// Query Margin Interest Rate History
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginInterestRateHistoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginInterestRateHistoryResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#query-margin-interest-rate-history).
///
pub async fn query_margin_interest_rate_history(
&self,
params: QueryMarginInterestRateHistoryParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginInterestRateHistoryResponseInner>>>
{
self.borrow_repay_api_client
.query_margin_interest_rate_history(params)
.await
}
/// Query Max Borrow (`USER_DATA`)
///
/// Query Max Borrow
///
/// Weight(IP): 50
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If isolatedSymbol is not sent, crossed margin data will be sent.
/// - `borrowLimit` is also available from [https://www.binance.com/en/margin-fee](https://www.binance.com/en/margin-fee)
///
/// # Arguments
///
/// - `params`: [`QueryMaxBorrowParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMaxBorrowResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/borrow-repay#query-max-borrow).
///
pub async fn query_max_borrow(
&self,
params: QueryMaxBorrowParams,
) -> anyhow::Result<RestApiResponse<models::QueryMaxBorrowResponse>> {
self.borrow_repay_api_client.query_max_borrow(params).await
}
/// Cross margin collateral ratio (`MARKET_DATA`)
///
/// Cross margin collateral ratio
///
/// Weight(IP): 100
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`CrossMarginCollateralRatioParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::CrossMarginCollateralRatioResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#cross-margin-collateral-ratio).
///
pub async fn cross_margin_collateral_ratio(
&self,
) -> anyhow::Result<RestApiResponse<Vec<models::CrossMarginCollateralRatioResponseInner>>> {
self.market_data_api_client
.cross_margin_collateral_ratio()
.await
}
/// Get All Cross Margin Pairs (`MARKET_DATA`)
///
/// Get All Cross Margin Pairs
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetAllCrossMarginPairsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetAllCrossMarginPairsResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-all-cross-margin-pairs).
///
pub async fn get_all_cross_margin_pairs(
&self,
params: GetAllCrossMarginPairsParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetAllCrossMarginPairsResponseInner>>> {
self.market_data_api_client
.get_all_cross_margin_pairs(params)
.await
}
/// Get All Isolated Margin Symbol (`MARKET_DATA`)
///
/// Get All Isolated Margin Symbol
///
/// Weight(IP): 10
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetAllIsolatedMarginSymbolParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetAllIsolatedMarginSymbolResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-all-isolated-margin-symbol).
///
pub async fn get_all_isolated_margin_symbol(
&self,
params: GetAllIsolatedMarginSymbolParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetAllIsolatedMarginSymbolResponseInner>>> {
self.market_data_api_client
.get_all_isolated_margin_symbol(params)
.await
}
/// Get All Margin Assets (`MARKET_DATA`)
///
/// Get All Margin Assets.
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetAllMarginAssetsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetAllMarginAssetsResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-all-margin-assets).
///
pub async fn get_all_margin_assets(
&self,
params: GetAllMarginAssetsParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetAllMarginAssetsResponseInner>>> {
self.market_data_api_client
.get_all_margin_assets(params)
.await
}
/// Get Delist Schedule (`MARKET_DATA`)
///
/// Get tokens or symbols delist schedule for cross margin and isolated margin
///
/// Weight(IP): 100
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetDelistScheduleParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetDelistScheduleResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-delist-schedule).
///
pub async fn get_delist_schedule(
&self,
params: GetDelistScheduleParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetDelistScheduleResponseInner>>> {
self.market_data_api_client
.get_delist_schedule(params)
.await
}
/// Get Limit Price Pairs (`MARKET_DATA`)
///
/// Query trading pairs with restriction on limit price range.
///
/// In margin trading, you can place orders with limit price. Limit price
/// should be within (-15%, 15%) of current index price for a list of margin
/// trading pairs. This rule only impacts limit sell orders with limit price
/// that is lower than current index price and limit buy orders with limit
/// price that is higher than current index price.
///
/// - Buy order: Your order will be rejected with an error message
/// notification if the limit price is 15% above the index price.
///
/// - Sell order: Your order will be rejected with an error message
/// notification if the limit price is 15% below the index price.
///
/// Please review the limit price order placing strategy, backtest and
/// calibrate the planned order size with the trading volume and order book
/// depth to prevent trading loss.
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetLimitPricePairsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetLimitPricePairsResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-limit-price-pairs).
///
pub async fn get_limit_price_pairs(
&self,
) -> anyhow::Result<RestApiResponse<models::GetLimitPricePairsResponse>> {
self.market_data_api_client.get_limit_price_pairs().await
}
/// Get list Schedule (`MARKET_DATA`)
///
/// Get the upcoming tokens or symbols listing schedule for Cross Margin and Isolated Margin.
///
/// Weight(IP): 100
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetListScheduleParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetListScheduleResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-list-schedule).
///
pub async fn get_list_schedule(
&self,
params: GetListScheduleParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetListScheduleResponseInner>>> {
self.market_data_api_client.get_list_schedule(params).await
}
/// Get Margin Asset Risk-Based Liquidation Ratio (`MARKET_DATA`)
///
/// Get Margin Asset Risk-Based Liquidation Ratio
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetMarginAssetRiskBasedLiquidationRatioParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetMarginAssetRiskBasedLiquidationRatioResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-margin-asset-risk-based-liquidation-ratio).
///
pub async fn get_margin_asset_risk_based_liquidation_ratio(
&self,
) -> anyhow::Result<
RestApiResponse<Vec<models::GetMarginAssetRiskBasedLiquidationRatioResponseInner>>,
> {
self.market_data_api_client
.get_margin_asset_risk_based_liquidation_ratio()
.await
}
/// Get Margin Restricted Assets (`MARKET_DATA`)
///
/// Get the list of margin-restricted assets.
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`GetMarginRestrictedAssetsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetMarginRestrictedAssetsResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#get-margin-restricted-assets).
///
pub async fn get_margin_restricted_assets(
&self,
) -> anyhow::Result<RestApiResponse<models::GetMarginRestrictedAssetsResponse>> {
self.market_data_api_client
.get_margin_restricted_assets()
.await
}
/// Query Isolated Margin Tier Data (`USER_DATA`)
///
/// Get isolated margin tier data collection with any tier as <https://www.binance.com/en/margin-data>
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryIsolatedMarginTierDataParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryIsolatedMarginTierDataResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#query-isolated-margin-tier-data).
///
pub async fn query_isolated_margin_tier_data(
&self,
params: QueryIsolatedMarginTierDataParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryIsolatedMarginTierDataResponseInner>>>
{
self.market_data_api_client
.query_isolated_margin_tier_data(params)
.await
}
/// Query Liability Coin Leverage Bracket in Cross Margin Pro Mode (`MARKET_DATA`)
///
/// Liability Coin Leverage Bracket in Cross Margin Pro Mode
///
/// Weight(IP): 1
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryLiabilityCoinLeverageBracketInCrossMarginProModeParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryLiabilityCoinLeverageBracketInCrossMarginProModeResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#query-liability-coin-leverage-bracket-in-cross-margin-pro-mode).
///
pub async fn query_liability_coin_leverage_bracket_in_cross_margin_pro_mode(
&self,
) -> anyhow::Result<
RestApiResponse<
Vec<models::QueryLiabilityCoinLeverageBracketInCrossMarginProModeResponseInner>,
>,
> {
self.market_data_api_client
.query_liability_coin_leverage_bracket_in_cross_margin_pro_mode()
.await
}
/// Query Margin Available Inventory (`USER_DATA`)
///
/// Margin available Inventory query
///
/// Weight(UID): 50
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginAvailableInventoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMarginAvailableInventoryResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#query-margin-available-inventory).
///
pub async fn query_margin_available_inventory(
&self,
params: QueryMarginAvailableInventoryParams,
) -> anyhow::Result<RestApiResponse<models::QueryMarginAvailableInventoryResponse>> {
self.market_data_api_client
.query_margin_available_inventory(params)
.await
}
/// Query Margin `PriceIndex` (`MARKET_DATA`)
///
/// Query Margin `PriceIndex`
///
/// Weight(IP): 10
///
/// Security Type: `MARKET_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginPriceindexParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMarginPriceindexResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/market-data#query-margin-priceindex).
///
pub async fn query_margin_priceindex(
&self,
params: QueryMarginPriceindexParams,
) -> anyhow::Result<RestApiResponse<models::QueryMarginPriceindexResponse>> {
self.market_data_api_client
.query_margin_priceindex(params)
.await
}
/// Create Special Key(Low-Latency Trading) (TRADE)
///
/// **Eligibility**
///
/// - Binance Margin offers low-latency trading through a [special key](https://www.binance.com/en/support/faq/frequently-asked-questions-on-margin-special-api-key-3208663e900d4d2e9fec4140e1832f4e), available exclusively to users with VIP level 7 or higher.
/// - If you are VIP level 6 or below, please contact your VIP manager for eligibility criterias.
/// - All new Margin Special Key users are required to read, understand, and agree to the Margin Special Key Supplemental Product Terms at the master account level before creating a Margin Special Key.
/// - Once signed at the master account level, the agreement applies to all sub-accounts. The master account and all sub-accounts (Cross Margin Classic and Portfolio Margin Pro) are authorized to create a Margin Special Key and are subject to the `LiquidationLoan` policy.
///
/// For more information, please refer to [FAQ](https://www.binance.com/en/support/faq/detail/3208663e900d4d2e9fec4140e1832f4e).
///
/// **Supported Products:**
///
/// - Cross Margin
/// - Isolated Margin
/// - Portfolio Margin Pro
///
/// **Unsupported Products:**
///
/// - Portfolio Margin
///
/// We support several types of API keys:
///
/// * Ed25519 (recommended)
/// * HMAC
/// * RSA
///
/// We recommend to **use Ed25519 API keys** as it should provide the best performance and security out of all supported key types. We accept PKCS#8 (BEGIN PUBLIC KEY). For how to generate an RSA key pair to send API requests on Binance. Please refer to the document below [FAQ](https://www.binance.com/en/support/faq/how-to-generate-an-rsa-key-pair-to-send-api-requests-on-binance-2b79728f331e43079b27440d9d15c5db) .
///
/// **How to use the Margin Special Key**
/// - Use the below `sapi` endpoint to create your margin special API Key.
/// - For accessing the Cross Margin account, do not send the `symbol` parameter.
/// - For accessing the Isolated Margin account(s), pass the relevant `symbol` parameter in the API Key creation request.
/// - Use the generated API Key (and Secret key, if applicable) to perform margin trading and listenKey generation via **Spot** REST API (`https://api.binance.com/api/v3/*`) endpoints.
///
/// Read [REST API](/products/spot/rest-api#signed-trade-and-user_data-endpoint-security) or [WebSocket API](/products/spot/web-socket-api#request-security) documentation to learn how to use different API keys
///
/// You need to enable Permits “Enable Spot & Margin Trading” option for the API Key which requests this endpoint.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// Response Notes:
/// - Error Code Description
///
/// - **`UNSUPPORTED_OPERATION`** : Portfolio Margin is an unsupported
/// product, please change the account type to a supported margin product.
///
/// - **Forbidden**: Cross Margin Pro accounts require additional
/// agreements, please contact your relationship manager.
///
/// # Arguments
///
/// - `params`: [`CreateSpecialKeyParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::CreateSpecialKeyResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#create-special-key).
///
pub async fn create_special_key(
&self,
params: CreateSpecialKeyParams,
) -> anyhow::Result<RestApiResponse<models::CreateSpecialKeyResponse>> {
self.trade_api_client.create_special_key(params).await
}
/// Delete Special Key(Low-Latency Trading) (TRADE)
///
/// Deleting your Margin Special Key alone does not exit you from the Margin Special Key framework or discharge your obligations under the Margin Special Key Supplemental Product Terms. To fully exit, you must:
///
/// 1. Delete your Margin Special Key.
/// 2. Ensure there are no outstanding liabilities on the account.
/// 3. Call the Exit Margin Special Key API endpoint.
/// 4. Confirm the exit status via the API response.
///
/// Only after step 4 is completed and the exit status is confirmed by Binance will your account revert to standard liquidation logic and no longer be subject to the Margin Special Key Supplemental Product Terms.
///
/// If apiKey is given, apiName will be ignored. If apiName is given with no
/// apiKey, all apikeys with given apiName will be deleted.
///
/// You need to enable Permits “Enable Spot & Margin” option for the API Key
/// which requests this endpoint.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`DeleteSpecialKeyParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#delete-special-key).
///
pub async fn delete_special_key(
&self,
params: DeleteSpecialKeyParams,
) -> anyhow::Result<RestApiResponse<Value>> {
self.trade_api_client.delete_special_key(params).await
}
/// Edit ip for Special Key(Low-Latency Trading) (TRADE)
///
/// Edit ip restriction. This only applies to Special Key for Low Latency
/// Trading.
///
/// You need to enable Permits “Enable Spot & Margin” option for the API Key
/// which requests this endpoint.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`EditIpForSpecialKeyParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#edit-ip-for-special-key).
///
pub async fn edit_ip_for_special_key(
&self,
params: EditIpForSpecialKeyParams,
) -> anyhow::Result<RestApiResponse<Value>> {
self.trade_api_client.edit_ip_for_special_key(params).await
}
/// Exit Special Key Mode (TRADE)
///
/// Exit the Margin Special Key mode for Cross Margin Classic accounts.
///
/// **All outstanding liabilities under the Cross Margin Classic account must be fully repaid before calling this endpoint.** Deleting the Margin Special Key alone does not constitute a valid exit.
///
/// When a user creates a Margin Special API Key, the account enters "Special Key Mode". Upon a successful request, the following actions will be performed atomically:
///
/// 1. All existing Margin Special API Keys under the Cross Margin Classic mode account will be deleted.
/// 2. All pre-execution margin checks (including Open-order-loss calculation) will revert to standard mode.
/// 3. A cooldown period (default: 24 hours) will be enforced, during which the account will not be permitted to create new Margin Special API Keys.
///
/// For more information, please refer to [FAQ](https://www.binance.com/en/support/faq/detail/3208663e900d4d2e9fec4140e1832f4e).
///
/// **Preconditions:**
///
/// The following conditions must be met; otherwise the request will be rejected:
///
/// - Account type must be **Cross Margin Classic**.
/// - Account must currently be in **Special Key Mode**. If not, the request silently succeeds.
/// - Account must **not be in liquidation**.
/// - Account must **have no liability**.
///
/// You need to enable "Permits Enable Spot & Margin Trading" option for the API Key which requests this endpoint.
///
/// Weight(UID): 10
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`ExitSpecialKeyModeParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<serde_json::Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#exit-special-key-mode).
///
pub async fn exit_special_key_mode(
&self,
params: ExitSpecialKeyModeParams,
) -> anyhow::Result<RestApiResponse<serde_json::Value>> {
self.trade_api_client.exit_special_key_mode(params).await
}
/// Get Force Liquidation Record (`USER_DATA`)
///
/// Get Force Liquidation Record
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Response in descending order
///
/// # Arguments
///
/// - `params`: [`GetForceLiquidationRecordParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetForceLiquidationRecordResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#get-force-liquidation-record).
///
pub async fn get_force_liquidation_record(
&self,
params: GetForceLiquidationRecordParams,
) -> anyhow::Result<RestApiResponse<models::GetForceLiquidationRecordResponse>> {
self.trade_api_client
.get_force_liquidation_record(params)
.await
}
/// Get Small Liability Exchange Coin List (`USER_DATA`)
///
/// Query the coins which can be small liability exchange
///
/// Weight(IP): 100
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`GetSmallLiabilityExchangeCoinListParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#get-small-liability-exchange-coin-list).
///
pub async fn get_small_liability_exchange_coin_list(
&self,
params: GetSmallLiabilityExchangeCoinListParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>>
{
self.trade_api_client
.get_small_liability_exchange_coin_list(params)
.await
}
/// Get Small Liability Exchange History (`USER_DATA`)
///
/// Get Small liability Exchange History
///
/// Weight(UID): 100
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`GetSmallLiabilityExchangeHistoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetSmallLiabilityExchangeHistoryResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#get-small-liability-exchange-history).
///
pub async fn get_small_liability_exchange_history(
&self,
params: GetSmallLiabilityExchangeHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetSmallLiabilityExchangeHistoryResponse>> {
self.trade_api_client
.get_small_liability_exchange_history(params)
.await
}
/// Liquidation Loan Repay (MARGIN)
///
/// Repays the outstanding cross-margin liquidation loan from the user's spot wallet. A liquidation loan represents the account deficit incurred when account equity turns negative during liquidation (bankruptcy). The repayment amount must be greater than 0 and cannot exceed the remaining loan balance. If the Spot Account has insufficient USDC balance, the repayment will fail.
///
/// Weight(UID): 100
///
/// Security Type: MARGIN
///
/// # Arguments
///
/// - `params`: [`LiquidationLoanRepayParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::LiquidationLoanRepayResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#liquidation-loan-repay).
///
pub async fn liquidation_loan_repay(
&self,
params: LiquidationLoanRepayParams,
) -> anyhow::Result<RestApiResponse<models::LiquidationLoanRepayResponse>> {
self.trade_api_client.liquidation_loan_repay(params).await
}
/// Margin Account Cancel all Open Orders on a Symbol (TRADE)
///
/// Cancels all active orders on a symbol for margin account.<br></br>
/// This includes OCO orders.
///
/// Weight(IP): 1
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`MarginAccountCancelAllOpenOrdersOnASymbolParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-cancel-all-open-orders-on-asymbol).
///
pub async fn margin_account_cancel_all_open_orders_on_a_symbol(
&self,
params: MarginAccountCancelAllOpenOrdersOnASymbolParams,
) -> anyhow::Result<
RestApiResponse<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>,
> {
self.trade_api_client
.margin_account_cancel_all_open_orders_on_a_symbol(params)
.await
}
/// Margin Account Cancel OCO (TRADE)
///
/// Cancel an entire Order List for a margin account.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// Notes:
/// - Canceling an individual leg will cancel the entire OCO
///
/// # Arguments
///
/// - `params`: [`MarginAccountCancelOcoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountCancelOcoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-cancel-oco).
///
pub async fn margin_account_cancel_oco(
&self,
params: MarginAccountCancelOcoParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOcoResponse>> {
self.trade_api_client
.margin_account_cancel_oco(params)
.await
}
/// Margin Account Cancel Order (TRADE)
///
/// Cancel an active order for margin account.
///
/// Weight(IP): 10
///
/// Security Type: TRADE
///
/// Notes:
/// - Either orderId or origClientOrderId must be sent.
///
/// # Arguments
///
/// - `params`: [`MarginAccountCancelOrderParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountCancelOrderResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-cancel-order).
///
pub async fn margin_account_cancel_order(
&self,
params: MarginAccountCancelOrderParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOrderResponse>> {
self.trade_api_client
.margin_account_cancel_order(params)
.await
}
/// Margin Account New OCO (TRADE)
///
/// Send in a new OCO for a margin account
///
/// Weight: 6(UID) or 1500(UID) when sideEffectType is `MARGIN_BUY` or `AUTO_BORROW_REPAY`
///
/// Security Type: TRADE
///
/// Notes:
/// - autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
///
/// # Arguments
///
/// - `params`: [`MarginAccountNewOcoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountNewOcoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-new-oco).
///
pub async fn margin_account_new_oco(
&self,
params: MarginAccountNewOcoParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOcoResponse>> {
self.trade_api_client.margin_account_new_oco(params).await
}
/// Margin Account New Order (TRADE)
///
/// Post a new order for margin account.
///
/// Weight: 6(UID) or 1500(UID) when sideEffectType is `MARGIN_BUY` or `AUTO_BORROW_REPAY`
///
/// Security Type: TRADE
///
/// Notes:
/// - autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
///
/// # Arguments
///
/// - `params`: [`MarginAccountNewOrderParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountNewOrderResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-new-order).
///
pub async fn margin_account_new_order(
&self,
params: MarginAccountNewOrderParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOrderResponse>> {
self.trade_api_client.margin_account_new_order(params).await
}
/// Margin Account New OTO (TRADE)
///
/// Post a new OTO order for margin account:
///
/// - 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 unfilled order count,
/// `EXCHANGE_MAX_NUM_ORDERS` filter and `MAX_NUM_ORDERS` filter.
///
/// Weight: 6(UID) or 1500(UID) when sideEffectType is `MARGIN_BUY` or `AUTO_BORROW_REPAY`
///
/// Security Type: TRADE
///
/// Notes:
/// - autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
/// - 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` | | | `pendingTrailingDelta` is provided | `pendingPrice` | |
///
/// # Arguments
///
/// - `params`: [`MarginAccountNewOtoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountNewOtoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-new-oto).
///
pub async fn margin_account_new_oto(
&self,
params: MarginAccountNewOtoParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtoResponse>> {
self.trade_api_client.margin_account_new_oto(params).await
}
/// Margin Account New OTOCO (TRADE)
///
/// Post a new OTOCO order for margin account:
///
///
/// - 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](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-new-oco).
/// - OTOCOs add **3 orders** against the unfilled order count,
/// `EXCHANGE_MAX_NUM_ORDERS` filter, and `MAX_NUM_ORDERS` filter.
///
/// Weight: 6(UID) or 1500(UID) when sideEffectType is `MARGIN_BUY` or `AUTO_BORROW_REPAY`
///
/// Security Type: TRADE
///
/// Notes:
/// - autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
/// - 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` | `pendingAboveStopPrice` and/or `pendingAboveTrailingDelta` | | | `pendingAboveType`=`STOP_LOSS_LIMIT` | `pendingAbovePrice`, `pendingAboveStopPrice` and/or `pendingAboveTrailingDelta`, `pendingAboveTimeInForce` | | | `pendingBelowType`= `LIMIT_MAKER` | `pendingBelowPrice` | | | `pendingBelowType`= `STOP_LOSS` | `pendingBelowStopPrice` and/or `pendingBelowTrailingDelta` | | | `pendingBelowType`=`STOP_LOSS_LIMIT` | `pendingBelowPrice`, `pendingBelowStopPrice` and/or `pendingBelowTrailingDelta`, `pendingBelowTimeInForce` | | | `pendingAboveTrailingDelta` is provided | `pendingAbovePrice` | | | `pendingBelowTrailingDelta` is provided | `pendingBelowPrice` | |
///
/// # Arguments
///
/// - `params`: [`MarginAccountNewOtocoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginAccountNewOtocoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-account-new-otoco).
///
pub async fn margin_account_new_otoco(
&self,
params: MarginAccountNewOtocoParams,
) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtocoResponse>> {
self.trade_api_client.margin_account_new_otoco(params).await
}
/// Margin Manual Liquidation (TRADE)
///
/// Margin Manual Liquidation
///
/// Weight(UID): 3000
///
/// Security Type: TRADE
///
/// Notes:
/// - This endpoint supports Cross Margin Classic Mode and Pro Mode.
/// - Isolated Margin is only supported in restricted regions.
///
/// # Arguments
///
/// - `params`: [`MarginManualLiquidationParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::MarginManualLiquidationResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#margin-manual-liquidation).
///
pub async fn margin_manual_liquidation(
&self,
params: MarginManualLiquidationParams,
) -> anyhow::Result<RestApiResponse<models::MarginManualLiquidationResponse>> {
self.trade_api_client
.margin_manual_liquidation(params)
.await
}
/// Query Current Margin Order Count Usage (TRADE)
///
/// Displays the user's current margin order count usage for all intervals.
///
/// Weight(IP): 20
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`QueryCurrentMarginOrderCountUsageParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-current-margin-order-count-usage).
///
pub async fn query_current_margin_order_count_usage(
&self,
params: QueryCurrentMarginOrderCountUsageParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>>
{
self.trade_api_client
.query_current_margin_order_count_usage(params)
.await
}
/// Query Liquidation Loan (`USER_DATA`)
///
/// Query the current user's cross-margin liquidation loan information, including the original loan amount, repaid amount, and remaining amount. When a cross-margin account is liquidated and the account equity turns negative (bankruptcy), the system generates a liquidation loan record representing the deficit. This represents the shortfall amount denominated in USDC.
///
/// Weight(UID): 100
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryLiquidationLoanParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryLiquidationLoanResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-liquidation-loan).
///
pub async fn query_liquidation_loan(
&self,
params: QueryLiquidationLoanParams,
) -> anyhow::Result<RestApiResponse<models::QueryLiquidationLoanResponse>> {
self.trade_api_client.query_liquidation_loan(params).await
}
/// Query Liquidation Loan Repay History (`USER_DATA`)
///
/// Query the repayment history of cross-margin liquidation loans (deficit caused by bankruptcy during liquidation). Supports time-range filtering and pagination.
///
/// Weight(UID): 100
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - The maximum query range is 90 days. If `startTime` is earlier than 90 days ago, it will be clamped to 90 days ago.
/// - Only records with status `SUCCESS` or `PENDING` are returned. Failed repayment records are excluded.
///
/// # Arguments
///
/// - `params`: [`QueryLiquidationLoanRepayHistoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryLiquidationLoanRepayHistoryResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-liquidation-loan-repay-history).
///
pub async fn query_liquidation_loan_repay_history(
&self,
params: QueryLiquidationLoanRepayHistoryParams,
) -> anyhow::Result<RestApiResponse<models::QueryLiquidationLoanRepayHistoryResponse>> {
self.trade_api_client
.query_liquidation_loan_repay_history(params)
.await
}
/// Query Margin Account's all OCO (`USER_DATA`)
///
/// Retrieves all OCO for a specific margin account based on provided optional parameters
///
/// Weight(IP): 200
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsAllOcoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginAccountsAllOcoResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-all-oco).
///
pub async fn query_margin_accounts_all_oco(
&self,
params: QueryMarginAccountsAllOcoParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOcoResponseInner>>> {
self.trade_api_client
.query_margin_accounts_all_oco(params)
.await
}
/// Query Margin Account's All Orders (`USER_DATA`)
///
/// Query Margin Account's All Orders
///
/// Weight(IP): 200
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If orderId is set, it will get orders >= that orderId. Otherwise the
/// orders within 24 hours are returned.
///
/// - For some historical orders cummulativeQuoteQty will be < 0, meaning
/// the data is not available at this time.
///
/// - Less than 24 hours between startTime and endTime.
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsAllOrdersParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-all-orders).
///
pub async fn query_margin_accounts_all_orders(
&self,
params: QueryMarginAccountsAllOrdersParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>>
{
self.trade_api_client
.query_margin_accounts_all_orders(params)
.await
}
/// Query Margin Account's OCO (`USER_DATA`)
///
/// Retrieves a specific OCO based on provided optional parameters
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsOcoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMarginAccountsOcoResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-oco).
///
pub async fn query_margin_accounts_oco(
&self,
params: QueryMarginAccountsOcoParams,
) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOcoResponse>> {
self.trade_api_client
.query_margin_accounts_oco(params)
.await
}
/// Query Margin Account's Open OCO (`USER_DATA`)
///
/// Query Margin Account's Open OCO
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsOpenOcoParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-open-oco).
///
pub async fn query_margin_accounts_open_oco(
&self,
params: QueryMarginAccountsOpenOcoParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>> {
self.trade_api_client
.query_margin_accounts_open_oco(params)
.await
}
/// Query Margin Account's Open Orders (`USER_DATA`)
///
/// Query Margin Account's Open Orders
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If the symbol is not sent, orders for all symbols will be returned in
/// an array.
///
/// - When all symbols are returned, the number of requests counted against
/// the rate limiter is equal to the number of symbols currently trading on
/// the exchange.
///
/// - If isIsolated ="TRUE", symbol must be sent.
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsOpenOrdersParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-open-orders).
///
pub async fn query_margin_accounts_open_orders(
&self,
params: QueryMarginAccountsOpenOrdersParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>>
{
self.trade_api_client
.query_margin_accounts_open_orders(params)
.await
}
/// Query Margin Account's Order (`USER_DATA`)
///
/// Query Margin Account's Order
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Either orderId or origClientOrderId must be sent.
///
/// - For some historical orders cummulativeQuoteQty will be < 0, meaning
/// the data is not available at this time.
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsOrderParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMarginAccountsOrderResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-order).
///
pub async fn query_margin_accounts_order(
&self,
params: QueryMarginAccountsOrderParams,
) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOrderResponse>> {
self.trade_api_client
.query_margin_accounts_order(params)
.await
}
/// Query Margin Account's Trade List (`USER_DATA`)
///
/// Query Margin Account's Trade List
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If fromId is set, it will get trades >= that fromId. Otherwise the
/// trades within 24 hours are returned.
///
/// - Less than 24 hours between startTime and endTime.
///
/// # Arguments
///
/// - `params`: [`QueryMarginAccountsTradeListParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryMarginAccountsTradeListResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-margin-accounts-trade-list).
///
pub async fn query_margin_accounts_trade_list(
&self,
params: QueryMarginAccountsTradeListParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsTradeListResponseInner>>>
{
self.trade_api_client
.query_margin_accounts_trade_list(params)
.await
}
/// Query Prevented Matches (`USER_DATA`)
///
/// Displays the list of orders that were expired due to STP. (Self-Trade Prevention).
///
/// Weight(IP): 10
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Supported parameter combinations:
///
/// - `symbol` + `preventedMatchId`
///
/// - `symbol` + `orderId`
///
/// - `symbol` + `orderId` + `fromPreventedMatchId`
///
/// - If `orderId` is provided, all prevented matches for that order will be
/// returned.
///
/// - If `preventedMatchId` is provided, the specific prevented match will
/// be returned.
///
/// - A single request returns a maximum of 500 records. If there are more
/// than 500 records, use `symbol` + `orderId` + `fromPreventedMatchId`
/// combination for pagination.
///
/// # Arguments
///
/// - `params`: [`QueryPreventedMatchesParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QueryPreventedMatchesResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-prevented-matches).
///
pub async fn query_prevented_matches(
&self,
params: QueryPreventedMatchesParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QueryPreventedMatchesResponseInner>>> {
self.trade_api_client.query_prevented_matches(params).await
}
/// Query Special key(Low Latency Trading) (TRADE)
///
/// Query Special Key Information.
///
/// This only applies to Special Key for Low Latency Trading.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`QuerySpecialKeyParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QuerySpecialKeyResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-special-key).
///
pub async fn query_special_key(
&self,
params: QuerySpecialKeyParams,
) -> anyhow::Result<RestApiResponse<models::QuerySpecialKeyResponse>> {
self.trade_api_client.query_special_key(params).await
}
/// Query Special key List(Low Latency Trading) (TRADE)
///
/// This only applies to Special Key for Low Latency Trading.
///
/// Weight(UID): 1
///
/// Security Type: TRADE
///
/// # Arguments
///
/// - `params`: [`QuerySpecialKeyListParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Vec<models::QuerySpecialKeyListResponseInner>>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#query-special-key-list).
///
pub async fn query_special_key_list(
&self,
params: QuerySpecialKeyListParams,
) -> anyhow::Result<RestApiResponse<Vec<models::QuerySpecialKeyListResponseInner>>> {
self.trade_api_client.query_special_key_list(params).await
}
/// Small Liability Exchange (MARGIN)
///
/// Small Liability Exchange
///
/// Weight(UID): 3000
///
/// Security Type: MARGIN
///
/// Notes:
/// - Only convert once within 6 hours
/// - Only liability valuation less than 10 USDT are supported
/// - The maximum number of coin is 10
///
/// # Arguments
///
/// - `params`: [`SmallLiabilityExchangeParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/trade#small-liability-exchange).
///
pub async fn small_liability_exchange(
&self,
params: SmallLiabilityExchangeParams,
) -> anyhow::Result<RestApiResponse<Value>> {
self.trade_api_client.small_liability_exchange(params).await
}
/// Get Cross Margin Transfer History (`USER_DATA`)
///
/// Get Cross Margin Transfer History
///
/// Weight(IP): 1
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - Response in descending order
/// - The max interval between `startTime` and `endTime` is 30 days.
/// - Returns data for last 7 days by default
///
/// # Arguments
///
/// - `params`: [`GetCrossMarginTransferHistoryParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::GetCrossMarginTransferHistoryResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/transfer#get-cross-margin-transfer-history).
///
pub async fn get_cross_margin_transfer_history(
&self,
params: GetCrossMarginTransferHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetCrossMarginTransferHistoryResponse>> {
self.transfer_api_client
.get_cross_margin_transfer_history(params)
.await
}
/// Query Max Transfer-Out Amount (`USER_DATA`)
///
/// Query Max Transfer-Out Amount
///
/// Weight(IP): 50
///
/// Security Type: `USER_DATA`
///
/// Notes:
/// - If isolatedSymbol is not sent, crossed margin data will be sent.
///
/// # Arguments
///
/// - `params`: [`QueryMaxTransferOutAmountParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::QueryMaxTransferOutAmountResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/transfer#query-max-transfer-out-amount).
///
pub async fn query_max_transfer_out_amount(
&self,
params: QueryMaxTransferOutAmountParams,
) -> anyhow::Result<RestApiResponse<models::QueryMaxTransferOutAmountResponse>> {
self.transfer_api_client
.query_max_transfer_out_amount(params)
.await
}
/// Close User Data Stream (`USER_STREAM`)
///
/// Close out a user data stream.
///
/// Weight(UID): 3000
///
/// Security Type: `USER_STREAM`
///
/// # Arguments
///
/// - `params`: [`CloseUserDataStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/user-data-stream#close-user-data-stream).
///
pub async fn close_user_data_stream(&self) -> anyhow::Result<RestApiResponse<Value>> {
self.user_data_stream_api_client
.close_user_data_stream()
.await
}
/// Keepalive User Data Stream (`USER_STREAM`)
///
/// Keepalive a user data stream to prevent a time out.
///
/// Weight(UID): 1
///
/// Security Type: `USER_STREAM`
///
/// # Arguments
///
/// - `params`: [`KeepaliveUserDataStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<Value>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/user-data-stream#keepalive-user-data-stream).
///
pub async fn keepalive_user_data_stream(
&self,
params: KeepaliveUserDataStreamParams,
) -> anyhow::Result<RestApiResponse<Value>> {
self.user_data_stream_api_client
.keepalive_user_data_stream(params)
.await
}
/// Start User Data Stream (`USER_STREAM`)
///
/// Start a new user data stream.
///
/// Weight(UID): 1
///
/// Security Type: `USER_STREAM`
///
/// # Arguments
///
/// - `params`: [`StartUserDataStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`RestApiResponse<models::StartUserDataStreamResponse>`] on success.
///
/// # Errors
///
/// This function will return an [`anyhow::Error`] if:
/// - the HTTP request fails
/// - any parameter is invalid
/// - the response cannot be parsed
/// - or one of the following occurs:
/// - `RequiredError`
/// - `ConnectorClientError`
/// - `UnauthorizedError`
/// - `ForbiddenError`
/// - `TooManyRequestsError`
/// - `RateLimitBanError`
/// - `ServerError`
/// - `NotFoundError`
/// - `NetworkError`
/// - `BadRequestError`
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-margin-trading/api/rest-api/user-data-stream#start-user-data-stream).
///
pub async fn start_user_data_stream(
&self,
) -> anyhow::Result<RestApiResponse<models::StartUserDataStreamResponse>> {
self.user_data_stream_api_client
.start_user_data_stream()
.await
}
}