"""
Binance Convert REST API

OpenAPI Specification for the Binance Convert 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
from requests import Session
from binance_common.configuration import ConfigurationRestAPI
from binance_common.models import ApiResponse
from binance_common.signature import Signers
from binance_common.utils import send_request

from ..models import ListAllConvertPairsResponse
from ..models import QueryOrderQuantityPrecisionPerAssetResponse


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

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

    def list_all_convert_pairs(
        self,
        from_asset: Optional[str] = None,
        to_asset: Optional[str] = None,
    ) -> ApiResponse[ListAllConvertPairsResponse]:
        """
                List All Convert Pairs
                GET /sapi/v1/convert/exchangeInfo
                https://developers.binance.com/docs/convert/market-data/

                Query for all convertible token pairs and the tokens’ respective upper/lower limits

        * User needs to supply either or both of the input parameter
        * If not defined for both fromAsset and toAsset, only partial token pairs will be returned

        Weight: 3000(IP)

                Args:
                    from_asset (Optional[str] = None): User spends coin
                    to_asset (Optional[str] = None): User receives coin

                Returns:
                    ApiResponse[ListAllConvertPairsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"from_asset": from_asset, "to_asset": to_asset}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/convert/exchangeInfo",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ListAllConvertPairsResponse,
        )

    def query_order_quantity_precision_per_asset(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[QueryOrderQuantityPrecisionPerAssetResponse]:
        """
                Query order quantity precision per asset(USER_DATA)
                GET /sapi/v1/convert/assetInfo
                https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset

                Query for supported asset’s precision information

        Weight: 100(IP)

                Args:
                    recv_window (Optional[int] = None): The value cannot be greater than 60000

                Returns:
                    ApiResponse[QueryOrderQuantityPrecisionPerAssetResponse]

                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/convert/assetInfo",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=QueryOrderQuantityPrecisionPerAssetResponse,
            is_signed=True,
            signer=self._signer,
        )
