"""
Options API namespace.

AUTO-GENERATED by scripts/generate_sdk.py - DO NOT EDIT MANUALLY!
Regenerate with: python scripts/generate_sdk.py --category options
"""
from __future__ import annotations

from typing import Any, Dict, List, Optional

from ._base import AsyncBaseAPI, BaseAPI


class OptionsAPI(BaseAPI):
    """Options namespace: greeks, iv, payoff, price, pricing, strategies, strategy."""

    def greeks(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Calculate Greeks

        Delta, gamma, theta, vega, rho.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return self._call("options.greeks", params=params, options=options, context=context)

    def iv(
        self,
        *,
        market_price: float,
        spot: float,
        strike: float,
        time_to_expiry: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Implied volatility

        Calculate implied volatility from price.

        Args:
        market_price: Option market price
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["market_price"] = market_price
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return self._call("options.iv", params=params, options=options, context=context)

    def payoff(
        self,
        *,
        legs: List[Any],
        spot_range: Optional[List[Any]] = None,
        spot: Optional[float] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Calculate payoff

        Calculate payoff at expiry.

        Args:
        legs: Strategy legs
        spot_range: Spot price range [min, max]
        spot: Current spot price"""
        params: Dict[str, Any] = {}
        params["legs"] = legs
        if spot_range is not None:
            params["spot_range"] = spot_range
        if spot is not None:
            params["spot"] = spot
        return self._call("options.payoff", params=params, options=options, context=context)

    def price(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price option

        Calculate option price using Black-Scholes.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return self._call("options.price", params=params, options=options, context=context)

    def pricing(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price option (alias of options.price)

        Alias for options.price. Use options.price instead.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        return self._call("options.pricing", params=params, options=options, context=context)

    def strategies(
        self,
        *,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """List strategies

        List predefined option strategies."""
        params: Dict[str, Any] = {}
        return self._call("options.strategies", params=params, options=options, context=context)

    def strategy(
        self,
        *,
        strategy_type: str,
        spot: float,
        legs: Optional[List[Any]] = None,
        volatility: Optional[float] = None,
        time_to_expiry: Optional[float] = None,
        risk_free_rate: Optional[float] = 0.03,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price strategy

        Price multi-leg option strategy.

        Args:
        strategy_type: Strategy type
        spot: Underlying price
        legs: Strategy legs (for custom)
        volatility: Volatility
        time_to_expiry: Time to expiry
        risk_free_rate: Risk-free rate"""
        params: Dict[str, Any] = {}
        params["strategy_type"] = strategy_type
        params["spot"] = spot
        if legs is not None:
            params["legs"] = legs
        if volatility is not None:
            params["volatility"] = volatility
        if time_to_expiry is not None:
            params["time_to_expiry"] = time_to_expiry
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        return self._call("options.strategy", params=params, options=options, context=context)



class AsyncOptionsAPI(AsyncBaseAPI):
    """Options namespace: greeks, iv, payoff, price, pricing, strategies, strategy."""

    async def greeks(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Calculate Greeks

        Delta, gamma, theta, vega, rho.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return await self._call("options.greeks", params=params, options=options, context=context)

    async def iv(
        self,
        *,
        market_price: float,
        spot: float,
        strike: float,
        time_to_expiry: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Implied volatility

        Calculate implied volatility from price.

        Args:
        market_price: Option market price
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["market_price"] = market_price
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return await self._call("options.iv", params=params, options=options, context=context)

    async def payoff(
        self,
        *,
        legs: List[Any],
        spot_range: Optional[List[Any]] = None,
        spot: Optional[float] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Calculate payoff

        Calculate payoff at expiry.

        Args:
        legs: Strategy legs
        spot_range: Spot price range [min, max]
        spot: Current spot price"""
        params: Dict[str, Any] = {}
        params["legs"] = legs
        if spot_range is not None:
            params["spot_range"] = spot_range
        if spot is not None:
            params["spot"] = spot
        return await self._call("options.payoff", params=params, options=options, context=context)

    async def price(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        risk_free_rate: Optional[float] = 0.03,
        option_type: Optional[str] = "call",
        dividend_yield: Optional[float] = 0.0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price option

        Calculate option price using Black-Scholes.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility
        risk_free_rate: Risk-free rate
        option_type: call|put
        dividend_yield: Dividend yield"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        if option_type is not None:
            params["option_type"] = option_type
        if dividend_yield is not None:
            params["dividend_yield"] = dividend_yield
        return await self._call("options.price", params=params, options=options, context=context)

    async def pricing(
        self,
        *,
        spot: float,
        strike: float,
        time_to_expiry: float,
        volatility: float,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price option (alias of options.price)

        Alias for options.price. Use options.price instead.

        Args:
        spot: Underlying price
        strike: Strike price
        time_to_expiry: Time to expiry (years)
        volatility: Volatility"""
        params: Dict[str, Any] = {}
        params["spot"] = spot
        params["strike"] = strike
        params["time_to_expiry"] = time_to_expiry
        params["volatility"] = volatility
        return await self._call("options.pricing", params=params, options=options, context=context)

    async def strategies(
        self,
        *,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """List strategies

        List predefined option strategies."""
        params: Dict[str, Any] = {}
        return await self._call("options.strategies", params=params, options=options, context=context)

    async def strategy(
        self,
        *,
        strategy_type: str,
        spot: float,
        legs: Optional[List[Any]] = None,
        volatility: Optional[float] = None,
        time_to_expiry: Optional[float] = None,
        risk_free_rate: Optional[float] = 0.03,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Price strategy

        Price multi-leg option strategy.

        Args:
        strategy_type: Strategy type
        spot: Underlying price
        legs: Strategy legs (for custom)
        volatility: Volatility
        time_to_expiry: Time to expiry
        risk_free_rate: Risk-free rate"""
        params: Dict[str, Any] = {}
        params["strategy_type"] = strategy_type
        params["spot"] = spot
        if legs is not None:
            params["legs"] = legs
        if volatility is not None:
            params["volatility"] = volatility
        if time_to_expiry is not None:
            params["time_to_expiry"] = time_to_expiry
        if risk_free_rate is not None:
            params["risk_free_rate"] = risk_free_rate
        return await self._call("options.strategy", params=params, options=options, context=context)


