"""
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 AccountCommissionResponse
from ..models import AllOrderListResponse
from ..models import AllOrdersResponse
from ..models import GetAccountResponse
from ..models import GetOpenOrdersResponse
from ..models import GetOrderResponse
from ..models import GetOrderListResponse
from ..models import MyAllocationsResponse
from ..models import MyFiltersResponse
from ..models import MyPreventedMatchesResponse
from ..models import MyTradesResponse
from ..models import OpenOrderListResponse
from ..models import OrderAmendmentsResponse
from ..models import RateLimitOrderResponse


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_commission(
        self,
        symbol: Union[str, None],
    ) -> ApiResponse[AccountCommissionResponse]:
        """
                Query Commission Rates
                GET /api/v3/account/commission
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-commission-rates-user_data

                Get current account commission rates.
        Weight: 20

                Args:
                    symbol (Union[str, None]):

                Returns:
                    ApiResponse[AccountCommissionResponse]

                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}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/api/v3/account/commission",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AccountCommissionResponse,
            is_signed=True,
            signer=self._signer,
        )

    def all_order_list(
        self,
        from_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[AllOrderListResponse]:
        """
                Query all Order lists
                GET /api/v3/allOrderList
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-all-order-lists-user_data

                Retrieves all order lists based on provided optional parameters.

        Note that the time between `startTime` and `endTime` can't be longer than 24 hours.
        Weight: 20

                Args:
                    from_id (Optional[int] = None): ID to get aggregate trades from INCLUSIVE.
                    start_time (Optional[int] = None): Timestamp in ms to get aggregate trades from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get aggregate trades until INCLUSIVE.
                    limit (Optional[int] = None): Default: 500; Maximum: 1000.
                    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[AllOrderListResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "from_id": from_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="/api/v3/allOrderList",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AllOrderListResponse,
            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[float] = None,
    ) -> ApiResponse[AllOrdersResponse]:
        """
                All orders
                GET /api/v3/allOrders
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#all-orders-user_data

                Get all account orders; active, canceled, or filled.
        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    start_time (Optional[int] = None): Timestamp in ms to get aggregate trades from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get aggregate trades until INCLUSIVE.
                    limit (Optional[int] = None): Default: 500; Maximum: 1000.
                    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[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="/api/v3/allOrders",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AllOrdersResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_account(
        self,
        omit_zero_balances: Optional[bool] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[GetAccountResponse]:
        """
                Account information
                GET /api/v3/account
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data

                Get current account information.
        Weight: 20

                Args:
                    omit_zero_balances (Optional[bool] = None): When set to `true`, emits only the non-zero balances of an account. <br>Default value: `false`
                    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[GetAccountResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def get_open_orders(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[GetOpenOrdersResponse]:
        """
                Current open orders
                GET /api/v3/openOrders
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#current-open-orders-user_data

                Get all open orders on a symbol. **Careful** when accessing this with no symbol.
        Weight: 6 for a single symbol; **80** when the symbol parameter is omitted

                Args:
                    symbol (Optional[str] = None): Symbol to query
                    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[GetOpenOrdersResponse]

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

    def get_order(
        self,
        symbol: Union[str, None],
        order_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[GetOrderResponse]:
        """
                Query order
                GET /api/v3/order
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-user_data

                Check an order's status.
        Weight: 4

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    orig_client_order_id (Optional[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[GetOrderResponse]

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

    def get_order_list(
        self,
        order_list_id: Optional[int] = None,
        orig_client_order_id: Optional[str] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[GetOrderListResponse]:
        """
                Query Order list
                GET /api/v3/orderList
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-list-user_data

                Retrieves a specific order list based on provided optional parameters.
        Weight: 4

                Args:
                    order_list_id (Optional[int] = None): Either `orderListId` or `listClientOrderId` must be provided
                    orig_client_order_id (Optional[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[GetOrderListResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "order_list_id": order_list_id,
            "orig_client_order_id": orig_client_order_id,
            "recv_window": recv_window,
        }

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

    def my_allocations(
        self,
        symbol: Union[str, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        from_allocation_id: Optional[int] = None,
        limit: Optional[int] = None,
        order_id: Optional[int] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[MyAllocationsResponse]:
        """
                Query Allocations
                GET /api/v3/myAllocations
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-allocations-user_data

                Retrieves allocations resulting from SOR order placement.
        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    start_time (Optional[int] = None): Timestamp in ms to get aggregate trades from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get aggregate trades until INCLUSIVE.
                    from_allocation_id (Optional[int] = None):
                    limit (Optional[int] = None): Default: 500; Maximum: 1000.
                    order_id (Optional[int] = 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[MyAllocationsResponse]

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

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

    def my_filters(
        self,
        symbol: Union[str, None],
        recv_window: Optional[float] = None,
    ) -> ApiResponse[MyFiltersResponse]:
        """
                Query relevant filters
                GET /api/v3/myFilters
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-relevant-filters-user_data

                Retrieves the list of [filters](filters.md) relevant to an account on a given symbol. This is the only endpoint that shows if an account has `MAX_ASSET` filters applied to it.
        Weight: 40

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

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def my_prevented_matches(
        self,
        symbol: Union[str, None],
        prevented_match_id: Optional[int] = None,
        order_id: Optional[int] = None,
        from_prevented_match_id: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[MyPreventedMatchesResponse]:
        """
                Query Prevented Matches
                GET /api/v3/myPreventedMatches
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-prevented-matches-user_data

                Displays the list of orders that were expired due to STP.

        These are the combinations supported:

        * `symbol` + `preventedMatchId`
        * `symbol` + `orderId`
        * `symbol` + `orderId` + `fromPreventedMatchId` (`limit` will default to 500)
        * `symbol` + `orderId` + `fromPreventedMatchId` + `limit`
        Weight: Case                            | Weight
        ----                            | -----
        If `symbol` is invalid          | 2
        Querying by `preventedMatchId`  | 2
        Querying by `orderId`           | 20

                Args:
                    symbol (Union[str, None]):
                    prevented_match_id (Optional[int] = None):
                    order_id (Optional[int] = None):
                    from_prevented_match_id (Optional[int] = None):
                    limit (Optional[int] = None): Default: 500; Maximum: 1000.
                    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[MyPreventedMatchesResponse]

                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,
            "prevented_match_id": prevented_match_id,
            "order_id": order_id,
            "from_prevented_match_id": from_prevented_match_id,
            "limit": limit,
            "recv_window": recv_window,
        }

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

    def my_trades(
        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[float] = None,
    ) -> ApiResponse[MyTradesResponse]:
        """
                Account trade list
                GET /api/v3/myTrades
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user_data

                Get trades for a specific account and symbol.
        Weight: Condition| Weight|
        ---| ---
        |Without orderId|20|
        |With orderId|5|

                Args:
                    symbol (Union[str, None]):
                    order_id (Optional[int] = None):
                    start_time (Optional[int] = None): Timestamp in ms to get aggregate trades from INCLUSIVE.
                    end_time (Optional[int] = None): Timestamp in ms to get aggregate trades until INCLUSIVE.
                    from_id (Optional[int] = None): ID to get aggregate trades from INCLUSIVE.
                    limit (Optional[int] = None): Default: 500; Maximum: 1000.
                    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[MyTradesResponse]

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

    def open_order_list(
        self,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[OpenOrderListResponse]:
        """
                Query Open Order lists
                GET /api/v3/openOrderList
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-open-order-lists-user_data


        Weight: 6

                Args:
                    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[OpenOrderListResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def order_amendments(
        self,
        symbol: Union[str, None],
        order_id: Union[int, None],
        from_execution_id: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[OrderAmendmentsResponse]:
        """
                Query Order Amendments
                GET /api/v3/order/amendments
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-amendments-user_data

                Queries all amendments of a single order.
        Weight: 4

                Args:
                    symbol (Union[str, None]):
                    order_id (Union[int, None]):
                    from_execution_id (Optional[int] = None):
                    limit (Optional[int] = None): Default:500; Maximum: 1000
                    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[OrderAmendmentsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "order_id": order_id,
            "from_execution_id": from_execution_id,
            "limit": limit,
            "recv_window": recv_window,
        }

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

    def rate_limit_order(
        self,
        recv_window: Optional[float] = None,
    ) -> ApiResponse[RateLimitOrderResponse]:
        """
                Query Unfilled Order Count
                GET /api/v3/rateLimit/order
                https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-unfilled-order-count-user_data

                Displays the user's unfilled order count for all intervals.
        Weight: 40

                Args:
                    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[RateLimitOrderResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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