"""
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,
        )

