"""
Binance Margin Trading REST API

OpenAPI Specification for the Binance Margin Trading 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 AdjustCrossMarginMaxLeverageResponse
from ..models import DisableIsolatedMarginAccountResponse
from ..models import EnableIsolatedMarginAccountResponse
from ..models import GetBnbBurnStatusResponse
from ..models import GetSummaryOfMarginAccountResponse
from ..models import QueryCrossIsolatedMarginCapitalFlowResponse
from ..models import QueryCrossMarginAccountDetailsResponse
from ..models import QueryCrossMarginFeeDataResponse
from ..models import QueryEnabledIsolatedMarginAccountLimitResponse
from ..models import QueryIsolatedMarginAccountInfoResponse
from ..models import QueryIsolatedMarginFeeDataResponse


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 adjust_cross_margin_max_leverage(
        self,
        max_leverage: Union[int, None],
    ) -> ApiResponse[AdjustCrossMarginMaxLeverageResponse]:
        """
                Adjust cross margin max leverage (USER_DATA)
                POST /sapi/v1/margin/max-leverage
                https://developers.binance.com/docs/margin_trading/account/Adjust-cross-margin-max-leverage

                Adjust cross margin max leverage

        * The margin level need higher than the initial risk ratio of adjusted leverage, the initial risk ratio of 3x is 1.5 , the initial risk ratio of 5x is 1.25;  The detail conditions on how to switch between Cross Margin Classic and Cross Margin Pro can refer to [the FAQ](https://www.binance.com/en/support/faq/how-to-activate-the-cross-margin-pro-mode-on-binance-e27786da05e743a694b8c625b3bc475d).

        Weight: 3000

                Args:
                    max_leverage (Union[int, None]): Can only adjust 3 , 5 or 10，Example: maxLeverage = 5 or 3 for Cross Margin Classic; maxLeverage=10 for Cross Margin Pro 10x leverage or 20x if compliance allows.

                Returns:
                    ApiResponse[AdjustCrossMarginMaxLeverageResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {"max_leverage": max_leverage}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/margin/max-leverage",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AdjustCrossMarginMaxLeverageResponse,
            is_signed=True,
            signer=self._signer,
        )

    def disable_isolated_margin_account(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[DisableIsolatedMarginAccountResponse]:
        """
                Disable Isolated Margin Account (TRADE)
                DELETE /sapi/v1/margin/isolated/account
                https://developers.binance.com/docs/margin_trading/account/Disable-Isolated-Margin-Account

                Disable isolated margin account for a specific symbol. Each trading pair can only be deactivated once every 24
        hours.

        Weight: 300(UID)

                Args:
                    symbol (Union[str, None]):
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[DisableIsolatedMarginAccountResponse]

                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="/sapi/v1/margin/isolated/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=DisableIsolatedMarginAccountResponse,
            is_signed=True,
            signer=self._signer,
        )

    def enable_isolated_margin_account(
        self,
        symbol: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[EnableIsolatedMarginAccountResponse]:
        """
                Enable Isolated Margin Account (TRADE)
                POST /sapi/v1/margin/isolated/account
                https://developers.binance.com/docs/margin_trading/account/Enable-Isolated-Margin-Account

                Enable isolated margin account for a specific symbol(Only supports activation of previously disabled accounts).

        Weight: 300(UID)

                Args:
                    symbol (Union[str, None]):
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[EnableIsolatedMarginAccountResponse]

                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="POST",
            path="/sapi/v1/margin/isolated/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=EnableIsolatedMarginAccountResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bnb_burn_status(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBnbBurnStatusResponse]:
        """
                Get BNB Burn Status (USER_DATA)
                GET /sapi/v1/bnbBurn
                https://developers.binance.com/docs/margin_trading/account/Get-BNB-Burn-Status

                Get BNB Burn Status

        Weight: 1(IP)

                Args:
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[GetBnbBurnStatusResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def get_summary_of_margin_account(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetSummaryOfMarginAccountResponse]:
        """
                Get Summary of Margin account (USER_DATA)
                GET /sapi/v1/margin/tradeCoeff
                https://developers.binance.com/docs/margin_trading/account/Get-Summary-of-Margin-account

                Get personal margin level information

        Weight: 10(IP)

                Args:
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[GetSummaryOfMarginAccountResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/margin/tradeCoeff",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetSummaryOfMarginAccountResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_cross_isolated_margin_capital_flow(
        self,
        asset: Optional[str] = None,
        symbol: Optional[str] = None,
        type: Optional[str] = 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[QueryCrossIsolatedMarginCapitalFlowResponse]:
        """
                Query Cross Isolated Margin Capital Flow (USER_DATA)
                GET /sapi/v1/margin/capital-flow
                https://developers.binance.com/docs/margin_trading/account/Query-Cross-Isolated-Margin-Capital-Flow

                Query Cross Isolated Margin Capital Flow

        Weight: 100(IP)

                Args:
                    asset (Optional[str] = None):
                    symbol (Optional[str] = None): isolated margin pair
                    type (Optional[str] = None): Transfer Type: ROLL_IN, ROLL_OUT
                    start_time (Optional[int] = None): 只支持查询最近90天的数据
                    end_time (Optional[int] = None):
                    from_id (Optional[int] = None): 如设置fromId, 将返回id > fromId的数据。否则将返回最新数据
                    limit (Optional[int] = None): Default Value: 500; Max Value: 1000
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryCrossIsolatedMarginCapitalFlowResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "asset": asset,
            "symbol": symbol,
            "type": type,
            "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="/sapi/v1/margin/capital-flow",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryCrossIsolatedMarginCapitalFlowResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_cross_margin_account_details(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryCrossMarginAccountDetailsResponse]:
        """
                Query Cross Margin Account Details (USER_DATA)
                GET /sapi/v1/margin/account
                https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Account-Details

                Query Cross Margin Account Details

        Weight: 10(IP)

                Args:
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryCrossMarginAccountDetailsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def query_cross_margin_fee_data(
        self,
        vip_level: Optional[int] = None,
        coin: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryCrossMarginFeeDataResponse]:
        """
                Query Cross Margin Fee Data (USER_DATA)
                GET /sapi/v1/margin/crossMarginData
                https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Fee-Data

                Get cross margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee

        Weight: 1 when coin is specified;(IP)

                Args:
                    vip_level (Optional[int] = None): User's current specific margin data will be returned if vipLevel is omitted
                    coin (Optional[str] = None):
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryCrossMarginFeeDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"vip_level": vip_level, "coin": coin, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/margin/crossMarginData",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryCrossMarginFeeDataResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_enabled_isolated_margin_account_limit(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryEnabledIsolatedMarginAccountLimitResponse]:
        """
                Query Enabled Isolated Margin Account Limit (USER_DATA)
                GET /sapi/v1/margin/isolated/accountLimit
                https://developers.binance.com/docs/margin_trading/account/Query-Enabled-Isolated-Margin-Account-Limit

                Query enabled isolated margin account limit.

        Weight: 1(IP)

                Args:
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryEnabledIsolatedMarginAccountLimitResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/margin/isolated/accountLimit",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryEnabledIsolatedMarginAccountLimitResponse,
            is_signed=True,
            signer=self._signer,
        )

    def query_isolated_margin_account_info(
        self,
        symbols: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryIsolatedMarginAccountInfoResponse]:
        """
                Query Isolated Margin Account Info (USER_DATA)
                GET /sapi/v1/margin/isolated/account
                https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Account-Info

                Query Isolated Margin Account Info

        * If "symbols" is not sent, all isolated assets will be returned.
        * If "symbols" is sent, only the isolated assets of the sent symbols will be returned.

        Weight: 10(IP)

                Args:
                    symbols (Optional[str] = None): Max 5 symbols can be sent; separated by ",". e.g. "BTCUSDT,BNBUSDT,ADAUSDT"
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryIsolatedMarginAccountInfoResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

    def query_isolated_margin_fee_data(
        self,
        vip_level: Optional[int] = None,
        symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryIsolatedMarginFeeDataResponse]:
        """
                Query Isolated Margin Fee Data (USER_DATA)
                GET /sapi/v1/margin/isolatedMarginData
                https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Fee-Data

                Get isolated margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee

        Weight: 1 when a single is specified;(IP)

                Args:
                    vip_level (Optional[int] = None): User's current specific margin data will be returned if vipLevel is omitted
                    symbol (Optional[str] = None): isolated margin pair
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[QueryIsolatedMarginFeeDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/margin/isolatedMarginData",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryIsolatedMarginFeeDataResponse,
            is_signed=True,
            signer=self._signer,
        )
