"""
Binance Wallet REST API

OpenAPI Specification for the Binance Wallet 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 AllCoinsInformationResponse
from ..models import DepositAddressResponse
from ..models import DepositHistoryResponse
from ..models import FetchDepositAddressListWithNetworkResponse
from ..models import FetchWithdrawAddressListResponse
from ..models import FetchWithdrawQuotaResponse
from ..models import OneClickArrivalDepositApplyResponse
from ..models import WithdrawResponse
from ..models import WithdrawHistoryResponse


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

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

    def all_coins_information(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[AllCoinsInformationResponse]:
        """
                All Coins' Information (USER_DATA)
                GET /sapi/v1/capital/config/getall
                https://developers.binance.com/docs/wallet/capital/all-coins-info

                Get information of coins (available for deposit and withdraw) for user.

        Weight: 10

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

                Returns:
                    ApiResponse[AllCoinsInformationResponse]

                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/capital/config/getall",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=AllCoinsInformationResponse,
            is_signed=True,
            signer=self._signer,
        )

    def deposit_address(
        self,
        coin: Union[str, None],
        network: Optional[str] = None,
        amount: Optional[float] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[DepositAddressResponse]:
        """
                Deposit Address(supporting network) (USER_DATA)
                GET /sapi/v1/capital/deposit/address
                https://developers.binance.com/docs/wallet/capital/deposite-address

                Fetch deposit address with network.

        * If `network` is not send, return with default network of the coin.
        * You can get `network` and `isDefault` in `networkList` in the response of `Get /sapi/v1/capital/config/getall (HMAC SHA256)`.
        * `amount` needs to be sent if using LIGHTNING network

        Weight: 10

                Args:
                    coin (Union[str, None]):
                    network (Optional[str] = None):
                    amount (Optional[float] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[DepositAddressResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "coin": coin,
            "network": network,
            "amount": amount,
            "recv_window": recv_window,
        }

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

    def deposit_history(
        self,
        include_source: Optional[bool] = None,
        coin: Optional[str] = None,
        status: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        offset: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
        tx_id: Optional[str] = None,
    ) -> ApiResponse[DepositHistoryResponse]:
        """
                Deposit History (supporting network) (USER_DATA)
                GET /sapi/v1/capital/deposit/hisrec
                https://developers.binance.com/docs/wallet/capital/deposite-history

                Fetch deposit history.


        * Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.
        * If both ``startTime`` and ``endTime`` are sent, time between ``startTime`` and ``endTime`` must be less than 90 days.

        Weight: 1

                Args:
                    include_source (Optional[bool] = None): Default: `false`, return `sourceAddress`field when set to `true`
                    coin (Optional[str] = None):
                    status (Optional[int] = None): 0(0:Email Sent, 2:Awaiting Approval 3:Rejected 4:Processing 6:Completed)
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    offset (Optional[int] = None): Default: 0
                    limit (Optional[int] = None): min 7, max 30, default 7
                    recv_window (Optional[int] = None):
                    tx_id (Optional[str] = None):

                Returns:
                    ApiResponse[DepositHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "include_source": include_source,
            "coin": coin,
            "status": status,
            "start_time": start_time,
            "end_time": end_time,
            "offset": offset,
            "limit": limit,
            "recv_window": recv_window,
            "tx_id": tx_id,
        }

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

    def fetch_deposit_address_list_with_network(
        self,
        coin: Union[str, None],
        network: Optional[str] = None,
    ) -> ApiResponse[FetchDepositAddressListWithNetworkResponse]:
        """
                Fetch deposit address list with network(USER_DATA)
                GET /sapi/v1/capital/deposit/address/list
                https://developers.binance.com/docs/wallet/capital/Fetch-deposit-address-list-with-network

                Fetch deposit address list with network.


        * If network is not send, return with default network of the coin.
        * You can get network and isDefault in networkList in the response of `Get /sapi/v1/capital/config/getall`.

        Weight: 10

                Args:
                    coin (Union[str, None]):
                    network (Optional[str] = None):

                Returns:
                    ApiResponse[FetchDepositAddressListWithNetworkResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {"coin": coin, "network": network}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/capital/deposit/address/list",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=FetchDepositAddressListWithNetworkResponse,
            is_signed=True,
            signer=self._signer,
        )

    def fetch_withdraw_address_list(
        self,
    ) -> ApiResponse[FetchWithdrawAddressListResponse]:
        """
                Fetch withdraw address list (USER_DATA)
                GET /sapi/v1/capital/withdraw/address/list
                https://developers.binance.com/docs/wallet/capital/fetch-withdraw-address

                Fetch withdraw address list

        Weight: 10

                Args:

                Returns:
                    ApiResponse[FetchWithdrawAddressListResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/capital/withdraw/address/list",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=FetchWithdrawAddressListResponse,
            is_signed=True,
            signer=self._signer,
        )

    def fetch_withdraw_quota(
        self,
    ) -> ApiResponse[FetchWithdrawQuotaResponse]:
        """
                Fetch withdraw quota (USER_DATA)
                GET /sapi/v1/capital/withdraw/quota
                https://developers.binance.com/docs/wallet/capital/Fetch-withdraw-quota

                Fetch withdraw quota

        Weight: 10

                Args:

                Returns:
                    ApiResponse[FetchWithdrawQuotaResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

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

    def one_click_arrival_deposit_apply(
        self,
        deposit_id: Optional[int] = None,
        tx_id: Optional[str] = None,
        sub_account_id: Optional[int] = None,
        sub_user_id: Optional[int] = None,
    ) -> ApiResponse[OneClickArrivalDepositApplyResponse]:
        """
                One click arrival deposit apply (for expired address deposit) (USER_DATA)
                POST /sapi/v1/capital/deposit/credit-apply
                https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply

                Apply deposit credit for expired address (One click arrival)

        * Params need to be in the POST body

        Weight: 1

                Args:
                    deposit_id (Optional[int] = None): Deposit record Id, priority use
                    tx_id (Optional[str] = None):
                    sub_account_id (Optional[int] = None): Sub-accountId of Cloud user
                    sub_user_id (Optional[int] = None): Sub-userId of parent user

                Returns:
                    ApiResponse[OneClickArrivalDepositApplyResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "deposit_id": deposit_id,
            "tx_id": tx_id,
            "sub_account_id": sub_account_id,
            "sub_user_id": sub_user_id,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/capital/deposit/credit-apply",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=OneClickArrivalDepositApplyResponse,
            is_signed=True,
            signer=self._signer,
        )

    def withdraw(
        self,
        coin: Union[str, None],
        address: Union[str, None],
        amount: Union[float, None],
        withdraw_order_id: Optional[str] = None,
        network: Optional[str] = None,
        address_tag: Optional[str] = None,
        transaction_fee_flag: Optional[bool] = None,
        name: Optional[str] = None,
        wallet_type: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[WithdrawResponse]:
        """
                Withdraw(USER_DATA)
                POST /sapi/v1/capital/withdraw/apply
                https://developers.binance.com/docs/wallet/capital/Withdraw

                Submit a withdraw request.


        * If `network` not send, return with default network of the coin.
        * You can get `network` and `isDefault` in `networkList` of a coin in the response of `Get /sapi/v1/capital/config/getall (HMAC SHA256)`.
        * To check if travel rule is required, by using  `GET /sapi/v1/localentity/questionnaire-requirements` and if it returns anything other than `NIL` you will need update SAPI to `POST /sapi/v1/localentity/withdraw/apply` else you can continue `POST /sapi/v1/capital/withdraw/apply`. Please note that if you are required to comply to travel rule please refer to the Travel Rule SAPI.

        Weight: 900

                Args:
                    coin (Union[str, None]):
                    address (Union[str, None]):
                    amount (Union[float, None]):
                    withdraw_order_id (Optional[str] = None): client side id for withdrawal, if provided in POST `/sapi/v1/capital/withdraw/apply`, can be used here for query.
                    network (Optional[str] = None):
                    address_tag (Optional[str] = None): Secondary address identifier for coins like XRP,XMR etc.
                    transaction_fee_flag (Optional[bool] = None): When making internal transfer, `true` for returning the fee to the destination account; `false` for returning the fee back to the departure account. Default `false`.
                    name (Optional[str] = None): Description of the address. Address book cap is 200, space in name should be encoded into `%20`
                    wallet_type (Optional[int] = None): The wallet type for withdraw，0-spot wallet ，1-funding wallet. Default walletType is the current "selected wallet" under wallet->Fiat and Spot/Funding->Deposit
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[WithdrawResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "coin": coin,
            "address": address,
            "amount": amount,
            "withdraw_order_id": withdraw_order_id,
            "network": network,
            "address_tag": address_tag,
            "transaction_fee_flag": transaction_fee_flag,
            "name": name,
            "wallet_type": wallet_type,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/capital/withdraw/apply",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=WithdrawResponse,
            is_signed=True,
            signer=self._signer,
        )

    def withdraw_history(
        self,
        coin: Optional[str] = None,
        withdraw_order_id: Optional[str] = None,
        status: Optional[int] = None,
        offset: Optional[int] = None,
        limit: Optional[int] = None,
        id_list: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[WithdrawHistoryResponse]:
        """
                Withdraw History (supporting network) (USER_DATA)
                GET /sapi/v1/capital/withdraw/history
                https://developers.binance.com/docs/wallet/capital/Withdraw-History

                Fetch withdraw history.

        * `network` may not be in the response for old withdraw.
        * Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.
        * If both `startTime` and `endTime`are sent, time between `startTime`and `endTime`must be less than 90 days.
        * If `withdrawOrderId` is sent, time between `startTime` and `endTime` must be less than 7 days.
        * If `withdrawOrderId` is sent, `startTime` and `endTime` are not sent, will return last 7 days records by default.
        * Maximum support `idList` number is 45.

        Weight: 18000
        Request limit: 10 requests per second

                Args:
                    coin (Optional[str] = None):
                    withdraw_order_id (Optional[str] = None): client side id for withdrawal, if provided in POST `/sapi/v1/capital/withdraw/apply`, can be used here for query.
                    status (Optional[int] = None): 0(0:Email Sent, 2:Awaiting Approval 3:Rejected 4:Processing 6:Completed)
                    offset (Optional[int] = None): Default: 0
                    limit (Optional[int] = None): min 7, max 30, default 7
                    id_list (Optional[str] = None): id list returned in the response of POST `/sapi/v1/capital/withdraw/apply`, separated by `,`
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[WithdrawHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "coin": coin,
            "withdraw_order_id": withdraw_order_id,
            "status": status,
            "offset": offset,
            "limit": limit,
            "id_list": id_list,
            "start_time": start_time,
            "end_time": end_time,
            "recv_window": recv_window,
        }

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