/*
 * Binance Derivatives Trading Portfolio Margin Pro REST API
 *
 * OpenAPI Specification for the Binance Derivatives Trading Portfolio Margin Pro REST API
 *
 * 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,
    market_data_api_client: MarketDataApiClient,
}

impl RestApi {
    pub fn new(configuration: ConfigurationRestApi) -> Self {
        let account_api_client = AccountApiClient::new(configuration.clone());
        let market_data_api_client = MarketDataApiClient::new(configuration.clone());

        Self {
            configuration,
            account_api_client,
            market_data_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
    }

    /// BNB `transfer(USER_DATA)`
    ///
    /// BNB transfer can be between Margin Account and USDM Account
    ///
    ///
    /// * You can only use this function 2 times per 10 minutes in a rolling manner
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`BnbTransferParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::BnbTransferResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/BNB-transfer).
    ///
    pub async fn bnb_transfer(
        &self,
        params: BnbTransferParams,
    ) -> anyhow::Result<RestApiResponse<models::BnbTransferResponse>> {
        self.account_api_client.bnb_transfer(params).await
    }

    /// Change Auto-repay-futures Status(TRADE)
    ///
    /// Change Auto-repay-futures Status
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`ChangeAutoRepayFuturesStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::ChangeAutoRepayFuturesStatusResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Change-Auto-repay-futures-Status).
    ///
    pub async fn change_auto_repay_futures_status(
        &self,
        params: ChangeAutoRepayFuturesStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::ChangeAutoRepayFuturesStatusResponse>> {
        self.account_api_client
            .change_auto_repay_futures_status(params)
            .await
    }

    /// Delete Margin Call Level (`USER_DATA`)
    ///
    /// Delete the margin call level for a Portfolio Margin account.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`DeleteMarginCallLevelParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::DeleteMarginCallLevelResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Delete-Margin-Call-Level).
    ///
    pub async fn delete_margin_call_level(
        &self,
        params: DeleteMarginCallLevelParams,
    ) -> anyhow::Result<RestApiResponse<models::DeleteMarginCallLevelResponse>> {
        self.account_api_client
            .delete_margin_call_level(params)
            .await
    }

    /// Fund Auto-collection(USER_DATA)
    ///
    /// Transfers all assets from Futures Account to Margin account
    ///
    /// * The BNB would not be collected from UM-PM account to the Portfolio Margin account.
    /// * You can only use this function 500 times per hour in a rolling manner.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`FundAutoCollectionParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::FundAutoCollectionResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Fund-Auto-collection).
    ///
    pub async fn fund_auto_collection(
        &self,
        params: FundAutoCollectionParams,
    ) -> anyhow::Result<RestApiResponse<models::FundAutoCollectionResponse>> {
        self.account_api_client.fund_auto_collection(params).await
    }

    /// Fund Collection by `Asset(USER_DATA)`
    ///
    /// Transfers specific asset from Futures Account to Margin account
    ///
    /// * The BNB transfer is not be supported
    ///
    /// Weight: 60
    ///
    /// # Arguments
    ///
    /// - `params`: [`FundCollectionByAssetParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::FundCollectionByAssetResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Fund-Collection-by-Asset).
    ///
    pub async fn fund_collection_by_asset(
        &self,
        params: FundCollectionByAssetParams,
    ) -> anyhow::Result<RestApiResponse<models::FundCollectionByAssetResponse>> {
        self.account_api_client
            .fund_collection_by_asset(params)
            .await
    }

    /// Get Auto-repay-futures `Status(USER_DATA)`
    ///
    /// Query Auto-repay-futures Status
    ///
    /// Weight: 30
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetAutoRepayFuturesStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetAutoRepayFuturesStatusResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Auto-repay-futures-Status).
    ///
    pub async fn get_auto_repay_futures_status(
        &self,
        params: GetAutoRepayFuturesStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetAutoRepayFuturesStatusResponse>> {
        self.account_api_client
            .get_auto_repay_futures_status(params)
            .await
    }

    /// Get Delta Mode `Status(USER_DATA)`
    ///
    /// Query the Delta mode status of current account.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetDeltaModeStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetDeltaModeStatusResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Delta-Mode-Status).
    ///
    pub async fn get_delta_mode_status(
        &self,
        params: GetDeltaModeStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetDeltaModeStatusResponse>> {
        self.account_api_client.get_delta_mode_status(params).await
    }

    /// Get Margin Call Level (`USER_DATA`)
    ///
    /// Get the margin call level for a Portfolio Margin account.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetMarginCallLevelParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetMarginCallLevelResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Margin-Call-Level).
    ///
    pub async fn get_margin_call_level(
        &self,
        params: GetMarginCallLevelParams,
    ) -> anyhow::Result<RestApiResponse<models::GetMarginCallLevelResponse>> {
        self.account_api_client.get_margin_call_level(params).await
    }

    /// Get Portfolio Margin Pro Account `Balance(USER_DATA)`
    ///
    /// Query Portfolio Margin Pro account balance
    ///
    /// Weight: 20
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPortfolioMarginProAccountBalanceParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::GetPortfolioMarginProAccountBalanceResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Balance-Info).
    ///
    pub async fn get_portfolio_margin_pro_account_balance(
        &self,
        params: GetPortfolioMarginProAccountBalanceParams,
    ) -> anyhow::Result<
        RestApiResponse<Vec<models::GetPortfolioMarginProAccountBalanceResponseInner>>,
    > {
        self.account_api_client
            .get_portfolio_margin_pro_account_balance(params)
            .await
    }

    /// Get Portfolio Margin Pro Account `Info(USER_DATA)`
    ///
    /// Get Portfolio Margin Pro Account Info
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPortfolioMarginProAccountInfoParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetPortfolioMarginProAccountInfoResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Account-Info).
    ///
    pub async fn get_portfolio_margin_pro_account_info(
        &self,
        params: GetPortfolioMarginProAccountInfoParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPortfolioMarginProAccountInfoResponse>> {
        self.account_api_client
            .get_portfolio_margin_pro_account_info(params)
            .await
    }

    /// Get Portfolio Margin Pro SPAN Account `Info(USER_DATA)`
    ///
    /// Get Portfolio Margin Pro SPAN Account Info (For Portfolio Margin Pro SPAN users only)
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPortfolioMarginProSpanAccountInfoParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetPortfolioMarginProSpanAccountInfoResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Account-Info-V2).
    ///
    pub async fn get_portfolio_margin_pro_span_account_info(
        &self,
        params: GetPortfolioMarginProSpanAccountInfoParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPortfolioMarginProSpanAccountInfoResponse>> {
        self.account_api_client
            .get_portfolio_margin_pro_span_account_info(params)
            .await
    }

    /// Get Transferable Earn Asset Balance for Portfolio Margin (`USER_DATA`)
    ///
    /// Get transferable earn asset balance for all types of Portfolio Margin account
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetTransferableEarnAssetBalanceForPortfolioMarginParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetTransferableEarnAssetBalanceForPortfolioMarginResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Get-Transferable-Earn-Asset-Balance-for-Portfolio-Margin).
    ///
    pub async fn get_transferable_earn_asset_balance_for_portfolio_margin(
        &self,
        params: GetTransferableEarnAssetBalanceForPortfolioMarginParams,
    ) -> anyhow::Result<
        RestApiResponse<models::GetTransferableEarnAssetBalanceForPortfolioMarginResponse>,
    > {
        self.account_api_client
            .get_transferable_earn_asset_balance_for_portfolio_margin(params)
            .await
    }

    /// Portfolio Margin Pro Bankruptcy Loan Repay
    ///
    /// Repay Portfolio Margin Pro Bankruptcy Loan
    ///
    /// * Please note that the API Key has enabled Spot & Margin Trading permissions to access this endpoint.
    ///
    /// Weight: 3000
    ///
    /// # Arguments
    ///
    /// - `params`: [`PortfolioMarginProBankruptcyLoanRepayParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::PortfolioMarginProBankruptcyLoanRepayResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Classic-Portfolio-Margin-Bankruptcy-Loan-Repay).
    ///
    pub async fn portfolio_margin_pro_bankruptcy_loan_repay(
        &self,
        params: PortfolioMarginProBankruptcyLoanRepayParams,
    ) -> anyhow::Result<RestApiResponse<models::PortfolioMarginProBankruptcyLoanRepayResponse>>
    {
        self.account_api_client
            .portfolio_margin_pro_bankruptcy_loan_repay(params)
            .await
    }

    /// Query Portfolio Margin Pro Bankruptcy Loan `Amount(USER_DATA)`
    ///
    /// Query Portfolio Margin Pro Bankruptcy Loan Amount
    ///
    /// * If there’s no classic portfolio margin bankruptcy loan, the amount would be 0
    ///
    /// Weight: 500
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPortfolioMarginProBankruptcyLoanAmountParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPortfolioMarginProBankruptcyLoanAmountResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Query-Classic-Portfolio-Margin-Bankruptcy-Loan-Amount).
    ///
    pub async fn query_portfolio_margin_pro_bankruptcy_loan_amount(
        &self,
        params: QueryPortfolioMarginProBankruptcyLoanAmountParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPortfolioMarginProBankruptcyLoanAmountResponse>>
    {
        self.account_api_client
            .query_portfolio_margin_pro_bankruptcy_loan_amount(params)
            .await
    }

    /// Query Portfolio Margin Pro Bankruptcy Loan Repay `History(USER_DATA)`
    ///
    /// Query repay history of pmloan for portfolio margin pro.
    ///
    /// * `startTime` and `endTime` cannot be longer than 360 days
    /// * If `startTime` and `endTime` not sent, return records of the last 30 days by default.
    /// * If `startTime`is sent and `endTime` is not sent, return records of [startTime, startTime+30d].
    /// * If `startTime` is not sent and `endTime` is sent, return records of [endTime-30d, endTime].
    ///
    /// Weight: 500
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPortfolioMarginProBankruptcyLoanRepayHistoryParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPortfolioMarginProBankruptcyLoanRepayHistoryResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Query-Portfolio-Margin-Pro-Bankruptcy-Loan-Repay-History).
    ///
    pub async fn query_portfolio_margin_pro_bankruptcy_loan_repay_history(
        &self,
        params: QueryPortfolioMarginProBankruptcyLoanRepayHistoryParams,
    ) -> anyhow::Result<
        RestApiResponse<models::QueryPortfolioMarginProBankruptcyLoanRepayHistoryResponse>,
    > {
        self.account_api_client
            .query_portfolio_margin_pro_bankruptcy_loan_repay_history(params)
            .await
    }

    /// Query Portfolio Margin Pro Negative Balance Interest `History(USER_DATA)`
    ///
    /// Query interest history of negative balance for portfolio margin.
    ///
    /// Weight: 50
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPortfolioMarginProNegativeBalanceInterestHistoryParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::QueryPortfolioMarginProNegativeBalanceInterestHistoryResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/account/Query-Classic-Portfolio-Margin-Negative-Balance-Interest-History).
    ///
    pub async fn query_portfolio_margin_pro_negative_balance_interest_history(
        &self,
        params: QueryPortfolioMarginProNegativeBalanceInterestHistoryParams,
    ) -> anyhow::Result<
        RestApiResponse<
            Vec<models::QueryPortfolioMarginProNegativeBalanceInterestHistoryResponseInner>,
        >,
    > {
        self.account_api_client
            .query_portfolio_margin_pro_negative_balance_interest_history(params)
            .await
    }

    /// Repay futures Negative `Balance(USER_DATA)`
    ///
    /// Repay futures Negative Balance
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`RepayFuturesNegativeBalanceParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::RepayFuturesNegativeBalanceResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Repay-futures-Negative-Balance).
    ///
    pub async fn repay_futures_negative_balance(
        &self,
        params: RepayFuturesNegativeBalanceParams,
    ) -> anyhow::Result<RestApiResponse<models::RepayFuturesNegativeBalanceResponse>> {
        self.account_api_client
            .repay_futures_negative_balance(params)
            .await
    }

    /// Set Margin Call Level (`USER_DATA`)
    ///
    /// Set the margin call level for a Portfolio Margin account. When the account's uniMMR drops to the specified level, a notification will be sent via email and SMS.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`SetMarginCallLevelParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::SetMarginCallLevelResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Set-Margin-Call-Level).
    ///
    pub async fn set_margin_call_level(
        &self,
        params: SetMarginCallLevelParams,
    ) -> anyhow::Result<RestApiResponse<models::SetMarginCallLevelResponse>> {
        self.account_api_client.set_margin_call_level(params).await
    }

    /// Switch Delta Mode(TRADE)
    ///
    /// Switch the Delta mode for existing PM PRO / PM RETAIL accounts.
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`SwitchDeltaModeParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::SwitchDeltaModeResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Switch-Delta-Mode).
    ///
    pub async fn switch_delta_mode(
        &self,
        params: SwitchDeltaModeParams,
    ) -> anyhow::Result<RestApiResponse<models::SwitchDeltaModeResponse>> {
        self.account_api_client.switch_delta_mode(params).await
    }

    /// Transfer LDUSDT/RWUSD for Portfolio Margin(TRADE)
    ///
    /// Transfer LDUSDT/RWUSD as collateral for all types of Portfolio Margin account
    ///
    /// Weight: 1500
    ///
    /// # Arguments
    ///
    /// - `params`: [`TransferLdusdtRwusdForPortfolioMarginParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::TransferLdusdtRwusdForPortfolioMarginResponse>`] 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/docs/derivatives/portfolio-margin-pro/account/Transfer-LDUSDT-Portfolio-Margin).
    ///
    pub async fn transfer_ldusdt_rwusd_for_portfolio_margin(
        &self,
        params: TransferLdusdtRwusdForPortfolioMarginParams,
    ) -> anyhow::Result<RestApiResponse<models::TransferLdusdtRwusdForPortfolioMarginResponse>>
    {
        self.account_api_client
            .transfer_ldusdt_rwusd_for_portfolio_margin(params)
            .await
    }

    /// Get Portfolio Margin Asset `Leverage(USER_DATA)`
    ///
    /// Get Portfolio Margin Asset Leverage
    ///
    /// Weight: 50
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPortfolioMarginAssetLeverageParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::GetPortfolioMarginAssetLeverageResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/market-data/Get-Portfolio-Margin-Asset-Leverage).
    ///
    pub async fn get_portfolio_margin_asset_leverage(
        &self,
    ) -> anyhow::Result<RestApiResponse<Vec<models::GetPortfolioMarginAssetLeverageResponseInner>>>
    {
        self.market_data_api_client
            .get_portfolio_margin_asset_leverage()
            .await
    }

    /// Portfolio Margin Collateral `Rate(MARKET_DATA)`
    ///
    /// Portfolio Margin Collateral Rate
    ///
    /// Weight: 50
    ///
    /// # Arguments
    ///
    /// - `params`: [`PortfolioMarginCollateralRateParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::PortfolioMarginCollateralRateResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/market-data/Classic-Portfolio-Margin-Collateral-Rate).
    ///
    pub async fn portfolio_margin_collateral_rate(
        &self,
    ) -> anyhow::Result<RestApiResponse<Vec<models::PortfolioMarginCollateralRateResponseInner>>>
    {
        self.market_data_api_client
            .portfolio_margin_collateral_rate()
            .await
    }

    /// Portfolio Margin Pro Tiered Collateral `Rate(USER_DATA)`
    ///
    /// Portfolio Margin PRO Tiered Collateral Rate
    ///
    /// Weight: 50
    ///
    /// # Arguments
    ///
    /// - `params`: [`PortfolioMarginProTieredCollateralRateParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::PortfolioMarginProTieredCollateralRateResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/market-data/Portfolio-Margin-Pro-Tiered-Collateral-Rate).
    ///
    pub async fn portfolio_margin_pro_tiered_collateral_rate(
        &self,
        params: PortfolioMarginProTieredCollateralRateParams,
    ) -> anyhow::Result<
        RestApiResponse<Vec<models::PortfolioMarginProTieredCollateralRateResponseInner>>,
    > {
        self.market_data_api_client
            .portfolio_margin_pro_tiered_collateral_rate(params)
            .await
    }

    /// Query Portfolio Margin Asset Index Price (`MARKET_DATA`)
    ///
    /// Query Portfolio Margin Asset Index Price
    ///
    /// Weight: 1 if send asset or 50 if not send asset
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPortfolioMarginAssetIndexPriceParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::QueryPortfolioMarginAssetIndexPriceResponseInner>>`] 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/docs/derivatives/portfolio-margin-pro/market-data/Query-Portfolio-Margin-Asset-Index-Price).
    ///
    pub async fn query_portfolio_margin_asset_index_price(
        &self,
        params: QueryPortfolioMarginAssetIndexPriceParams,
    ) -> anyhow::Result<
        RestApiResponse<Vec<models::QueryPortfolioMarginAssetIndexPriceResponseInner>>,
    > {
        self.market_data_api_client
            .query_portfolio_margin_asset_index_price(params)
            .await
    }
}
