"""
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 BasisResponse
from ..models import CheckServerTimeResponse
from ..models import CompressedAggregateTradesListResponse
from ..models import ContinuousContractKlineCandlestickDataResponse
from ..models import ExchangeInformationResponse
from ..models import GetFundingRateHistoryOfPerpetualFuturesResponse
from ..models import GetFundingRateInfoResponse
from ..models import IndexPriceAndMarkPriceResponse
from ..models import IndexPriceKlineCandlestickDataResponse
from ..models import KlineCandlestickDataResponse
from ..models import LongShortRatioResponse
from ..models import MarkPriceKlineCandlestickDataResponse
from ..models import OldTradesLookupResponse
from ..models import OpenInterestResponse
from ..models import OpenInterestStatisticsResponse
from ..models import OrderBookResponse
from ..models import PremiumIndexKlineDataResponse
from ..models import QueryIndexPriceConstituentsResponse
from ..models import RecentTradesListResponse
from ..models import SymbolOrderBookTickerResponse
from ..models import SymbolPriceTickerResponse
from ..models import TakerBuySellVolumeResponse

from ..models import Ticker24hrPriceChangeStatisticsResponse
from ..models import TopTraderLongShortRatioAccountsResponse
from ..models import TopTraderLongShortRatioPositionsResponse


from ..models import BasisContractTypeEnum
from ..models import BasisPeriodEnum
from ..models import ContinuousContractKlineCandlestickDataContractTypeEnum
from ..models import ContinuousContractKlineCandlestickDataIntervalEnum
from ..models import IndexPriceKlineCandlestickDataIntervalEnum
from ..models import KlineCandlestickDataIntervalEnum
from ..models import LongShortRatioPeriodEnum
from ..models import MarkPriceKlineCandlestickDataIntervalEnum
from ..models import OpenInterestStatisticsContractTypeEnum
from ..models import OpenInterestStatisticsPeriodEnum
from ..models import PremiumIndexKlineDataIntervalEnum
from ..models import TakerBuySellVolumeContractTypeEnum
from ..models import TakerBuySellVolumePeriodEnum
from ..models import TopTraderLongShortRatioAccountsPeriodEnum
from ..models import TopTraderLongShortRatioPositionsPeriodEnum


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 basis(
        self,
        pair: Union[str, None],
        contract_type: Union[BasisContractTypeEnum, None],
        period: Union[BasisPeriodEnum, None],
        limit: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
    ) -> ApiResponse[BasisResponse]:
        """
                Basis
                GET /futures/data/basis
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Basis

                Query basis

        * If startTime and endTime are not sent, the most recent data is returned.
        * Only the data of the latest 30 days is available.

        Weight: 1

                Args:
                    pair (Union[str, None]): BTCUSD
                    contract_type (Union[BasisContractTypeEnum, None]): ALL, CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL
                    period (Union[BasisPeriodEnum, None]): "5m","15m","30m","1h","2h","4h","6h","12h","1d"
                    limit (Optional[int] = None): Default 100; max 1000
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):

                Returns:
                    ApiResponse[BasisResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "pair": pair,
            "contract_type": contract_type,
            "period": period,
            "limit": limit,
            "start_time": start_time,
            "end_time": end_time,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/futures/data/basis",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=BasisResponse,
        )

    def check_server_time(
        self,
    ) -> ApiResponse[CheckServerTimeResponse]:
        """
                Check Server time
                GET /dapi/v1/time
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Check-Server-time

                Test connectivity to the Rest API and get the current server time.

        Weight: 1

                Args:

                Returns:
                    ApiResponse[CheckServerTimeResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/time",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CheckServerTimeResponse,
        )

    def compressed_aggregate_trades_list(
        self,
        symbol: Union[str, None],
        from_id: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[CompressedAggregateTradesListResponse]:
        """
                Compressed/Aggregate Trades List
                GET /dapi/v1/aggTrades
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List

                Get compressed, aggregate trades. Market trades that fill in 100ms with the same price and the same taking side will have the quantity aggregated.

        * support querying futures trade histories that are not older than one year
        * If both `startTime` and `endTime` are sent, time between `startTime` and `endTime` must be less than 1 hour.
        * If `fromId`, `startTime`, and `endTime` are not sent, the most recent aggregate trades will be returned.
        * Only market trades will be aggregated and returned, which means the insurance fund trades and ADL trades won't be aggregated.
        * Sending both `startTime`/`endTime` and `fromId` might cause response timeout, please send either `fromId` or `startTime`/`endTime`

        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    from_id (Optional[int] = None): ID to get aggregate trades from INCLUSIVE.
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[CompressedAggregateTradesListResponse]

                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,
            "from_id": from_id,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/aggTrades",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CompressedAggregateTradesListResponse,
        )

    def continuous_contract_kline_candlestick_data(
        self,
        pair: Union[str, None],
        contract_type: Union[
            ContinuousContractKlineCandlestickDataContractTypeEnum, None
        ],
        interval: Union[ContinuousContractKlineCandlestickDataIntervalEnum, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[ContinuousContractKlineCandlestickDataResponse]:
        """
                Continuous Contract Kline/Candlestick Data
                GET /dapi/v1/continuousKlines
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data

                Kline/candlestick bars for a specific contract type.
        Klines are uniquely identified by their open time.

        * Contract type:
        * PERPETUAL
        * CURRENT_QUARTER
        * NEXT_QUARTER


        1000 | 10
        * The difference between `startTime` and `endTime` can only be up to 200 days
        * Between `startTime` and `endTime`, the most recent `limit` data from `endTime` will be returned:
        * If `startTime` and `endTime` are not sent, current timestamp will be set as `endTime`, and the most recent data will be returned.
        * If `startTime` is sent only, the timestamp of 200 days after `startTime` will be set as `endTime`(up to the current time)
        * If `endTime` is sent only, the timestamp of 200 days before `endTime` will be set as `startTime`

        Weight: based on parameter LIMIT
        LIMIT | weight
        ---|---
        [1,100) | 1
        [100, 500) | 2
        [500, 1000] | 5
        > 1000 | 10

                Args:
                    pair (Union[str, None]): BTCUSD
                    contract_type (Union[ContinuousContractKlineCandlestickDataContractTypeEnum, None]): ALL, CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL
                    interval (Union[ContinuousContractKlineCandlestickDataIntervalEnum, None]):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[ContinuousContractKlineCandlestickDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "pair": pair,
            "contract_type": contract_type,
            "interval": interval,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/continuousKlines",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ContinuousContractKlineCandlestickDataResponse,
        )

    def exchange_information(
        self,
    ) -> ApiResponse[ExchangeInformationResponse]:
        """
                Exchange Information
                GET /dapi/v1/exchangeInfo
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information

                Current exchange trading rules and symbol information

        Weight: 1

                Args:

                Returns:
                    ApiResponse[ExchangeInformationResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

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

    def get_funding_rate_history_of_perpetual_futures(
        self,
        symbol: Union[str, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[GetFundingRateHistoryOfPerpetualFuturesResponse]:
        """
                Get Funding Rate History of Perpetual Futures
                GET /dapi/v1/fundingRate
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Rate-History-of-Perpetual-Futures

                Get Funding Rate History of Perpetual Futures

        * empty array will be returned for delivery symbols.

        Weight: 1

                Args:
                    symbol (Union[str, None]):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[GetFundingRateHistoryOfPerpetualFuturesResponse]

                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,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/fundingRate",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetFundingRateHistoryOfPerpetualFuturesResponse,
        )

    def get_funding_rate_info(
        self,
    ) -> ApiResponse[GetFundingRateInfoResponse]:
        """
                Get Funding Rate Info
                GET /dapi/v1/fundingInfo
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Info

                Query funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment

        Weight: 0

                Args:

                Returns:
                    ApiResponse[GetFundingRateInfoResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/fundingInfo",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetFundingRateInfoResponse,
        )

    def index_price_and_mark_price(
        self,
        symbol: Optional[str] = None,
        pair: Optional[str] = None,
    ) -> ApiResponse[IndexPriceAndMarkPriceResponse]:
        """
                Index Price and Mark Price
                GET /dapi/v1/premiumIndex
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price

                Query index price and mark price

        Weight: 10

                Args:
                    symbol (Optional[str] = None):
                    pair (Optional[str] = None):

                Returns:
                    ApiResponse[IndexPriceAndMarkPriceResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/premiumIndex",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=IndexPriceAndMarkPriceResponse,
        )

    def index_price_kline_candlestick_data(
        self,
        pair: Union[str, None],
        interval: Union[IndexPriceKlineCandlestickDataIntervalEnum, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[IndexPriceKlineCandlestickDataResponse]:
        """
                Index Price Kline/Candlestick Data
                GET /dapi/v1/indexPriceKlines
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data

                Kline/candlestick bars for the index price of a pair. Klines are uniquely identified by their open time.


        1000 | 10
        * The difference between `startTime` and `endTime` can only be up to 200 days
        * Between `startTime` and `endTime`, the most recent `limit` data from `endTime` will be returned:
        * If `startTime` and `endTime` are not sent, current timestamp will be set as `endTime`, and the most recent data will be returned.
        * If `startTime` is sent only, the timestamp of 200 days after `startTime` will be set as `endTime`(up to the current time)
        * If `endTime` is sent only, the timestamp of 200 days before `endTime` will be set as `startTime`

        Weight: based on parameter LIMIT
        LIMIT | weight
        ---|---
        [1,100) | 1
        [100, 500) | 2
        [500, 1000] | 5
        > 1000 | 10

                Args:
                    pair (Union[str, None]): BTCUSD
                    interval (Union[IndexPriceKlineCandlestickDataIntervalEnum, None]):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[IndexPriceKlineCandlestickDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "pair": pair,
            "interval": interval,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/indexPriceKlines",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=IndexPriceKlineCandlestickDataResponse,
        )

    def kline_candlestick_data(
        self,
        symbol: Union[str, None],
        interval: Union[KlineCandlestickDataIntervalEnum, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[KlineCandlestickDataResponse]:
        """
                Kline/Candlestick Data
                GET /dapi/v1/klines
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data

                Kline/candlestick bars for a symbol.
        Klines are uniquely identified by their open time.

        1000 | 10
        * The difference between `startTime` and `endTime` can only be up to 200 days
        * Between `startTime` and `endTime`, the most recent `limit` data from `endTime` will be returned:
        * If `startTime` and `endTime` are not sent, current timestamp will be set as `endTime`, and the most recent data will be returned.
        * If `startTime` is sent only, the timestamp of 200 days after `startTime` will be set as `endTime`(up to the current time)
        * If `endTime` is sent only, the timestamp of 200 days before `endTime` will be set as `startTime`

        Weight: based on parameter LIMIT
        LIMIT | weight
        ---|---
        [1,100) | 1
        [100, 500) | 2
        [500, 1000] | 5
        > 1000 | 10

                Args:
                    symbol (Union[str, None]):
                    interval (Union[KlineCandlestickDataIntervalEnum, None]):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[KlineCandlestickDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "interval": interval,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/klines",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=KlineCandlestickDataResponse,
        )

    def long_short_ratio(
        self,
        pair: Union[str, None],
        period: Union[LongShortRatioPeriodEnum, None],
        limit: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
    ) -> ApiResponse[LongShortRatioResponse]:
        """
                Long/Short Ratio
                GET /futures/data/globalLongShortAccountRatio
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Long-Short-Ratio

                Query symbol Long/Short Ratio

        * If startTime and endTime are not sent, the most recent data is returned.
        * Only the data of the latest 30 days is available.

        Weight: 1

                Args:
                    pair (Union[str, None]): BTCUSD
                    period (Union[LongShortRatioPeriodEnum, None]): "5m","15m","30m","1h","2h","4h","6h","12h","1d"
                    limit (Optional[int] = None): Default 100; max 1000
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):

                Returns:
                    ApiResponse[LongShortRatioResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "pair": pair,
            "period": period,
            "limit": limit,
            "start_time": start_time,
            "end_time": end_time,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/futures/data/globalLongShortAccountRatio",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=LongShortRatioResponse,
        )

    def mark_price_kline_candlestick_data(
        self,
        symbol: Union[str, None],
        interval: Union[MarkPriceKlineCandlestickDataIntervalEnum, None],
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> ApiResponse[MarkPriceKlineCandlestickDataResponse]:
        """
                Mark Price Kline/Candlestick Data
                GET /dapi/v1/markPriceKlines
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data

                Kline/candlestick bars for the mark price of a symbol.
        Klines are uniquely identified by their open time.


        1000 | 10
        * The difference between `startTime` and `endTime` can only be up to 200 days
        * Between `startTime` and `endTime`, the most recent `limit` data from `endTime` will be returned:
        * If `startTime` and `endTime` are not sent, current timestamp will be set as `endTime`, and the most recent data will be returned.
        * If `startTime` is sent only, the timestamp of 200 days after `startTime` will be set as `endTime`(up to the current time)
        * If `endTime` is sent only, the timestamp of 200 days before `endTime` will be set as `startTime`

        Weight: based on parameter LIMIT
        LIMIT | weight
        ---|---
        [1,100) | 1
        [100, 500) | 2
        [500, 1000] | 5
        > 1000 | 10

                Args:
                    symbol (Union[str, None]):
                    interval (Union[MarkPriceKlineCandlestickDataIntervalEnum, None]):
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): Default 100; max 1000

                Returns:
                    ApiResponse[MarkPriceKlineCandlestickDataResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "symbol": symbol,
            "interval": interval,
            "start_time": start_time,
            "end_time": end_time,
            "limit": limit,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/markPriceKlines",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=MarkPriceKlineCandlestickDataResponse,
        )

    def old_trades_lookup(
        self,
        symbol: Union[str, None],
        limit: Optional[int] = None,
        from_id: Optional[int] = None,
    ) -> ApiResponse[OldTradesLookupResponse]:
        """
                Old Trades Lookup(MARKET_DATA)
                GET /dapi/v1/historicalTrades
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Old-Trades-Lookup

                Get older market historical trades.

        * Market trades means trades filled in the order book. Only market trades will be returned, which means the insurance fund trades and ADL trades won't be returned.

        Weight: 20

                Args:
                    symbol (Union[str, None]):
                    limit (Optional[int] = None): Default 100; max 1000
                    from_id (Optional[int] = None): ID to get aggregate trades from INCLUSIVE.

                Returns:
                    ApiResponse[OldTradesLookupResponse]

                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, "limit": limit, "from_id": from_id}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/historicalTrades",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=OldTradesLookupResponse,
        )

    def open_interest(
        self,
        symbol: Union[str, None],
    ) -> ApiResponse[OpenInterestResponse]:
        """
                Open Interest
                GET /dapi/v1/openInterest
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest

                Get present open interest of a specific symbol.

        Weight: 1

                Args:
                    symbol (Union[str, None]):

                Returns:
                    ApiResponse[OpenInterestResponse]

                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}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/dapi/v1/openInterest",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=OpenInterestResponse,
        )

    def open_interest_statistics(
        self,
        pair: Union[str, None],
        contract_type: Union[OpenInterestStatisticsContractTypeEnum, None],
        period: Union[OpenInterestStatisticsPeriodEnum, None],
        limit: Optional[int] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
    ) -> ApiResponse[OpenInterestStatisticsResponse]:
        """
                Open Interest Statistics
                GET /futures/data/openInterestHist
                https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest-Statistics

                Query open interest stats


        * If startTime and endTime are not sent, the most recent data is returned.
        * Only the data of the latest 30 days is available.

        Weight: 1

                Args:
                    pair (Union[str, None]): BTCUSD
                    contract_type (Union[OpenInterestStatisticsContractTypeEnum, None]): ALL, CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL
                    period (Union[OpenInterestStatisticsPeriodEnum, None]): "5m","15m","30m","1h","2h","4h","6h","12h","1d"
                    limit (Optional[int] = None): Default 100; max 1000
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):

