/*
 * Prediction Trading REST API
 *
 * Place and manage prediction market orders, query positions, and transfer funds via the Prediction Trading 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,
    market_data_api_client: MarketDataApiClient,
    position_api_client: PositionApiClient,
    redeem_api_client: RedeemApiClient,
    trade_api_client: TradeApiClient,
    transfer_api_client: TransferApiClient,
    wallet_api_client: WalletApiClient,
}

impl RestApi {
    pub fn new(configuration: ConfigurationRestApi) -> Self {
        let market_data_api_client = MarketDataApiClient::new(configuration.clone());
        let position_api_client = PositionApiClient::new(configuration.clone());
        let redeem_api_client = RedeemApiClient::new(configuration.clone());
        let trade_api_client = TradeApiClient::new(configuration.clone());
        let transfer_api_client = TransferApiClient::new(configuration.clone());
        let wallet_api_client = WalletApiClient::new(configuration.clone());

        Self {
            configuration,
            market_data_api_client,
            position_api_client,
            redeem_api_client,
            trade_api_client,
            transfer_api_client,
            wallet_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
    }

    /// Get Market Detail
    ///
    /// Get full details for a specific prediction market topic, including variant data and timeline.
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetMarketDetailParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetMarketDetailResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#get-market-detail).
    ///
    pub async fn get_market_detail(
        &self,
        params: GetMarketDetailParams,
    ) -> anyhow::Result<RestApiResponse<models::GetMarketDetailResponse>> {
        self.market_data_api_client.get_market_detail(params).await
    }

    /// List Prediction Categories
    ///
    /// Get all available prediction market categories (L1 and L2).
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`ListPredictionCategoriesParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::ListPredictionCategoriesResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#list-prediction-categories).
    ///
    pub async fn list_prediction_categories(
        &self,
    ) -> anyhow::Result<RestApiResponse<models::ListPredictionCategoriesResponse>> {
        self.market_data_api_client
            .list_prediction_categories()
            .await
    }

    /// List Prediction Markets
    ///
    /// Get a paginated list of prediction market topics, with optional category and sort filters.
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`ListPredictionMarketsParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::ListPredictionMarketsResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#list-prediction-markets).
    ///
    pub async fn list_prediction_markets(
        &self,
        params: ListPredictionMarketsParams,
    ) -> anyhow::Result<RestApiResponse<models::ListPredictionMarketsResponse>> {
        self.market_data_api_client
            .list_prediction_markets(params)
            .await
    }

    /// Market Search
    ///
    /// Semantic search for prediction market topics by keyword.
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`MarketSearchParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<Vec<models::MarketSearchResponseInner>>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#market-search).
    ///
    pub async fn market_search(
        &self,
        params: MarketSearchParams,
    ) -> anyhow::Result<RestApiResponse<Vec<models::MarketSearchResponseInner>>> {
        self.market_data_api_client.market_search(params).await
    }

    /// Query Last Trade Price
    ///
    /// Get the most recent trade price for a prediction market.
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryLastTradePriceParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryLastTradePriceResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#query-last-trade-price).
    ///
    pub async fn query_last_trade_price(
        &self,
        params: QueryLastTradePriceParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryLastTradePriceResponse>> {
        self.market_data_api_client
            .query_last_trade_price(params)
            .await
    }

    /// Query Order Book
    ///
    /// Get the current order book (bids and asks) for a specific prediction market outcome token.
    ///
    /// Weight(IP): 200
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryOrderBookParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryOrderBookResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/market-data#query-order-book).
    ///
    pub async fn query_order_book(
        &self,
        params: QueryOrderBookParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryOrderBookResponse>> {
        self.market_data_api_client.query_order_book(params).await
    }

    /// Get Position by Token
    ///
    /// Get the authenticated user's position detail for a specific prediction token.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPositionByTokenParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetPositionByTokenResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/position#get-position-by-token).
    ///
    pub async fn get_position_by_token(
        &self,
        params: GetPositionByTokenParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPositionByTokenResponse>> {
        self.position_api_client.get_position_by_token(params).await
    }

    /// Query `PnL`
    ///
    /// Query profit and loss records for the authenticated user's prediction positions. When `tokenId` is provided, returns a single record in `pnl`; otherwise returns a list in `pnlList`.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPnLParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPnLResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/position#query-pn-l).
    ///
    pub async fn query_pn_l(
        &self,
        params: QueryPnLParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPnLResponse>> {
        self.position_api_client.query_pn_l(params).await
    }

    /// Query Positions
    ///
    /// Get the authenticated user's prediction token positions with portfolio summary and tab-based filtering.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPositionsParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPositionsResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/position#query-positions).
    ///
    pub async fn query_positions(
        &self,
        params: QueryPositionsParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPositionsResponse>> {
        self.position_api_client.query_positions(params).await
    }

    /// Query Positions by Filter
    ///
    /// Get prediction positions filtered by wallet address and/or market topic ID. Both parameters are optional.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPositionsByFilterParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPositionsByFilterResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/position#query-positions-by-filter).
    ///
    pub async fn query_positions_by_filter(
        &self,
        params: QueryPositionsByFilterParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPositionsByFilterResponse>> {
        self.position_api_client
            .query_positions_by_filter(params)
            .await
    }

    /// Query Settled Position History
    ///
    /// Get the authenticated user's settled (resolved) prediction position history with optional filters.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QuerySettledPositionHistoryParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QuerySettledPositionHistoryResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/position#query-settled-position-history).
    ///
    pub async fn query_settled_position_history(
        &self,
        params: QuerySettledPositionHistoryParams,
    ) -> anyhow::Result<RestApiResponse<models::QuerySettledPositionHistoryResponse>> {
        self.position_api_client
            .query_settled_position_history(params)
            .await
    }

    /// Batch Redeem
    ///
    /// Redeem one or more settled prediction tokens on-chain to claim winnings. Requires SAS authorization.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// # Arguments
    ///
    /// - `params`: [`BatchRedeemParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::BatchRedeemResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/redeem#batch-redeem).
    ///
    pub async fn batch_redeem(
        &self,
        params: BatchRedeemParams,
    ) -> anyhow::Result<RestApiResponse<models::BatchRedeemResponse>> {
        self.redeem_api_client.batch_redeem(params).await
    }

    /// Get Redeem Status
    ///
    /// Query the on-chain transaction status of a previously submitted redeem request.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// Response Notes:
    /// - Status values:
    ///
    /// | Value       | Description                                  |
    /// | ----------- | -------------------------------------------- |
    /// | `PENDING`   | Transaction submitted, awaiting confirmation |
    /// | `CONFIRMED` | Transaction confirmed on-chain               |
    /// | `FAILED`    | Transaction failed                           |
    /// | `NOT_FOUND` | Transaction hash not found                   |
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetRedeemStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetRedeemStatusResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/redeem#get-redeem-status).
    ///
    pub async fn get_redeem_status(
        &self,
        params: GetRedeemStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetRedeemStatusResponse>> {
        self.redeem_api_client.get_redeem_status(params).await
    }

    /// Batch Cancel Orders
    ///
    /// Cancel one or more active prediction orders in a single request. Requires SAS authorization.
    ///
    /// **Known Issue — Bracket Encoding Incompatibility:**
    /// This endpoint uses indexed bracket notation (`cancelInfoList[0].orderId`). Binance SAPI signature verification runs over the **raw, unencoded** canonical string. However, mainstream HTTP libraries (Python `requests`, Java `HttpURLConnection`/`URI`, Go `net/url`, Node.js `url`) automatically percent-encode `[` → `%5B` and `]` → `%5D`, producing a signature mismatch with error `-1022 Signature for this request is not valid`. Postman is unaffected because it does not encode keys.
    ///
    /// **Workarounds** (use low-level HTTP APIs that do not normalize URLs):
    /// - **Python:** use `http.client` (stdlib) and hand-build the body string.
    /// - **Java:** use `HttpURLConnection` and write the raw body bytes directly.
    /// - **Go:** use `strings.NewReader` with a hand-built body instead of `url.Values.Encode()`.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// Notes:
    /// - Use dot notation for nested list fields: `cancelInfoList[0].orderId`, `cancelInfoList[1].orderId`, etc.
    /// - `vendor` does not need to be supplied. The server automatically sets the correct vendor (`predict_fun`) for every item in the batch.
    ///
    /// # Arguments
    ///
    /// - `params`: [`BatchCancelOrdersParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::BatchCancelOrdersResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/trade#batch-cancel-orders).
    ///
    pub async fn batch_cancel_orders(
        &self,
        params: BatchCancelOrdersParams,
    ) -> anyhow::Result<RestApiResponse<models::BatchCancelOrdersResponse>> {
        self.trade_api_client.batch_cancel_orders(params).await
    }

    /// Get Quote
    ///
    /// Get a price quote for a prediction order. The returned `quoteId` must be used in the subsequent Place Order request.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// Response Notes:
    /// - `feeAmount` is a string because it is denominated in wei (18 decimals) and may exceed JavaScript's safe integer range. `feeDiscountBps` is also a string to allow fractional basis-point values in the future. `feeRateBps` and `slippageBps` are integers and will never exceed safe integer bounds.
    /// - **MARKET order minimum amount:** For `MARKET` orders, `amountIn` must be at least approximately **1.5 USDT** (in wei: `1500000000000000000`). The exact minimum varies by market liquidity. If the amount is too small, the server returns `-9000 Your order amount is too small`. This limit does **not** apply to `LIMIT` orders.
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetQuoteParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetQuoteResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/trade#get-quote).
    ///
    pub async fn get_quote(
        &self,
        params: GetQuoteParams,
    ) -> anyhow::Result<RestApiResponse<models::GetQuoteResponse>> {
        self.trade_api_client.get_quote(params).await
    }

    /// Place Order
    ///
    /// Place a prediction order using a previously obtained quote. Requires SAS authorization.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// Notes:
    /// - Validation rules:
    ///
    /// | orderType | timeInForce   | priceLimit            |
    /// | --------- | ------------- | --------------------- |
    /// | `MARKET`  | Must be `FOK` | Not required          |
    /// | `LIMIT`   | Must be `GTC` | Required, must be > 0 |
    ///
    /// # Arguments
    ///
    /// - `params`: [`PlaceOrderParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::PlaceOrderResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/trade#place-order).
    ///
    pub async fn place_order(
        &self,
        params: PlaceOrderParams,
    ) -> anyhow::Result<RestApiResponse<models::PlaceOrderResponse>> {
        self.trade_api_client.place_order(params).await
    }

    /// Query Active Orders
    ///
    /// Get active (open) prediction orders for the authenticated user.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryActiveOrdersParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryActiveOrdersResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/trade#query-active-orders).
    ///
    pub async fn query_active_orders(
        &self,
        params: QueryActiveOrdersParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryActiveOrdersResponse>> {
        self.trade_api_client.query_active_orders(params).await
    }

    /// Query Order History
    ///
    /// Get historical prediction orders (all statuses) for the authenticated user, with optional filters.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryOrderHistoryParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryOrderHistoryResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/trade#query-order-history).
    ///
    pub async fn query_order_history(
        &self,
        params: QueryOrderHistoryParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryOrderHistoryResponse>> {
        self.trade_api_client.query_order_history(params).await
    }

    /// Create Inbound Transfer
    ///
    /// Transfer funds from the prediction wallet back to the user's CEX account (SPOT or FUNDING). Requires SAS authorization.
    ///
    /// ⚠️ **SAS Authorization Required:** This endpoint enforces SAS (Self-Authorization Service) authorization. If SAS is not enabled for the wallet, the request will be rejected with `-31003 SAS authorization required`. Enable SAS for your wallet before calling this endpoint.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// # Arguments
    ///
    /// - `params`: [`CreateInboundTransferParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::CreateInboundTransferResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/transfer#create-inbound-transfer).
    ///
    pub async fn create_inbound_transfer(
        &self,
        params: CreateInboundTransferParams,
    ) -> anyhow::Result<RestApiResponse<models::CreateInboundTransferResponse>> {
        self.transfer_api_client
            .create_inbound_transfer(params)
            .await
    }

    /// Create Outbound Transfer
    ///
    /// Transfer funds from the user's CEX account (SPOT or FUNDING) into the prediction wallet. Requires SAS authorization.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: TRADE
    ///
    /// # Arguments
    ///
    /// - `params`: [`CreateOutboundTransferParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::CreateOutboundTransferResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/transfer#create-outbound-transfer).
    ///
    pub async fn create_outbound_transfer(
        &self,
        params: CreateOutboundTransferParams,
    ) -> anyhow::Result<RestApiResponse<models::CreateOutboundTransferResponse>> {
        self.transfer_api_client
            .create_outbound_transfer(params)
            .await
    }

    /// Query Transfer List
    ///
    /// Get the authenticated user's prediction wallet transfer history within a date range.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryTransferListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryTransferListResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/transfer#query-transfer-list).
    ///
    pub async fn query_transfer_list(
        &self,
        params: QueryTransferListParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryTransferListResponse>> {
        self.transfer_api_client.query_transfer_list(params).await
    }

    /// Query Transfer Status
    ///
    /// Query the current status of a prediction wallet transfer by transfer ID.
    ///
    /// **`status` values:** Terminal states are `COMPLETED` and `FAILED`. Intermediate states are `PROCESSING` and `PENDING`. **Do not** poll for `SUCCESS` — it is not a valid terminal state.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryTransferStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryTransferStatusResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/transfer#query-transfer-status).
    ///
    pub async fn query_transfer_status(
        &self,
        params: QueryTransferStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryTransferStatusResponse>> {
        self.transfer_api_client.query_transfer_status(params).await
    }

    /// Get Portfolio
    ///
    /// Get the authenticated user's prediction portfolio overview including active positions count, aggregated `PnL`, and full position list.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetPortfolioParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetPortfolioResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/wallet#get-portfolio).
    ///
    pub async fn get_portfolio(
        &self,
        params: GetPortfolioParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPortfolioResponse>> {
        self.wallet_api_client.get_portfolio(params).await
    }

    /// Get Quota Status
    ///
    /// Query the current user's daily trading quota limit and remaining allowance for prediction markets.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`GetQuotaStatusParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::GetQuotaStatusResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/wallet#get-quota-status).
    ///
    pub async fn get_quota_status(
        &self,
        params: GetQuotaStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetQuotaStatusResponse>> {
        self.wallet_api_client.get_quota_status(params).await
    }

    /// List Prediction Wallets
    ///
    /// Get all prediction wallets registered for the authenticated user.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`ListPredictionWalletsParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::ListPredictionWalletsResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/wallet#list-prediction-wallets).
    ///
    pub async fn list_prediction_wallets(
        &self,
        params: ListPredictionWalletsParams,
    ) -> anyhow::Result<RestApiResponse<models::ListPredictionWalletsResponse>> {
        self.wallet_api_client.list_prediction_wallets(params).await
    }

    /// Query Payment Option Balances
    ///
    /// Get available balances for each payment option that can be used for prediction trading.
    ///
    /// Weight(IP): 200
    ///
    /// Security Type: `USER_DATA`
    ///
    /// # Arguments
    ///
    /// - `params`: [`QueryPaymentOptionBalancesParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::QueryPaymentOptionBalancesResponse>`] 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/dev-docs/catalog/web3-wallet-prediction-trading/api/rest-api/wallet#query-payment-option-balances).
    ///
    pub async fn query_payment_option_balances(
        &self,
        params: QueryPaymentOptionBalancesParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPaymentOptionBalancesResponse>> {
        self.wallet_api_client
            .query_payment_option_balances(params)
            .await
    }
}
