# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.commodity_types_list import CommodityTypesList
from ..types.cursor_page_t_customized_historical_raw_tick import CursorPageTCustomizedHistoricalRawTick
from ..types.cursor_page_t_customized_news_out import CursorPageTCustomizedNewsOut
from ..types.cursor_page_t_customized_symbols_out_full import CursorPageTCustomizedSymbolsOutFull
from ..types.historical_data_resolution import HistoricalDataResolution
from ..types.historical_ohlc_response import HistoricalOhlcResponse
from ..types.last_quote import LastQuote
from ..types.last_quotes import LastQuotes
from .raw_client import AsyncRawCommoditiesClient, RawCommoditiesClient


class CommoditiesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCommoditiesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawCommoditiesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawCommoditiesClient
        """
        return self._raw_client

    def get_quotes(
        self,
        *,
        symbols: str,
        precision: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LastQuotes:
        """
        Get the last quote tick for the provided symbols.

        Parameters
        ----------
        symbols : str
            Comma separated list of symbols.

        precision : typing.Optional[int]
            The decimal precision of the result.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        LastQuotes
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_quotes(
            symbols="symbols",
        )
        """
        _response = self._raw_client.get_quotes(symbols=symbols, precision=precision, request_options=request_options)
        return _response.data

    def get_quote(
        self,
        *,
        symbol: str,
        precision: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LastQuote:
        """
        Get the last quote tick for the provided symbol.

        Parameters
        ----------
        symbol : str
            The symbol to get the quote for.

        precision : typing.Optional[int]
            The decimal precision of the result.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        LastQuote
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_quote(
            symbol="GOLD",
            precision=2,
        )
        """
        _response = self._raw_client.get_quote(symbol=symbol, precision=precision, request_options=request_options)
        return _response.data

    def get_symbols(
        self,
        *,
        size: typing.Optional[int] = None,
        mode: typing.Optional[str] = None,
        type: typing.Optional[str] = None,
        country: typing.Optional[str] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedSymbolsOutFull:
        """
        Get list of available symbols

        Parameters
        ----------
        size : typing.Optional[int]
            The number of items per page.

        mode : typing.Optional[str]
            The mode of the response.

        type : typing.Optional[str]
            Type of the instrument.

        country : typing.Optional[str]
            Country of the instrument.

        cursor : typing.Optional[str]
            Cursor for the next page

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedSymbolsOutFull
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_symbols()
        """
        _response = self._raw_client.get_symbols(
            size=size, mode=mode, type=type, country=country, cursor=cursor, request_options=request_options
        )
        return _response.data

    def get_insights(
        self,
        *,
        cursor: typing.Optional[str] = None,
        size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedNewsOut:
        """
        Get recent commodities insights.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Cursor for the next page

        size : typing.Optional[int]
            The number of items per page.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedNewsOut
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_insights()
        """
        _response = self._raw_client.get_insights(cursor=cursor, size=size, request_options=request_options)
        return _response.data

    def get_types(self, *, request_options: typing.Optional[RequestOptions] = None) -> CommodityTypesList:
        """
        Get list of available commodity types

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CommodityTypesList
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_types()
        """
        _response = self._raw_client.get_types(request_options=request_options)
        return _response.data

    def get_historical_ohlc(
        self,
        symbol: str,
        *,
        resolution: HistoricalDataResolution,
        start: int,
        end: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HistoricalOhlcResponse:
        """
        Get historical OHLC candles for a symbol in a selected resolution and time range.

        Parameters
        ----------
        symbol : str

        resolution : HistoricalDataResolution
            Resolution in seconds.

        start : int
            Unix timestamp (inclusive).

        end : int
            Unix timestamp (exclusive).

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HistoricalOhlcResponse
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_historical_ohlc(
            symbol="symbol",
            resolution="5",
            start=1,
            end=1,
        )
        """
        _response = self._raw_client.get_historical_ohlc(
            symbol, resolution=resolution, start=start, end=end, request_options=request_options
        )
        return _response.data

    def get_historical_ticks(
        self,
        symbol: str,
        *,
        start: int,
        end: int,
        cursor: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedHistoricalRawTick:
        """
        Get raw historical ticks for a symbol in a selected time range using cursor pagination.

        Parameters
        ----------
        symbol : str

        start : int
            Unix timestamp (inclusive).

        end : int
            Unix timestamp (exclusive).

        cursor : typing.Optional[str]
            Cursor for the next page

        limit : typing.Optional[int]
            The number of ticks per page.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedHistoricalRawTick
            Successful Response

        Examples
        --------
        from tradewatch import TradewatchApi

        client = TradewatchApi(
            api_key="YOUR_API_KEY",
        )
        client.commodities.get_historical_ticks(
            symbol="symbol",
            start=1,
            end=1,
        )
        """
        _response = self._raw_client.get_historical_ticks(
            symbol, start=start, end=end, cursor=cursor, limit=limit, request_options=request_options
        )
        return _response.data


class AsyncCommoditiesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCommoditiesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawCommoditiesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawCommoditiesClient
        """
        return self._raw_client

    async def get_quotes(
        self,
        *,
        symbols: str,
        precision: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LastQuotes:
        """
        Get the last quote tick for the provided symbols.

        Parameters
        ----------
        symbols : str
            Comma separated list of symbols.

        precision : typing.Optional[int]
            The decimal precision of the result.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        LastQuotes
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_quotes(
                symbols="symbols",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_quotes(
            symbols=symbols, precision=precision, request_options=request_options
        )
        return _response.data

    async def get_quote(
        self,
        *,
        symbol: str,
        precision: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LastQuote:
        """
        Get the last quote tick for the provided symbol.

        Parameters
        ----------
        symbol : str
            The symbol to get the quote for.

        precision : typing.Optional[int]
            The decimal precision of the result.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        LastQuote
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_quote(
                symbol="GOLD",
                precision=2,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_quote(
            symbol=symbol, precision=precision, request_options=request_options
        )
        return _response.data

    async def get_symbols(
        self,
        *,
        size: typing.Optional[int] = None,
        mode: typing.Optional[str] = None,
        type: typing.Optional[str] = None,
        country: typing.Optional[str] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedSymbolsOutFull:
        """
        Get list of available symbols

        Parameters
        ----------
        size : typing.Optional[int]
            The number of items per page.

        mode : typing.Optional[str]
            The mode of the response.

        type : typing.Optional[str]
            Type of the instrument.

        country : typing.Optional[str]
            Country of the instrument.

        cursor : typing.Optional[str]
            Cursor for the next page

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedSymbolsOutFull
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_symbols()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_symbols(
            size=size, mode=mode, type=type, country=country, cursor=cursor, request_options=request_options
        )
        return _response.data

    async def get_insights(
        self,
        *,
        cursor: typing.Optional[str] = None,
        size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedNewsOut:
        """
        Get recent commodities insights.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Cursor for the next page

        size : typing.Optional[int]
            The number of items per page.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedNewsOut
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_insights()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_insights(cursor=cursor, size=size, request_options=request_options)
        return _response.data

    async def get_types(self, *, request_options: typing.Optional[RequestOptions] = None) -> CommodityTypesList:
        """
        Get list of available commodity types

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CommodityTypesList
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_types()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_types(request_options=request_options)
        return _response.data

    async def get_historical_ohlc(
        self,
        symbol: str,
        *,
        resolution: HistoricalDataResolution,
        start: int,
        end: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HistoricalOhlcResponse:
        """
        Get historical OHLC candles for a symbol in a selected resolution and time range.

        Parameters
        ----------
        symbol : str

        resolution : HistoricalDataResolution
            Resolution in seconds.

        start : int
            Unix timestamp (inclusive).

        end : int
            Unix timestamp (exclusive).

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HistoricalOhlcResponse
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_historical_ohlc(
                symbol="symbol",
                resolution="5",
                start=1,
                end=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_historical_ohlc(
            symbol, resolution=resolution, start=start, end=end, request_options=request_options
        )
        return _response.data

    async def get_historical_ticks(
        self,
        symbol: str,
        *,
        start: int,
        end: int,
        cursor: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CursorPageTCustomizedHistoricalRawTick:
        """
        Get raw historical ticks for a symbol in a selected time range using cursor pagination.

        Parameters
        ----------
        symbol : str

        start : int
            Unix timestamp (inclusive).

        end : int
            Unix timestamp (exclusive).

        cursor : typing.Optional[str]
            Cursor for the next page

        limit : typing.Optional[int]
            The number of ticks per page.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CursorPageTCustomizedHistoricalRawTick
            Successful Response

        Examples
        --------
        import asyncio

        from tradewatch import AsyncTradewatchApi

        client = AsyncTradewatchApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.commodities.get_historical_ticks(
                symbol="symbol",
                start=1,
                end=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_historical_ticks(
            symbol, start=start, end=end, cursor=cursor, limit=limit, request_options=request_options
        )
        return _response.data
