"""
Binance Derivatives Trading Portfolio Margin REST API

OpenAPI Specification for the Binance Derivatives Trading Portfolio Margin REST API
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from typing import Optional, Union
from requests import Session
from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.models import ApiResponse
from binance_common.signature import Signers
from binance_common.utils import send_request

from ..models import AccountBalanceResponse
from ..models import AccountInformationResponse
from ..models import BnbTransferResponse
from ..models import ChangeAutoRepayFuturesStatusResponse
from ..models import ChangeCmInitialLeverageResponse
from ..models import ChangeCmPositionModeResponse
from ..models import ChangeUmInitialLeverageResponse
from ..models import ChangeUmPositionModeResponse
from ..models import CmNotionalAndLeverageBracketsResponse
from ..models import FundAutoCollectionResponse
from ..models import FundCollectionByAssetResponse
from ..models import GetAutoRepayFuturesStatusResponse
from ..models import GetCmAccountDetailResponse
from ..models import GetCmCurrentPositionModeResponse
from ..models import GetCmIncomeHistoryResponse
from ..models import GetDownloadIdForUmFuturesOrderHistoryResponse
from ..models import GetDownloadIdForUmFuturesTradeHistoryResponse
from ..models import GetDownloadIdForUmFuturesTransactionHistoryResponse
from ..models import GetMarginBorrowLoanInterestHistoryResponse
from ..models import GetUmAccountDetailResponse
from ..models import GetUmAccountDetailV2Response
from ..models import GetUmCurrentPositionModeResponse
from ..models import GetUmFuturesOrderDownloadLinkByIdResponse
from ..models import GetUmFuturesTradeDownloadLinkByIdResponse
from ..models import GetUmFuturesTransactionDownloadLinkByIdResponse
from ..models import GetUmIncomeHistoryResponse
from ..models import GetUserCommissionRateForCmResponse
from ..models import GetUserCommissionRateForUmResponse
from ..models import MarginMaxBorrowResponse
from ..models import PortfolioMarginUmTradingQuantitativeRulesIndicatorsResponse
from ..models import QueryCmPositionInformationResponse
from ..models import QueryMarginLoanRecordResponse
from ..models import QueryMarginMaxWithdrawResponse
from ..models import QueryMarginRepayRecordResponse
from ..models import QueryPortfolioMarginNegativeBalanceInterestHistoryResponse
from ..models import QueryUmPositionInformationResponse
from ..models import QueryUserNegativeBalanceAutoExchangeRecordResponse
from ..models import QueryUserRateLimitResponse
from ..models import RepayFuturesNegativeBalanceResponse
from ..models import UmFuturesAccountConfigurationResponse
from ..models import UmFuturesSymbolConfigurationResponse
from ..models import UmNotionalAndLeverageBracketsResponse


class AccountApi:
    """API Client for AccountApi endpoints."""

    def __init__(
        self,
        configuration: ConfigurationRestAPI = None,
        session: Session = None,
        signer: Signers = None,
    ) -> None:
        self._configuration = configuration
        self._session = session
        self._signer = signer

    def account_balance(
        self,
        asset: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AccountBalanceResponse]:
        """
                Account Balance(USER_DATA)
                GET /papi/v1/balance
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Balance

                Query account balance

        Weight: 20

                Args:
                    asset (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[AccountBalanceResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"asset": asset, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/balance",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AccountBalanceResponse,
            is_signed=True,
            signer=self._signer,
        )

    def account_information(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AccountInformationResponse]:
        """
                Account Information(USER_DATA)
                GET /papi/v1/account
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Information

                Query account information

        Weight: 20

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[AccountInformationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AccountInformationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def bnb_transfer(
        self,
        amount: Union[float, None],
        transfer_side: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[BnbTransferResponse]:
        """
                BNB transfer (TRADE)
                POST /papi/v1/bnb-transfer
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/BNB-transfer

                Transfer BNB in and out of UM

        * The endpoint can only be called 10 times per 10 minutes in a rolling manner

        Weight: 750

                Args:
                    amount (Union[float, None]):
                    transfer_side (Union[str, None]): "TO_UM","FROM_UM"
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[BnbTransferResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if amount is None:
            raise RequiredError(
                field="amount", error_message="Missing required parameter 'amount'"
            )
        if transfer_side is None:
            raise RequiredError(
                field="transfer_side",
                error_message="Missing required parameter 'transfer_side'",
            )

        body = {}
        payload = {
            "amount": amount,
            "transfer_side": transfer_side,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/bnb-transfer",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=BnbTransferResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_auto_repay_futures_status(
        self,
        auto_repay: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeAutoRepayFuturesStatusResponse]:
        """
                Change Auto-repay-futures Status(TRADE)
                POST /papi/v1/repay-futures-switch
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-Auto-repay-futures-Status

                Change Auto-repay-futures Status

        Weight: 750

                Args:
                    auto_repay (Union[str, None]): Default: `true`; `false` for turn off the auto-repay futures negative balance function
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeAutoRepayFuturesStatusResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if auto_repay is None:
            raise RequiredError(
                field="auto_repay",
                error_message="Missing required parameter 'auto_repay'",
            )

        body = {}
        payload = {"auto_repay": auto_repay, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/repay-futures-switch",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeAutoRepayFuturesStatusResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_cm_initial_leverage(
        self,
        symbol: Union[str, None],
        leverage: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeCmInitialLeverageResponse]:
        """
                Change CM Initial Leverage (TRADE)
                POST /papi/v1/cm/leverage
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Initial-Leverage

                Change user's initial leverage of specific symbol in CM.

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    leverage (Union[int, None]): target initial leverage: int from 1 to 125
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeCmInitialLeverageResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if symbol is None:
            raise RequiredError(
                field="symbol", error_message="Missing required parameter 'symbol'"
            )
        if leverage is None:
            raise RequiredError(
                field="leverage", error_message="Missing required parameter 'leverage'"
            )

        body = {}
        payload = {"symbol": symbol, "leverage": leverage, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/cm/leverage",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeCmInitialLeverageResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_cm_position_mode(
        self,
        dual_side_position: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeCmPositionModeResponse]:
        """
                Change CM Position Mode(TRADE)
                POST /papi/v1/cm/positionSide/dual
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Position-Mode

                Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM

        Weight: 1

                Args:
                    dual_side_position (Union[str, None]): "true": Hedge Mode; "false": One-way Mode
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeCmPositionModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if dual_side_position is None:
            raise RequiredError(
                field="dual_side_position",
                error_message="Missing required parameter 'dual_side_position'",
            )

        body = {}
        payload = {"dual_side_position": dual_side_position, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/cm/positionSide/dual",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeCmPositionModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_um_initial_leverage(
        self,
        symbol: Union[str, None],
        leverage: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeUmInitialLeverageResponse]:
        """
                Change UM Initial Leverage(TRADE)
                POST /papi/v1/um/leverage
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Initial-Leverage

                Change user's initial leverage of specific symbol in UM.

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    leverage (Union[int, None]): target initial leverage: int from 1 to 125
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeUmInitialLeverageResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if symbol is None:
            raise RequiredError(
                field="symbol", error_message="Missing required parameter 'symbol'"
            )
        if leverage is None:
            raise RequiredError(
                field="leverage", error_message="Missing required parameter 'leverage'"
            )

        body = {}
        payload = {"symbol": symbol, "leverage": leverage, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/um/leverage",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeUmInitialLeverageResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_um_position_mode(
        self,
        dual_side_position: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeUmPositionModeResponse]:
        """
                Change UM Position Mode(TRADE)
                POST /papi/v1/um/positionSide/dual
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Position-Mode

                Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM

        Weight: 1

                Args:
                    dual_side_position (Union[str, None]): "true": Hedge Mode; "false": One-way Mode
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeUmPositionModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if dual_side_position is None:
            raise RequiredError(
                field="dual_side_position",
                error_message="Missing required parameter 'dual_side_position'",
            )

        body = {}
        payload = {"dual_side_position": dual_side_position, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/um/positionSide/dual",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeUmPositionModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cm_notional_and_leverage_brackets(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CmNotionalAndLeverageBracketsResponse]:
        """
                CM Notional and Leverage Brackets(USER_DATA)
                GET /papi/v1/cm/leverageBracket
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/CM-Notional-and-Leverage-Brackets

                Query CM notional and leverage brackets

        Weight: 1

                Args:
                    symbol (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[CmNotionalAndLeverageBracketsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/leverageBracket",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CmNotionalAndLeverageBracketsResponse,
            is_signed=True,
            signer=self._signer,
        )

    def fund_auto_collection(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[FundAutoCollectionResponse]:
        """
                Fund Auto-collection(TRADE)
                POST /papi/v1/auto-collection
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Auto-collection

                Fund collection for Portfolio Margin

        * 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: 750

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[FundAutoCollectionResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/auto-collection",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=FundAutoCollectionResponse,
            is_signed=True,
            signer=self._signer,
        )

    def fund_collection_by_asset(
        self,
        asset: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[FundCollectionByAssetResponse]:
        """
                Fund Collection by Asset(TRADE)
                POST /papi/v1/asset-collection
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Collection-by-Asset

                Transfers specific asset from Futures Account to Margin account

        * The BNB transfer is not be supported

        Weight: 30

                Args:
                    asset (Union[str, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[FundCollectionByAssetResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )

        body = {}
        payload = {"asset": asset, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/asset-collection",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=FundCollectionByAssetResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_auto_repay_futures_status(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetAutoRepayFuturesStatusResponse]:
        """
                Get Auto-repay-futures Status(USER_DATA)
                GET /papi/v1/repay-futures-switch
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Auto-repay-futures-Status

                Query Auto-repay-futures Status

        Weight: 30

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetAutoRepayFuturesStatusResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/repay-futures-switch",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetAutoRepayFuturesStatusResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_cm_account_detail(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetCmAccountDetailResponse]:
        """
                Get CM Account Detail(USER_DATA)
                GET /papi/v1/cm/account
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Account-Detail

                Get current CM account asset and position information.

        Weight: 5

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetCmAccountDetailResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetCmAccountDetailResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_cm_current_position_mode(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetCmCurrentPositionModeResponse]:
        """
                Get CM Current Position Mode(USER_DATA)
                GET /papi/v1/cm/positionSide/dual
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Current-Position-Mode

                Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM

        Weight: 30

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetCmCurrentPositionModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/positionSide/dual",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetCmCurrentPositionModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_cm_income_history(
        self,
        symbol: Optional[str] = None,
        income_type: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        page: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetCmIncomeHistoryResponse]:
        """
                Get CM Income History(USER_DATA)
                GET /papi/v1/cm/income
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History

                Get CM Income History


        * If `incomeType` is not sent, all kinds of flow will be returned
        * "trandId" is unique in the same "incomeType" for a user
        * The interval between `startTime` and `endTime` can not exceed 200 days:
        * If `startTime` and `endTime` are not sent, the last 200 days will be returned

        Weight: 30

                Args:
                    symbol (Optional[str] = None):
                    income_type (Optional[str] = None): TRANSFER, WELCOME_BONUS, REALIZED_PNL, FUNDING_FEE, COMMISSION, INSURANCE_CLEAR, REFERRAL_KICKBACK, COMMISSION_REBATE, API_REBATE, CONTEST_REWARD, CROSS_COLLATERAL_TRANSFER, OPTIONS_PREMIUM_FEE, OPTIONS_SETTLE_PROFIT, INTERNAL_TRANSFER, AUTO_EXCHANGE, DELIVERED_SETTELMENT, COIN_SWAP_DEPOSIT, COIN_SWAP_WITHDRAW, POSITION_LIMIT_INCREASE_FEE
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    page (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetCmIncomeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "symbol": symbol,
            "income_type": income_type,
            "start_time": start_time,
            "end_time": end_time,
            "page": page,
            "limit": limit,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/income",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetCmIncomeHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_download_id_for_um_futures_order_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForUmFuturesOrderHistoryResponse]:
        """
                Get Download Id For UM Futures Order History (USER_DATA)
                GET /papi/v1/um/order/asyn
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Order-History

                Get download id for UM futures order history

        * Request Limitation is 10 times per month, shared by front end download page and rest api
        * The time between `startTime` and `endTime` can not be longer than 1 year

        Weight: 1500

                Args:
                    start_time (Union[int, None]):
                    end_time (Union[int, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetDownloadIdForUmFuturesOrderHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if start_time is None:
            raise RequiredError(
                field="start_time",
                error_message="Missing required parameter 'start_time'",
            )
        if end_time is None:
            raise RequiredError(
                field="end_time", error_message="Missing required parameter 'end_time'"
            )

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/order/asyn",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetDownloadIdForUmFuturesOrderHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_download_id_for_um_futures_trade_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForUmFuturesTradeHistoryResponse]:
        """
                Get Download Id For UM Futures Trade History (USER_DATA)
                GET /papi/v1/um/trade/asyn
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Trade-History

                Get download id for UM futures trade history

        * Request Limitation is 5 times per month, shared by front end download page and rest api
        * The time between `startTime` and `endTime` can not be longer than 1 year

        Weight: 1500

                Args:
                    start_time (Union[int, None]):
                    end_time (Union[int, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetDownloadIdForUmFuturesTradeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if start_time is None:
            raise RequiredError(
                field="start_time",
                error_message="Missing required parameter 'start_time'",
            )
        if end_time is None:
            raise RequiredError(
                field="end_time", error_message="Missing required parameter 'end_time'"
            )

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/trade/asyn",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetDownloadIdForUmFuturesTradeHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_download_id_for_um_futures_transaction_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForUmFuturesTransactionHistoryResponse]:
        """
                Get Download Id For UM Futures Transaction History (USER_DATA)
                GET /papi/v1/um/income/asyn
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Transaction-History

                Get download id for UM futures transaction history

        * Request Limitation is 5 times per month, shared by front end download page and rest api
        * The time between `startTime` and `endTime` can not be longer than 1 year

        Weight: 1500

                Args:
                    start_time (Union[int, None]):
                    end_time (Union[int, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetDownloadIdForUmFuturesTransactionHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if start_time is None:
            raise RequiredError(
                field="start_time",
                error_message="Missing required parameter 'start_time'",
            )
        if end_time is None:
            raise RequiredError(
                field="end_time", error_message="Missing required parameter 'end_time'"
            )

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/income/asyn",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetDownloadIdForUmFuturesTransactionHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_margin_borrow_loan_interest_history(
        self,
        asset: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        archived: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetMarginBorrowLoanInterestHistoryResponse]:
        """
                Get Margin Borrow/Loan Interest History(USER_DATA)
                GET /papi/v1/margin/marginInterestHistory
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Margin-BorrowLoan-Interest-History

                Get Margin Borrow/Loan Interest History


        * Response in descending order
        * 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, the records from `startTime` to the present will be returned; if `startTime` is more than 30 days ago, the records of the past 30 days will be returned.
        * If `startTime` is not sent and `endTime` is sent, the records of the 7 days before `endTime` is returned.
        * Type in response has 5 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` Portfolio Margin negative balance daily interest

        Weight: 1

                Args:
                    asset (Optional[str] = None):
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    current (Optional[int] = None): Currently querying page. Start from 1. Default:1
                    size (Optional[int] = None): Default:10 Max:100
                    archived (Optional[str] = None): Default: `false`. Set to `true` for archived data from 6 months ago
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetMarginBorrowLoanInterestHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "asset": asset,
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "archived": archived,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/margin/marginInterestHistory",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetMarginBorrowLoanInterestHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_account_detail(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmAccountDetailResponse]:
        """
                Get UM Account Detail(USER_DATA)
                GET /papi/v1/um/account
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail

                Get current UM account asset and position information.

        Weight: 5

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmAccountDetailResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmAccountDetailResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_account_detail_v2(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmAccountDetailV2Response]:
        """
                Get UM Account Detail V2(USER_DATA)
                GET /papi/v2/um/account
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail-V2

                Get current UM account asset and position information.

        Weight: 5

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmAccountDetailV2Response]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v2/um/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmAccountDetailV2Response,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_current_position_mode(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmCurrentPositionModeResponse]:
        """
                Get UM Current Position Mode(USER_DATA)
                GET /papi/v1/um/positionSide/dual
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Current-Position-Mode

                Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM

        Weight: 30

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmCurrentPositionModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/positionSide/dual",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmCurrentPositionModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_futures_order_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmFuturesOrderDownloadLinkByIdResponse]:
        """
                Get UM Futures Order Download Link by Id(USER_DATA)
                GET /papi/v1/um/order/asyn/id
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Order-Download-Link-by-Id

                Get UM futures order download link by Id

        * Download link expiration: 24h

        Weight: 10

                Args:
                    download_id (Union[str, None]): get by download id api
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmFuturesOrderDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if download_id is None:
            raise RequiredError(
                field="download_id",
                error_message="Missing required parameter 'download_id'",
            )

        body = {}
        payload = {"download_id": download_id, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/order/asyn/id",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmFuturesOrderDownloadLinkByIdResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_futures_trade_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmFuturesTradeDownloadLinkByIdResponse]:
        """
                Get UM Futures Trade Download Link by Id(USER_DATA)
                GET /papi/v1/um/trade/asyn/id
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Trade-Download-Link-by-Id

                Get UM futures trade download link by Id

        * Download link expiration: 24h

        Weight: 10

                Args:
                    download_id (Union[str, None]): get by download id api
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmFuturesTradeDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if download_id is None:
            raise RequiredError(
                field="download_id",
                error_message="Missing required parameter 'download_id'",
            )

        body = {}
        payload = {"download_id": download_id, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/trade/asyn/id",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmFuturesTradeDownloadLinkByIdResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_futures_transaction_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmFuturesTransactionDownloadLinkByIdResponse]:
        """
                Get UM Futures Transaction Download Link by Id(USER_DATA)
                GET /papi/v1/um/income/asyn/id
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Transaction-Download-Link-by-Id

                Get UM futures Transaction download link by Id

        * Download link expiration: 24h

        Weight: 10

                Args:
                    download_id (Union[str, None]): get by download id api
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmFuturesTransactionDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if download_id is None:
            raise RequiredError(
                field="download_id",
                error_message="Missing required parameter 'download_id'",
            )

        body = {}
        payload = {"download_id": download_id, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/income/asyn/id",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmFuturesTransactionDownloadLinkByIdResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_um_income_history(
        self,
        symbol: Optional[str] = None,
        income_type: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        page: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUmIncomeHistoryResponse]:
        """
                Get UM Income History(USER_DATA)
                GET /papi/v1/um/income
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History

                Get UM Income History

        * If neither `startTime` nor `endTime` is sent, the recent 7-day data will be returned.
        * If `incomeType` is not sent, all kinds of flow will be returned
        * "trandId" is unique in the same incomeType for a user
        * Income history only contains data for the last three months

        Weight: 30

                Args:
                    symbol (Optional[str] = None):
                    income_type (Optional[str] = None): TRANSFER, WELCOME_BONUS, REALIZED_PNL, FUNDING_FEE, COMMISSION, INSURANCE_CLEAR, REFERRAL_KICKBACK, COMMISSION_REBATE, API_REBATE, CONTEST_REWARD, CROSS_COLLATERAL_TRANSFER, OPTIONS_PREMIUM_FEE, OPTIONS_SETTLE_PROFIT, INTERNAL_TRANSFER, AUTO_EXCHANGE, DELIVERED_SETTELMENT, COIN_SWAP_DEPOSIT, COIN_SWAP_WITHDRAW, POSITION_LIMIT_INCREASE_FEE
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    page (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUmIncomeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "symbol": symbol,
            "income_type": income_type,
            "start_time": start_time,
            "end_time": end_time,
            "page": page,
            "limit": limit,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/income",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUmIncomeHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_user_commission_rate_for_cm(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUserCommissionRateForCmResponse]:
        """
                Get User Commission Rate for CM(USER_DATA)
                GET /papi/v1/cm/commissionRate
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-CM

                Get User Commission Rate for CM

        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUserCommissionRateForCmResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if symbol is None:
            raise RequiredError(
                field="symbol", error_message="Missing required parameter 'symbol'"
            )

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/commissionRate",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUserCommissionRateForCmResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_user_commission_rate_for_um(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetUserCommissionRateForUmResponse]:
        """
                Get User Commission Rate for UM(USER_DATA)
                GET /papi/v1/um/commissionRate
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-UM

                Get User Commission Rate for UM

        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetUserCommissionRateForUmResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if symbol is None:
            raise RequiredError(
                field="symbol", error_message="Missing required parameter 'symbol'"
            )

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/commissionRate",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetUserCommissionRateForUmResponse,
            is_signed=True,
            signer=self._signer,
        )

    def margin_max_borrow(
        self,
        asset: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[MarginMaxBorrowResponse]:
        """
                Margin Max Borrow(USER_DATA)
                GET /papi/v1/margin/maxBorrowable
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Margin-Max-Borrow

                Query margin max borrow

        Weight: 5

                Args:
                    asset (Union[str, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[MarginMaxBorrowResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )

        body = {}
        payload = {"asset": asset, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/margin/maxBorrowable",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=MarginMaxBorrowResponse,
            is_signed=True,
            signer=self._signer,
        )

    def portfolio_margin_um_trading_quantitative_rules_indicators(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[PortfolioMarginUmTradingQuantitativeRulesIndicatorsResponse]:
        """
                Portfolio Margin UM Trading Quantitative Rules Indicators(USER_DATA)
                GET /papi/v1/um/apiTradingStatus
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Portfolio-Margin-UM-Trading-Quantitative-Rules-Indicators

                Portfolio Margin UM Trading Quantitative Rules Indicators

        Weight: 1 for a single symbol
        10 when the symbol parameter is omitted

                Args:
                    symbol (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[PortfolioMarginUmTradingQuantitativeRulesIndicatorsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/apiTradingStatus",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=PortfolioMarginUmTradingQuantitativeRulesIndicatorsResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_cm_position_information(
        self,
        margin_asset: Optional[str] = None,
        pair: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryCmPositionInformationResponse]:
        """
                Query CM Position Information(USER_DATA)
                GET /papi/v1/cm/positionRisk
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-CM-Position-Information

                Get current CM position information.

        * If neither `marginAsset` nor `pair` is sent, positions of all symbols with `TRADING` status will be returned.
        * for One-way Mode user, the response will only show the "BOTH" positions
        * for Hedge Mode user, the response will show "LONG", and "SHORT" positions.
        * Please use with user data stream `ACCOUNT_UPDATE` to meet your timeliness and accuracy needs.

        Weight: 1

                Args:
                    margin_asset (Optional[str] = None):
                    pair (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryCmPositionInformationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "margin_asset": margin_asset,
            "pair": pair,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/cm/positionRisk",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryCmPositionInformationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_margin_loan_record(
        self,
        asset: Union[str, None],
        tx_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        archived: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryMarginLoanRecordResponse]:
        """
                Query Margin Loan Record(USER_DATA)
                GET /papi/v1/margin/marginLoan
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Loan-Record

                Query margin loan record

        * txId or startTime must be sent. txId takes precedence.
        * Response in descending order
        * The max interval between `startTime` and `endTime` is 30 days.
        * If `startTime` and `endTime` not sent, return records of the last 7 days by default
        * Set `archived` to `true` to query data from 6 months ago

        Weight: 10

                Args:
                    asset (Union[str, None]):
                    tx_id (Optional[int] = None): the `tranId` in `POST/papi/v1/marginLoan`
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    current (Optional[int] = None): Currently querying page. Start from 1. Default:1
                    size (Optional[int] = None): Default:10 Max:100
                    archived (Optional[str] = None): Default: `false`. Set to `true` for archived data from 6 months ago
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryMarginLoanRecordResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )

        body = {}
        payload = {
            "asset": asset,
            "tx_id": tx_id,
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "archived": archived,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/margin/marginLoan",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryMarginLoanRecordResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_margin_max_withdraw(
        self,
        asset: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryMarginMaxWithdrawResponse]:
        """
                Query Margin Max Withdraw(USER_DATA)
                GET /papi/v1/margin/maxWithdraw
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Max-Withdraw

                Query Margin Max Withdraw

        Weight: 5

                Args:
                    asset (Union[str, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryMarginMaxWithdrawResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )

        body = {}
        payload = {"asset": asset, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/margin/maxWithdraw",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryMarginMaxWithdrawResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_margin_repay_record(
        self,
        asset: Union[str, None],
        tx_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        archived: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryMarginRepayRecordResponse]:
        """
                Query Margin repay Record(USER_DATA)
                GET /papi/v1/margin/repayLoan
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-repay-Record

                Query margin repay record.

        * txId or startTime must be sent. txId takes precedence.
        * Response in descending order
        * The max interval between `startTime` and `endTime` is 30 days.
        * If `startTime` and `endTime` not sent, return records of the last 7 days by default
        * Set `archived` to `true` to query data from 6 months ago

        Weight: 10

                Args:
                    asset (Union[str, None]):
                    tx_id (Optional[int] = None): the `tranId` in `POST/papi/v1/marginLoan`
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    current (Optional[int] = None): Currently querying page. Start from 1. Default:1
                    size (Optional[int] = None): Default:10 Max:100
                    archived (Optional[str] = None): Default: `false`. Set to `true` for archived data from 6 months ago
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryMarginRepayRecordResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )

        body = {}
        payload = {
            "asset": asset,
            "tx_id": tx_id,
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "archived": archived,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/margin/repayLoan",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryMarginRepayRecordResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_portfolio_margin_negative_balance_interest_history(
        self,
        asset: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        size: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryPortfolioMarginNegativeBalanceInterestHistoryResponse]:
        """
                Query Portfolio Margin Negative Balance Interest History(USER_DATA)
                GET /papi/v1/portfolio/interest-history
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Portfolio-Margin-Negative-Balance-Interest-History

                Query interest history of negative balance for portfolio margin.

        * Response in descending order
        * 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, the records from `startTime` to the present will be returned; if `startTime` is more than 30 days ago, the records of the past 30 days will be returned.
        * If `startTime` is not sent and `endTime` is sent, the records of the 7 days before `endTime` is returned.

        Weight: 50

                Args:
                    asset (Optional[str] = None):
                    start_time (Optional[int] = None): Timestamp in ms to get funding from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get funding until INCLUSIVE.
                    size (Optional[int] = None): Default:10 Max:100
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryPortfolioMarginNegativeBalanceInterestHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "asset": asset,
            "start_time": start_time,
            "end_time": end_time,
            "size": size,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/portfolio/interest-history",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryPortfolioMarginNegativeBalanceInterestHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_um_position_information(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryUmPositionInformationResponse]:
        """
                Query UM Position Information(USER_DATA)
                GET /papi/v1/um/positionRisk
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-UM-Position-Information

                Get current UM position information.

        * Please use with user data stream `ACCOUNT_UPDATE` to meet your timeliness and accuracy needs.
        * for One-way Mode user, the response will only show the "BOTH" positions
        * for Hedge Mode user, the response will show "LONG", and "SHORT" positions.

        Weight: 5

                Args:
                    symbol (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryUmPositionInformationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/positionRisk",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryUmPositionInformationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_user_negative_balance_auto_exchange_record(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryUserNegativeBalanceAutoExchangeRecordResponse]:
        """
                Query User Negative Balance Auto Exchange Record (USER_DATA)
                GET /papi/v1/portfolio/negative-balance-exchange-record
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Negative-Balance-Auto-Exchange-Record

                Query user negative balance auto exchange record

        * Response in descending order
        * The max interval between `startTime` and `endTime` is 3 months.

        Weight: 100

                Args:
                    start_time (Union[int, None]):
                    end_time (Union[int, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryUserNegativeBalanceAutoExchangeRecordResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if start_time is None:
            raise RequiredError(
                field="start_time",
                error_message="Missing required parameter 'start_time'",
            )
        if end_time is None:
            raise RequiredError(
                field="end_time", error_message="Missing required parameter 'end_time'"
            )

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/portfolio/negative-balance-exchange-record",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryUserNegativeBalanceAutoExchangeRecordResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_user_rate_limit(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryUserRateLimitResponse]:
        """
                Query User Rate Limit (USER_DATA)
                GET /papi/v1/rateLimit/order
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Rate-Limit

                Query User Rate Limit

        Weight: 1

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[QueryUserRateLimitResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/rateLimit/order",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryUserRateLimitResponse,
            is_signed=True,
            signer=self._signer,
        )

    def repay_futures_negative_balance(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[RepayFuturesNegativeBalanceResponse]:
        """
                Repay futures Negative Balance(USER_DATA)
                POST /papi/v1/repay-futures-negative-balance
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Repay-futures-Negative-Balance

                Repay futures Negative Balance

        Weight: 750

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[RepayFuturesNegativeBalanceResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/papi/v1/repay-futures-negative-balance",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=RepayFuturesNegativeBalanceResponse,
            is_signed=True,
            signer=self._signer,
        )

    def um_futures_account_configuration(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[UmFuturesAccountConfigurationResponse]:
        """
                UM Futures Account Configuration(USER_DATA)
                GET /papi/v1/um/accountConfig
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Account-Config

                Query UM Futures account configuration

        Weight: 5

                Args:
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[UmFuturesAccountConfigurationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/accountConfig",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=UmFuturesAccountConfigurationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def um_futures_symbol_configuration(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[UmFuturesSymbolConfigurationResponse]:
        """
                UM Futures Symbol Configuration(USER_DATA)
                GET /papi/v1/um/symbolConfig
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Symbol-Config

                Get current UM account symbol configuration.

        Weight: 5

                Args:
                    symbol (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[UmFuturesSymbolConfigurationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/symbolConfig",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=UmFuturesSymbolConfigurationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def um_notional_and_leverage_brackets(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[UmNotionalAndLeverageBracketsResponse]:
        """
                UM Notional and Leverage Brackets (USER_DATA)
                GET /papi/v1/um/leverageBracket
                https://developers.binance.com/docs/derivatives/portfolio-margin/account/UM-Notional-and-Leverage-Brackets

                Query UM notional and leverage brackets

        Weight: 1

                Args:
                    symbol (Optional[str] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[UmNotionalAndLeverageBracketsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"symbol": symbol, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/papi/v1/um/leverageBracket",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=UmNotionalAndLeverageBracketsResponse,
            is_signed=True,
            signer=self._signer,
        )
