"""
Binance Derivatives Trading COIN Futures REST API

OpenAPI Specification for the Binance Derivatives Trading COIN 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 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 AccountInformationResponse
from ..models import FuturesAccountBalanceResponse
from ..models import GetCurrentPositionModeResponse
from ..models import GetDownloadIdForFuturesOrderHistoryResponse
from ..models import GetDownloadIdForFuturesTradeHistoryResponse
from ..models import GetDownloadIdForFuturesTransactionHistoryResponse
from ..models import GetFuturesOrderHistoryDownloadLinkByIdResponse
from ..models import GetFuturesTradeDownloadLinkByIdResponse
from ..models import GetFuturesTransactionHistoryDownloadLinkByIdResponse
from ..models import GetIncomeHistoryResponse
from ..models import NotionalBracketForPairResponse
from ..models import NotionalBracketForSymbolResponse
from ..models import UserCommissionRateResponse


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_information(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AccountInformationResponse]:
        """
                Account Information (USER_DATA)
                GET /dapi/v1/account
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information

                Get current account information.

        * for One-way Mode user, the "positions" will only show the "BOTH" positions
        * for Hedge Mode user, the "positions" will show "BOTH", "LONG", and "SHORT" positions.

        Weight: 5

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

                Returns:
                    ApiResponse[AccountInformationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def futures_account_balance(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[FuturesAccountBalanceResponse]:
        """
                Futures Account Balance (USER_DATA)
                GET /dapi/v1/balance
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Futures-Account-Balance

                Check futures account balance

        Weight: 1

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

                Returns:
                    ApiResponse[FuturesAccountBalanceResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def get_current_position_mode(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetCurrentPositionModeResponse]:
        """
                Get Current Position Mode(USER_DATA)
                GET /dapi/v1/positionSide/dual
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Current-Position-Mode

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

        Weight: 30

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

                Returns:
                    ApiResponse[GetCurrentPositionModeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def get_download_id_for_futures_order_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForFuturesOrderHistoryResponse]:
        """
                Get Download Id For Futures Order History (USER_DATA)
                GET /dapi/v1/order/asyn
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History

                Get Download Id For Futures Order History

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

        Weight: 5

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

                Returns:
                    ApiResponse[GetDownloadIdForFuturesOrderHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_download_id_for_futures_trade_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForFuturesTradeHistoryResponse]:
        """
                Get Download Id For Futures Trade History (USER_DATA)
                GET /dapi/v1/trade/asyn
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History

                Get download id for futures trade history

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

        Weight: 5

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

                Returns:
                    ApiResponse[GetDownloadIdForFuturesTradeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_download_id_for_futures_transaction_history(
        self,
        start_time: Union[int, None],
        end_time: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDownloadIdForFuturesTransactionHistoryResponse]:
        """
                Get Download Id For Futures Transaction History(USER_DATA)
                GET /dapi/v1/income/asyn
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History

                Get download id for futures transaction history

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

        Weight: 5

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

                Returns:
                    ApiResponse[GetDownloadIdForFuturesTransactionHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_futures_order_history_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetFuturesOrderHistoryDownloadLinkByIdResponse]:
        """
                Get Futures Order History Download Link by Id (USER_DATA)
                GET /dapi/v1/order/asyn/id
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id

                Get futures order history download link by Id

        * Download link expiration: 24h

        Weight: 5

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

                Returns:
                    ApiResponse[GetFuturesOrderHistoryDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_futures_trade_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetFuturesTradeDownloadLinkByIdResponse]:
        """
                Get Futures Trade Download Link by Id(USER_DATA)
                GET /dapi/v1/trade/asyn/id
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id

                Get futures trade download link by Id

        * Download link expiration: 24h

        Weight: 5

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

                Returns:
                    ApiResponse[GetFuturesTradeDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_futures_transaction_history_download_link_by_id(
        self,
        download_id: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetFuturesTransactionHistoryDownloadLinkByIdResponse]:
        """
                Get Futures Transaction History Download Link by Id (USER_DATA)
                GET /dapi/v1/income/asyn/id
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id

                Get futures transaction history download link by Id

        * Download link expiration: 24h

        Weight: 5

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

                Returns:
                    ApiResponse[GetFuturesTransactionHistoryDownloadLinkByIdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

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

    def get_income_history(
        self,
        symbol: Optional[str] = None,
        income_type: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        page: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetIncomeHistoryResponse]:
        """
                Get Income History(USER_DATA)
                GET /dapi/v1/income
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History

                Get income history

        * If `incomeType ` is not sent, all kinds of flow will be returned
        * "trandId" is unique in the same "incomeType" for a user
        * The time between `startTime` and `endTime` can not be longer than 1 year

        Weight: 20

                Args:
                    symbol (Optional[str] = None):
                    income_type (Optional[str] = None): "TRANSFER","WELCOME_BONUS", "FUNDING_FEE", "REALIZED_PNL", "COMMISSION", "INSURANCE_CLEAR", and "DELIVERED_SETTELMENT"
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    page (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetIncomeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def notional_bracket_for_pair(
        self,
        pair: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[NotionalBracketForPairResponse]:
        """
                Notional Bracket for Pair(USER_DATA)
                GET /dapi/v1/leverageBracket
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Pair

                **Not recommended to continue using this v1 endpoint**

        Get the pair's default notional bracket list, may return ambiguous values when there have been multiple different `symbol` brackets under the `pair`, suggest using the following `GET /dapi/v2/leverageBracket` query instead to get the specific `symbol` notional bracket list.

        Weight: 1

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

                Returns:
                    ApiResponse[NotionalBracketForPairResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def notional_bracket_for_symbol(
        self,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[NotionalBracketForSymbolResponse]:
        """
                Notional Bracket for Symbol(USER_DATA)
                GET /dapi/v2/leverageBracket
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Symbol

                Get the symbol's notional bracket list.

        Weight: 1

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

                Returns:
                    ApiResponse[NotionalBracketForSymbolResponse]

                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="/dapi/v2/leverageBracket",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=NotionalBracketForSymbolResponse,
            is_signed=True,
            signer=self._signer,
        )

    def user_commission_rate(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[UserCommissionRateResponse]:
        """
                User Commission Rate (USER_DATA)
                GET /dapi/v1/commissionRate
                https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/User-Commission-Rate

                Query user commission rate

        Weight: 20

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

                Returns:
                    ApiResponse[UserCommissionRateResponse]

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