"""
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 GetCrossMarginTransferHistoryResponse
from ..models import QueryMaxTransferOutAmountResponse


class TransferApi:
    """API Client for TransferApi endpoints."""

    def __init__(
        self,
        configuration: ConfigurationRestAPI = None,
        session: Session = None,
        signer: Signers = None,
    ) -> None:
        self._configuration = configuration
        self._session = session
        self._signer = signer

    def get_cross_margin_transfer_history(
        self,
        asset: Optional[str] = None,
        type: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        isolated_symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetCrossMarginTransferHistoryResponse]:
        """
                Get Cross Margin Transfer History (USER_DATA)
                GET /sapi/v1/margin/transfer
                https://developers.binance.com/docs/margin_trading/transfer/Get-Cross-Margin-Transfer-History

                Get Cross Margin Transfer History

        * Response in descending order
        * The max interval between `startTime` and `endTime` is 30 days.
        * Returns data for last 7 days by default

        Weight: 1(IP)

                Args:
                    asset (Optional[str] = None):
                    type (Optional[str] = None): Transfer Type: ROLL_IN, ROLL_OUT
                    start_time (Optional[int] = None): 只支持查询最近90天的数据
                    end_time (Optional[int] = None):
                    current (Optional[int] = None): Currently querying page. Start from 1. Default:1
                    size (Optional[int] = None): Default:10 Max:100
                    isolated_symbol (Optional[str] = None): isolated symbol
                    recv_window (Optional[int] = None): No more than 60000

                Returns:
                    ApiResponse[GetCrossMarginTransferHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "asset": asset,
            "type": type,
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "isolated_symbol": isolated_symbol,
            "recv_window": recv_window,
        }

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

    def query_max_transfer_out_amount(
        self,
        asset: Union[str, None],
        isolated_symbol: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryMaxTransferOutAmountResponse]:
        """
                Query Max Transfer-Out Amount (USER_DATA)
                GET /sapi/v1/margin/maxTransferable
                https://developers.binance.com/docs/margin_trading/transfer/Query-Max-Transfer-Out-Amount

                Query Max Transfer-Out Amount

        * If isolatedSymbol is not sent, crossed margin data will be sent.

        Weight: 50(IP)

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

                Returns:
                    ApiResponse[QueryMaxTransferOutAmountResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "asset": asset,
            "isolated_symbol": isolated_symbol,
            "recv_window": recv_window,
        }

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