"""
Binance Derivatives Trading USDS Futures REST API

OpenAPI Specification for the Binance Derivatives Trading USDS Futures 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 List, 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 AccountTradeListResponse
from ..models import AllOrdersResponse
from ..models import AutoCancelAllOpenOrdersResponse
from ..models import CancelAlgoOrderResponse
from ..models import CancelAllAlgoOpenOrdersResponse
from ..models import CancelAllOpenOrdersResponse
from ..models import CancelMultipleOrdersResponse
from ..models import CancelOrderResponse
from ..models import ChangeInitialLeverageResponse
from ..models import ChangeMarginTypeResponse
from ..models import ChangeMultiAssetsModeResponse
from ..models import ChangePositionModeResponse
from ..models import CurrentAllAlgoOpenOrdersResponse
from ..models import CurrentAllOpenOrdersResponse
from ..models import FuturesTradfiPerpsContractResponse
from ..models import GetOrderModifyHistoryResponse
from ..models import GetPositionMarginChangeHistoryResponse
from ..models import ModifyIsolatedPositionMarginResponse
from ..models import ModifyMultipleOrdersResponse
from ..models import ModifyOrderResponse
from ..models import NewAlgoOrderResponse
from ..models import NewOrderResponse
from ..models import PlaceMultipleOrdersResponse
from ..models import PositionAdlQuantileEstimationResponse
from ..models import PositionInformationV2Response
from ..models import PositionInformationV3Response
from ..models import QueryAlgoOrderResponse
from ..models import QueryAllAlgoOrdersResponse
from ..models import QueryCurrentOpenOrderResponse
from ..models import QueryOrderResponse
from ..models import TestOrderResponse
from ..models import UsersForceOrdersResponse


from ..models import ChangeMarginTypeMarginTypeEnum
from ..models import ModifyIsolatedPositionMarginPositionSideEnum
from ..models import ModifyOrderSideEnum
from ..models import ModifyOrderPriceMatchEnum
from ..models import NewAlgoOrderSideEnum
from ..models import NewAlgoOrderPositionSideEnum
from ..models import NewAlgoOrderTimeInForceEnum
from ..models import NewAlgoOrderWorkingTypeEnum
from ..models import NewAlgoOrderPriceMatchEnum
from ..models import NewAlgoOrderSelfTradePreventionModeEnum
from ..models import NewOrderSideEnum
from ..models import NewOrderPositionSideEnum
from ..models import NewOrderTimeInForceEnum
from ..models import NewOrderNewOrderRespTypeEnum
from ..models import NewOrderPriceMatchEnum
from ..models import NewOrderSelfTradePreventionModeEnum
from ..models import TestOrderSideEnum
from ..models import TestOrderPositionSideEnum
from ..models import TestOrderTimeInForceEnum
from ..models import TestOrderWorkingTypeEnum
from ..models import TestOrderNewOrderRespTypeEnum
from ..models import TestOrderPriceMatchEnum
from ..models import TestOrderSelfTradePreventionModeEnum
from ..models import UsersForceOrdersAutoCloseTypeEnum


from ..models import ModifyMultipleOrdersBatchOrdersParameterInner
from ..models import PlaceMultipleOrdersBatchOrdersParameterInner


class TradeApi:
    """API Client for TradeApi 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_trade_list(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        from_id: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AccountTradeListResponse]:
        """
                Account Trade List (USER_DATA)
                GET /fapi/v1/userTrades
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List

                Get trades for a specific account and symbol.

        * If `startTime` and `endTime` are both not sent, then the last 7 days' data will be returned.
        * The time between `startTime` and `endTime` cannot be longer than 7 days.
        * The parameter `fromId` cannot be sent with `startTime` or `endTime`.
        * Only support querying trade in the past 6 months

        Weight: 5

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    from_id (Optional[int] = None): ID to get aggregate trades from INCLUSIVE.
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[AccountTradeListResponse]

                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,
            "order_id": order_id,
            "start_time": start_time,
            "end_time": end_time,
            "from_id": from_id,
            "limit": limit,
            "recv_window": recv_window,
        }

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

    def all_orders(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AllOrdersResponse]:
        """
                All Orders (USER_DATA)
                GET /fapi/v1/allOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders

                Get all account orders; active, canceled, or filled.

        * These orders will not be found:
        * order status is `CANCELED` or `EXPIRED` **AND** order has NO filled trade **AND** created time + 3 days < current time
        * order create time + 90 days < current time

        * If `orderId` is set, it will get orders >= that `orderId`. Otherwise most recent orders are returned.
        * The query time period must be less then 7 days( default as the recent 7 days).

        Weight: 5

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[AllOrdersResponse]

                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,
            "order_id": order_id,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
            "recv_window": recv_window,
        }

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

    def auto_cancel_all_open_orders(
        self,
        symbol: Union[str, None],
        countdown_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AutoCancelAllOpenOrdersResponse]:
        """
                Auto-Cancel All Open Orders (TRADE)
                POST /fapi/v1/countdownCancelAll
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders

                Cancel all open orders of the specified symbol at the end of the specified countdown.
        The endpoint should be called repeatedly as heartbeats so that the existing countdown time can be canceled and replaced by a new one.

        * Example usage:
        Call this endpoint at 30s intervals with an countdownTime of 120000 (120s).
        If this endpoint is not called within 120 seconds, all your orders of the specified symbol will be automatically canceled.
        If this endpoint is called with an countdownTime of 0, the countdown timer will be stopped.

        The system will check all countdowns **approximately every 10 milliseconds**, so please note that sufficient redundancy should be considered when using this function. We do not recommend setting the countdown time to be too precise or too small.

        Weight: 10

                Args:
                    symbol (Union[str, None]):
                    countdown_time (Union[int, None]): countdown time, 1000 for 1 second. 0 to cancel the timer
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[AutoCancelAllOpenOrdersResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/fapi/v1/countdownCancelAll",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AutoCancelAllOpenOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cancel_algo_order(
        self,
        algoid: Optional[int] = None,
        clientalgoid: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CancelAlgoOrderResponse]:
        """
                Cancel Algo Order (TRADE)
                DELETE /fapi/v1/algoOrder
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Algo-Order

                Cancel an active algo order.

        * Either `algoid` or `clientalgoid` must be sent.

        Weight: 1

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

                Returns:
                    ApiResponse[CancelAlgoOrderResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "algoid": algoid,
            "clientalgoid": clientalgoid,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="DELETE",
            path="/fapi/v1/algoOrder",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CancelAlgoOrderResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cancel_all_algo_open_orders(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CancelAllAlgoOpenOrdersResponse]:
        """
                Cancel All Algo Open Orders (TRADE)
                DELETE /fapi/v1/algoOpenOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders

                Cancel All Algo Open Orders

        Weight: 1

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

                Returns:
                    ApiResponse[CancelAllAlgoOpenOrdersResponse]

                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="DELETE",
            path="/fapi/v1/algoOpenOrders",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CancelAllAlgoOpenOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cancel_all_open_orders(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CancelAllOpenOrdersResponse]:
        """
                Cancel All Open Orders (TRADE)
                DELETE /fapi/v1/allOpenOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders

                Cancel All Open Orders

        Weight: 1

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

                Returns:
                    ApiResponse[CancelAllOpenOrdersResponse]

                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="DELETE",
            path="/fapi/v1/allOpenOrders",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CancelAllOpenOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cancel_multiple_orders(
        self,
        symbol: Union[str, None],
        order_id_list: Optional[List[int]] = None,
        orig_client_order_id_list: Optional[List[str]] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CancelMultipleOrdersResponse]:
        """
                Cancel Multiple Orders (TRADE)
                DELETE /fapi/v1/batchOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Multiple-Orders

                Cancel Multiple Orders

        * Either `orderIdList` or `origClientOrderIdList ` must be sent.

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    order_id_list (Optional[List[int]] = None): max length 10 <br /> e.g. [1234567,2345678]
                    orig_client_order_id_list (Optional[List[str]] = None): max length 10<br /> e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma.
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[CancelMultipleOrdersResponse]

                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,
            "order_id_list": order_id_list,
            "orig_client_order_id_list": orig_client_order_id_list,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="DELETE",
            path="/fapi/v1/batchOrders",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CancelMultipleOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def cancel_order(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CancelOrderResponse]:
        """
                Cancel Order (TRADE)
                DELETE /fapi/v1/order
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order

                Cancel an active order.

        * Either `orderId` or `origClientOrderId` must be sent.

        Weight: 1

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

                Returns:
                    ApiResponse[CancelOrderResponse]

                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,
            "order_id": order_id,
            "orig_client_order_id": orig_client_order_id,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="DELETE",
            path="/fapi/v1/order",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CancelOrderResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_initial_leverage(
        self,
        symbol: Union[str, None],
        leverage: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeInitialLeverageResponse]:
        """
                Change Initial Leverage(TRADE)
                POST /fapi/v1/leverage
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Initial-Leverage

                Change user's initial leverage of specific symbol market.

        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[ChangeInitialLeverageResponse]

                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="/fapi/v1/leverage",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeInitialLeverageResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_margin_type(
        self,
        symbol: Union[str, None],
        margin_type: Union[ChangeMarginTypeMarginTypeEnum, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeMarginTypeResponse]:
        """
                Change Margin Type(TRADE)
                POST /fapi/v1/marginType
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Margin-Type

                Change symbol level margin type

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    margin_type (Union[ChangeMarginTypeMarginTypeEnum, None]): ISOLATED, CROSSED
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeMarginTypeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/fapi/v1/marginType",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeMarginTypeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_multi_assets_mode(
        self,
        multi_assets_margin: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeMultiAssetsModeResponse]:
        """
                Change Multi-Assets Mode (TRADE)
                POST /fapi/v1/multiAssetsMargin
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Multi-Assets-Mode

                Change user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on ***Every symbol***

        Weight: 1

                Args:
                    multi_assets_margin (Union[str, None]): "true": Multi-Assets Mode; "false": Single-Asset Mode
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[ChangeMultiAssetsModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/fapi/v1/multiAssetsMargin",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeMultiAssetsModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def change_position_mode(
        self,
        dual_side_position: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangePositionModeResponse]:
        """
                Change Position Mode(TRADE)
                POST /fapi/v1/positionSide/dual
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Position-Mode

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

        Weight: 1

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

                Returns:
                    ApiResponse[ChangePositionModeResponse]

                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="/fapi/v1/positionSide/dual",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangePositionModeResponse,
            is_signed=True,
            signer=self._signer,
        )

    def current_all_algo_open_orders(
        self,
        algo_type: Optional[str] = None,
        symbol: Optional[str] = None,
        algo_id: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CurrentAllAlgoOpenOrdersResponse]:
        """
                Current All Algo Open Orders (USER_DATA)
                GET /fapi/v1/openAlgoOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Algo-Open-Orders

                Get all algo open orders on a symbol.

        * If the symbol is not sent, orders for all symbols will be returned in an array.

        Weight: 1 for a single symbol; 40 when the symbol parameter is omitted
        Careful when accessing this with no symbol.

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

                Returns:
                    ApiResponse[CurrentAllAlgoOpenOrdersResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def current_all_open_orders(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CurrentAllOpenOrdersResponse]:
        """
                Current All Open Orders (USER_DATA)
                GET /fapi/v1/openOrders
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders

                Get all open orders on a symbol.

        * If the symbol is not sent, orders for all symbols will be returned in an array.

        Weight: 1 for a single symbol; 40 when the symbol parameter is omitted
        Careful when accessing this with no symbol.

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

                Returns:
                    ApiResponse[CurrentAllOpenOrdersResponse]

                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="/fapi/v1/openOrders",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CurrentAllOpenOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def futures_tradfi_perps_contract(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[FuturesTradfiPerpsContractResponse]:
        """
                Futures TradFi Perps Contract(USER_DATA)
                POST /fapi/v1/stock/contract
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Futures-TradFi-Perps-Contract

                Sign TradFi-Perps agreement contract

        Weight: 0

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

                Returns:
                    ApiResponse[FuturesTradfiPerpsContractResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/fapi/v1/stock/contract",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=FuturesTradfiPerpsContractResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_order_modify_history(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetOrderModifyHistoryResponse]:
        """
                Get Order Modify History (USER_DATA)
                GET /fapi/v1/orderAmendment
                https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Order-Modify-History

                Get order modification history

        * Either `orderId` or `origClientOrderId` must be sent, and the `orderId` will prevail if both are sent.
        * Order modify history longer than 3 month is not avaliable

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    orig_client_order_id (Optional[str] = None):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetOrderModifyHistoryResponse]

                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,
            "order_id": order_id,
            "orig_client_order_id": orig_client_order_id,
            "start_time": start_time,
