"""
Binance Spot REST API

OpenAPI Specifications for the Binance Spot REST API

API documents:
  - [Github rest-api documentation file](https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md)
  - [General API information for rest-api on website](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information)

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 DeleteOpenOrdersResponse
from ..models import DeleteOrderResponse
from ..models import DeleteOrderListResponse
from ..models import NewOrderResponse
from ..models import OrderAmendKeepPriorityResponse
from ..models import OrderCancelReplaceResponse
from ..models import OrderListOcoResponse
from ..models import OrderListOpoResponse
from ..models import OrderListOpocoResponse
from ..models import OrderListOtoResponse
from ..models import OrderListOtocoResponse
from ..models import OrderOcoResponse
from ..models import OrderTestResponse
from ..models import SorOrderResponse
from ..models import SorOrderTestResponse


from ..models import DeleteOrderCancelRestrictionsEnum
from ..models import NewOrderSideEnum
from ..models import NewOrderTypeEnum
from ..models import NewOrderTimeInForceEnum
from ..models import NewOrderNewOrderRespTypeEnum
from ..models import NewOrderSelfTradePreventionModeEnum
from ..models import NewOrderPegPriceTypeEnum
from ..models import NewOrderPegOffsetTypeEnum
from ..models import OrderCancelReplaceSideEnum
from ..models import OrderCancelReplaceTypeEnum
from ..models import OrderCancelReplaceCancelReplaceModeEnum
from ..models import OrderCancelReplaceTimeInForceEnum
from ..models import OrderCancelReplaceNewOrderRespTypeEnum
from ..models import OrderCancelReplaceSelfTradePreventionModeEnum
from ..models import OrderCancelReplaceCancelRestrictionsEnum
from ..models import OrderCancelReplaceOrderRateLimitExceededModeEnum
from ..models import OrderCancelReplacePegPriceTypeEnum
from ..models import OrderCancelReplacePegOffsetTypeEnum
from ..models import OrderListOcoSideEnum
from ..models import OrderListOcoAboveTypeEnum
from ..models import OrderListOcoBelowTypeEnum
from ..models import OrderListOcoAboveTimeInForceEnum
from ..models import OrderListOcoAbovePegPriceTypeEnum
from ..models import OrderListOcoAbovePegOffsetTypeEnum
from ..models import OrderListOcoBelowTimeInForceEnum
from ..models import OrderListOcoBelowPegPriceTypeEnum
from ..models import OrderListOcoBelowPegOffsetTypeEnum
from ..models import OrderListOcoNewOrderRespTypeEnum
from ..models import OrderListOcoSelfTradePreventionModeEnum
from ..models import OrderListOpoWorkingTypeEnum
from ..models import OrderListOpoWorkingSideEnum
from ..models import OrderListOpoPendingTypeEnum
from ..models import OrderListOpoPendingSideEnum
from ..models import OrderListOpoNewOrderRespTypeEnum
from ..models import OrderListOpoSelfTradePreventionModeEnum
from ..models import OrderListOpoWorkingTimeInForceEnum
from ..models import OrderListOpoWorkingPegPriceTypeEnum
from ..models import OrderListOpoWorkingPegOffsetTypeEnum
from ..models import OrderListOpoPendingTimeInForceEnum
from ..models import OrderListOpoPendingPegPriceTypeEnum
from ..models import OrderListOpoPendingPegOffsetTypeEnum
from ..models import OrderListOpocoWorkingTypeEnum
from ..models import OrderListOpocoWorkingSideEnum
from ..models import OrderListOpocoPendingSideEnum
from ..models import OrderListOpocoPendingAboveTypeEnum
from ..models import OrderListOpocoNewOrderRespTypeEnum
from ..models import OrderListOpocoSelfTradePreventionModeEnum
from ..models import OrderListOpocoWorkingTimeInForceEnum
from ..models import OrderListOpocoWorkingPegPriceTypeEnum
from ..models import OrderListOpocoWorkingPegOffsetTypeEnum
from ..models import OrderListOpocoPendingAboveTimeInForceEnum
from ..models import OrderListOpocoPendingAbovePegPriceTypeEnum
from ..models import OrderListOpocoPendingAbovePegOffsetTypeEnum
from ..models import OrderListOpocoPendingBelowTypeEnum
from ..models import OrderListOpocoPendingBelowTimeInForceEnum
from ..models import OrderListOpocoPendingBelowPegPriceTypeEnum
from ..models import OrderListOpocoPendingBelowPegOffsetTypeEnum
from ..models import OrderListOtoWorkingTypeEnum
from ..models import OrderListOtoWorkingSideEnum
from ..models import OrderListOtoPendingTypeEnum
from ..models import OrderListOtoPendingSideEnum
from ..models import OrderListOtoNewOrderRespTypeEnum
from ..models import OrderListOtoSelfTradePreventionModeEnum
from ..models import OrderListOtoWorkingTimeInForceEnum
from ..models import OrderListOtoWorkingPegPriceTypeEnum
from ..models import OrderListOtoWorkingPegOffsetTypeEnum
from ..models import OrderListOtoPendingTimeInForceEnum
from ..models import OrderListOtoPendingPegPriceTypeEnum
from ..models import OrderListOtoPendingPegOffsetTypeEnum
from ..models import OrderListOtocoWorkingTypeEnum
from ..models import OrderListOtocoWorkingSideEnum
from ..models import OrderListOtocoPendingSideEnum
from ..models import OrderListOtocoPendingAboveTypeEnum
from ..models import OrderListOtocoNewOrderRespTypeEnum
from ..models import OrderListOtocoSelfTradePreventionModeEnum
from ..models import OrderListOtocoWorkingTimeInForceEnum
from ..models import OrderListOtocoWorkingPegPriceTypeEnum
from ..models import OrderListOtocoWorkingPegOffsetTypeEnum
from ..models import OrderListOtocoPendingAboveTimeInForceEnum
from ..models import OrderListOtocoPendingAbovePegPriceTypeEnum
from ..models import OrderListOtocoPendingAbovePegOffsetTypeEnum
from ..models import OrderListOtocoPendingBelowTypeEnum
from ..models import OrderListOtocoPendingBelowTimeInForceEnum
from ..models import OrderListOtocoPendingBelowPegPriceTypeEnum
from ..models import OrderListOtocoPendingBelowPegOffsetTypeEnum
from ..models import OrderOcoSideEnum
from ..models import OrderOcoStopLimitTimeInForceEnum
from ..models import OrderOcoNewOrderRespTypeEnum
from ..models import OrderOcoSelfTradePreventionModeEnum
from ..models import OrderTestSideEnum
from ..models import OrderTestTypeEnum
from ..models import OrderTestTimeInForceEnum
from ..models import OrderTestNewOrderRespTypeEnum
from ..models import OrderTestSelfTradePreventionModeEnum
from ..models import OrderTestPegPriceTypeEnum
from ..models import OrderTestPegOffsetTypeEnum
from ..models import SorOrderSideEnum
from ..models import SorOrderTypeEnum
from ..models import SorOrderTimeInForceEnum
from ..models import SorOrderNewOrderRespTypeEnum
from ..models import SorOrderSelfTradePreventionModeEnum
from ..models import SorOrderTestSideEnum
from ..models import SorOrderTestTypeEnum
from ..models import SorOrderTestTimeInForceEnum
from ..models import SorOrderTestNewOrderRespTypeEnum
from ..models import SorOrderTestSelfTradePreventionModeEnum


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 delete_open_orders(
        self,
        symbol: Union[str, None],
        recv_window: Optional[float] = None,
    ) -> ApiResponse[DeleteOpenOrdersResponse]:
        """
                Cancel All Open Orders on a Symbol
                DELETE /api/v3/openOrders
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-all-open-orders-on-a-symbol-trade

                Cancels all active orders on a symbol.
        This includes orders that are part of an order list.
        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[DeleteOpenOrdersResponse]

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

    def delete_order(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        new_client_order_id: Optional[str] = None,
        cancel_restrictions: Optional[DeleteOrderCancelRestrictionsEnum] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[DeleteOrderResponse]:
        """
                Cancel order
                DELETE /api/v3/order
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade

                Cancel an active order.
        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    orig_client_order_id (Optional[str] = None):
                    new_client_order_id (Optional[str] = None): A unique id among open orders. Automatically generated if not sent.<br/> Orders with the same `newClientOrderID` can be accepted only when the previous one is filled, otherwise the order will be rejected.
                    cancel_restrictions (Optional[DeleteOrderCancelRestrictionsEnum] = None):
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[DeleteOrderResponse]

                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,
            "new_client_order_id": new_client_order_id,
            "cancel_restrictions": cancel_restrictions,
            "recv_window": recv_window,
        }

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

    def delete_order_list(
        self,
        symbol: Union[str, None],
        order_list_id: Optional[int] = None,
        list_client_order_id: Optional[str] = None,
        new_client_order_id: Optional[str] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[DeleteOrderListResponse]:
        """
                Cancel Order list
                DELETE /api/v3/orderList
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-list-trade

                Cancel an entire Order list
        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    order_list_id (Optional[int] = None): Either `orderListId` or `listClientOrderId` must be provided
                    list_client_order_id (Optional[str] = None): A unique Id for the entire orderList
                    new_client_order_id (Optional[str] = None): A unique id among open orders. Automatically generated if not sent.<br/> Orders with the same `newClientOrderID` can be accepted only when the previous one is filled, otherwise the order will be rejected.
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[DeleteOrderListResponse]

                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_list_id": order_list_id,
            "list_client_order_id": list_client_order_id,
            "new_client_order_id": new_client_order_id,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="DELETE",
            path="/api/v3/orderList",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=DeleteOrderListResponse,
            is_signed=True,
            signer=self._signer,
        )

    def new_order(
        self,
        symbol: Union[str, None],
        side: Union[NewOrderSideEnum, None],
        type: Union[NewOrderTypeEnum, None],
        time_in_force: Optional[NewOrderTimeInForceEnum] = None,
        quantity: Optional[float] = None,
        quote_order_qty: Optional[float] = None,
        price: Optional[float] = None,
        new_client_order_id: Optional[str] = None,
        strategy_id: Optional[int] = None,
        strategy_type: Optional[int] = None,
        stop_price: Optional[float] = None,
        trailing_delta: Optional[int] = None,
        iceberg_qty: Optional[float] = None,
        new_order_resp_type: Optional[NewOrderNewOrderRespTypeEnum] = None,
        self_trade_prevention_mode: Optional[
            NewOrderSelfTradePreventionModeEnum
        ] = None,
        peg_price_type: Optional[NewOrderPegPriceTypeEnum] = None,
        peg_offset_value: Optional[int] = None,
        peg_offset_type: Optional[NewOrderPegOffsetTypeEnum] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[NewOrderResponse]:
        """
                New order
                POST /api/v3/order
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

                Send in a new order.

        This adds 1 order to the `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter.
        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    side (Union[NewOrderSideEnum, None]):
                    type (Union[NewOrderTypeEnum, None]):
                    time_in_force (Optional[NewOrderTimeInForceEnum] = None):
                    quantity (Optional[float] = None):
                    quote_order_qty (Optional[float] = None):
                    price (Optional[float] = None):
                    new_client_order_id (Optional[str] = None): A unique id among open orders. Automatically generated if not sent.<br/> Orders with the same `newClientOrderID` can be accepted only when the previous one is filled, otherwise the order will be rejected.
                    strategy_id (Optional[int] = None):
                    strategy_type (Optional[int] = None): The value cannot be less than `1000000`.
                    stop_price (Optional[float] = None): Used with `STOP_LOSS`, `STOP_LOSS_LIMIT`, `TAKE_PROFIT`, and `TAKE_PROFIT_LIMIT` orders.
                    trailing_delta (Optional[int] = None): See [Trailing Stop order FAQ](faqs/trailing-stop-faq.md).
                    iceberg_qty (Optional[float] = None): Used with `LIMIT`, `STOP_LOSS_LIMIT`, and `TAKE_PROFIT_LIMIT` to create an iceberg order.
                    new_order_resp_type (Optional[NewOrderNewOrderRespTypeEnum] = None):
                    self_trade_prevention_mode (Optional[NewOrderSelfTradePreventionModeEnum] = None):
                    peg_price_type (Optional[NewOrderPegPriceTypeEnum] = None):
                    peg_offset_value (Optional[int] = None): Priceleveltopegthepriceto(max:100).<br>See[PeggedOrdersInfo](#pegged-orders-info)
                    peg_offset_type (Optional[NewOrderPegOffsetTypeEnum] = None):
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[NewOrderResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "side": side,
            "type": type,
            "time_in_force": time_in_force,
            "quantity": quantity,
            "quote_order_qty": quote_order_qty,
            "price": price,
            "new_client_order_id": new_client_order_id,
            "strategy_id": strategy_id,
            "strategy_type": strategy_type,
            "stop_price": stop_price,
            "trailing_delta": trailing_delta,
            "iceberg_qty": iceberg_qty,
            "new_order_resp_type": new_order_resp_type,
            "self_trade_prevention_mode": self_trade_prevention_mode,
            "peg_price_type": peg_price_type,
            "peg_offset_value": peg_offset_value,
            "peg_offset_type": peg_offset_type,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/api/v3/order",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=NewOrderResponse,
            is_signed=True,
            signer=self._signer,
        )

    def order_amend_keep_priority(
        self,
        symbol: Union[str, None],
        new_qty: Union[float, None],
        order_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        new_client_order_id: Optional[str] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[OrderAmendKeepPriorityResponse]:
        """
                Order Amend Keep Priority
                PUT /api/v3/order/amend/keepPriority
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#order-amend-keep-priority-trade

                Reduce the quantity of an existing open order.

        This adds 0 orders to the `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter.

        Read [Order Amend Keep Priority FAQ](faqs/order_amend_keep_priority.md) to learn more.
        Weight: 4

                Args:
                    symbol (Union[str, None]):
                    new_qty (Union[float, None]): `newQty` must be greater than 0 and less than the order's quantity.
                    order_id (Optional[int] = None):
                    orig_client_order_id (Optional[str] = None):
                    new_client_order_id (Optional[str] = None): A unique id among open orders. Automatically generated if not sent.<br/> Orders with the same `newClientOrderID` can be accepted only when the previous one is filled, otherwise the order will be rejected.
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[OrderAmendKeepPriorityResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "new_qty": new_qty,
            "order_id": order_id,
            "orig_client_order_id": orig_client_order_id,
            "new_client_order_id": new_client_order_id,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="PUT",
            path="/api/v3/order/amend/keepPriority",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=OrderAmendKeepPriorityResponse,
            is_signed=True,
            signer=self._signer,
        )

    def order_cancel_replace(
        self,
        symbol: Union[str, None],
        side: Union[OrderCancelReplaceSideEnum, None],
        type: Union[OrderCancelReplaceTypeEnum, None],
        cancel_replace_mode: Union[OrderCancelReplaceCancelReplaceModeEnum, None],
        time_in_force: Optional[OrderCancelReplaceTimeInForceEnum] = None,
        quantity: Optional[float] = None,
        quote_order_qty: Optional[float] = None,
        price: Optional[float] = None,
        cancel_new_client_order_id: Optional[str] = None,
        cancel_orig_client_order_id: Optional[str] = None,
        cancel_order_id: Optional[int] = None,
        new_client_order_id: Optional[str] = None,
        strategy_id: Optional[int] = None,
        strategy_type: Optional[int] = None,
        stop_price: Optional[float] = None,
        trailing_delta: Optional[int] = None,
        iceberg_qty: Optional[float] = None,
        new_order_resp_type: Optional[OrderCancelReplaceNewOrderRespTypeEnum] = None,
        self_trade_prevention_mode: Optional[
            OrderCancelReplaceSelfTradePreventionModeEnum
        ] = None,
        cancel_restrictions: Optional[OrderCancelReplaceCancelRestrictionsEnum] = None,
        order_rate_limit_exceeded_mode: Optional[
            OrderCancelReplaceOrderRateLimitExceededModeEnum
        ] = None,
        peg_price_type: Optional[OrderCancelReplacePegPriceTypeEnum] = None,
        peg_offset_value: Optional[int] = None,
        peg_offset_type: Optional[OrderCancelReplacePegOffsetTypeEnum] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[OrderCancelReplaceResponse]:
        """
                Cancel an Existing Order and Send a New Order
                POST /api/v3/order/cancelReplace
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade

                Cancels an existing order and places a new order on the same symbol.

        Filters and Order Count are evaluated before the processing of the cancellation and order placement occurs.

        A new order that was not attempted (i.e. when `newOrderResult: NOT_ATTEMPTED`), will still increase the unfilled order count by 1.
        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    side (Union[OrderCancelReplaceSideEnum, None]):
                    type (Union[OrderCancelReplaceTypeEnum, None]):
                    cancel_replace_mode (Union[OrderCancelReplaceCancelReplaceModeEnum, None]):
                    time_in_force (Optional[OrderCancelReplaceTimeInForceEnum] = None):
                    quantity (Optional[float] = None):
                    quote_order_qty (Optional[float] = None):
                    price (Optional[float] = None):
                    cancel_new_client_order_id (Optional[str] = None): Used to uniquely identify this cancel. Automatically generated by default.
                    cancel_orig_client_order_id (Optional[str] = None): Either `cancelOrderId` or `cancelOrigClientOrderId` must be sent. <br></br> If both `cancelOrderId` and `cancelOrigClientOrderId` parameters are provided, the `cancelOrderId` is searched first, then the `cancelOrigClientOrderId` from that result is checked against that order. <br></br> If both conditions are not met the request will be rejected.
                    cancel_order_id (Optional[int] = None): Either `cancelOrderId` or `cancelOrigClientOrderId` must be sent. <br></br>If both `cancelOrderId` and `cancelOrigClientOrderId` parameters are provided, the `cancelOrderId` is searched first, then the `cancelOrigClientOrderId` from that result is checked against that order. <br></br>If both conditions are not met the request will be rejected.
                    new_client_order_id (Optional[str] = None): A unique id among open orders. Automatically generated if not sent.<br/> Orders with the same `newClientOrderID` can be accepted only when the previous one is filled, otherwise the order will be rejected.
                    strategy_id (Optional[int] = None):
                    strategy_type (Optional[int] = None): The value cannot be less than `1000000`.
                    stop_price (Optional[float] = None): Used with `STOP_LOSS`, `STOP_LOSS_LIMIT`, `TAKE_PROFIT`, and `TAKE_PROFIT_LIMIT` orders.
                    trailing_delta (Optional[int] = None): See [Trailing Stop order FAQ](faqs/trailing-stop-faq.md).
                    iceberg_qty (Optional[float] = None): Used with `LIMIT`, `STOP_LOSS_LIMIT`, and `TAKE_PROFIT_LIMIT` to create an iceberg order.
                    new_order_resp_type (Optional[OrderCancelReplaceNewOrderRespTypeEnum] = None):
                    self_trade_prevention_mode (Optional[OrderCancelReplaceSelfTradePreventionModeEnum] = None):
                    cancel_restrictions (Optional[OrderCancelReplaceCancelRestrictionsEnum] = None):
                    order_rate_limit_exceeded_mode (Optional[OrderCancelReplaceOrderRateLimitExceededModeEnum] = None):
                    peg_price_type (Optional[OrderCancelReplacePegPriceTypeEnum] = None):
                    peg_offset_value (Optional[int] = None): Priceleveltopegthepriceto(max:100).<br>See[PeggedOrdersInfo](#pegged-orders-info)
                    peg_offset_type (Optional[OrderCancelReplacePegOffsetTypeEnum] = None):
                    recv_window (Optional[float] = None): The value cannot be greater than `60000`. <br> Supports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.

                Returns:
                    ApiResponse[OrderCancelReplaceResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "side": side,
            "type": type,
            "cancel_replace_mode": cancel_replace_mode,
            "time_in_force": time_in_force,
            "quantity": quantity,
            "quote_order_qty": quote_order_qty,
            "price": price,
            "cancel_new_client_order_id": cancel_new_client_order_id,
            "cancel_orig_client_order_id": cancel_orig_client_order_id,
            "cancel_order_id": cancel_order_id,
            "new_client_order_id": new_client_order_id,
            "strategy_id": strategy_id,
            "strategy_type": strategy_type,
            "stop_price": stop_price,
            "trailing_delta": trailing_delta,
            "iceberg_qty": iceberg_qty,
            "new_order_resp_type": new_order_resp_type,
            "self_trade_prevention_mode": self_trade_prevention_mode,
            "cancel_restrictions": cancel_restrictions,
            "order_rate_limit_exceeded_mode": order_rate_limit_exceeded_mode,
            "peg_price_type": peg_price_type,
            "peg_offset_value": peg_offset_value,
            "peg_offset_type": peg_offset_type,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/api/v3/order/cancelReplace",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=OrderCancelReplaceResponse,
            is_signed=True,
            signer=self._signer,
        )

    def order_list_oco(
        self,
        symbol: Union[str, None],
        side: Union[OrderListOcoSideEnum, None],
        quantity: Union[float, None],
        above_type: Union[OrderListOcoAboveTypeEnum, None],
        below_type: Union[OrderListOcoBelowTypeEnum, None],
        list_client_order_id: Optional[str] = None,
        above_client_order_id: Optional[str] = None,
        above_iceberg_qty: Optional[int] = None,
        above_price: Optional[float] = None,
        above_stop_price: Optional[float] = None,
        above_trailing_delta: Optional[int] = None,
        above_time_in_force: Optional[OrderListOcoAboveTimeInForceEnum] = None,
        above_strategy_id: Optional[int] = None,
        above_strategy_type: Optional[int] = None,
        above_peg_price_type: Optional[OrderListOcoAbovePegPriceTypeEnum] = None,
        above_peg_offset_type: Optional[OrderListOcoAbovePegOffsetTypeEnum] = None,
        above_peg_offset_value: Optional[int] = None,
        below_client_order_id: Optional[str] = None,
        below_iceberg_qty: Optional[int] = None,
        below_price: Optional[float] = None,
        below_stop_price: Optional[float] = None,
        below_trailing_delta: Optional[int] = None,
        below_time_in_force: Optional[OrderListOcoBelowTimeInForceEnum] = None,
        below_strategy_id: Optional[int] = None,
        below_strategy_type: Optional[int] = None,
        below_peg_price_type: Optional[OrderListOcoBelowPegPriceTypeEnum] = None,
        below_peg_offset_type: Optional[OrderListOcoBelowPegOffsetTypeEnum] = None,
        below_peg_offset_value: Optional[int] = None,
        new_order_resp_type: Optional[OrderListOcoNewOrderRespTypeEnum] = None,
        self_trade_prevention_mode: Optional[
            OrderListOcoSelfTradePreventionModeEnum
        ] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[OrderListOcoResponse]:
        """
                New Order list - OCO
                POST /api/v3/orderList/oco
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade

                Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.

        * An OCO has 2 orders called the **above order** and **below order**.
