Class OptionAPI

This class provides an API for interacting with options in the Premia system. All methods are asynchronous and return promises.

Hierarchy

  • BaseAPI
    • OptionAPI

Constructors

Properties

premia: Premia

The Premia SDK instance.

streamIndex: number = 0

The current index of quote streams. Used to cancel stale streams.

Methods

  • Filters a list of pool objects according to the provided options.

    Parameters

    • pools: PoolMinimal[]

      An array of pool objects to filter.

    • Optional options: {
          maturity?: BigNumberish;
          priceOracle?: string;
          quoteTokens?: string[];
          strike?: BigNumberish;
      }

      An object containing filter conditions.

      • Optional maturity?: BigNumberish

        The maturity time.

      • Optional priceOracle?: string

        The address of the price oracle (optional).

      • Optional quoteTokens?: string[]

        Array of quote tokens' addresses (optional).

      • Optional strike?: BigNumberish

        The strike price.

    Returns PoolMinimal[]

    • The filtered array of pool objects.
  • Parses a token input to return a token address string.

    Parameters

    • token: TokenOrAddress

      The token input which can be either a Token object or a string representing the address.

    Returns string

    • The token address as a string.
  • Cancels all ongoing streams.

    Returns Promise<void>

  • Cancels the streaming of quotes for the provided pool address, isCall, and isBuy parameters.

    Parameters

    • poolAddress: string

      The pool address.

    • isCall: boolean

      Whether the quote is for a call option.

    • isBuy: boolean

      Whether the quote is for a buy or sell.

    Returns Promise<void>

  • Gets the implied volatility for a given pool, price, and spot price. The implied volatility is calculated using the Black-Scholes model.

    Parameters

    • pool: PoolMinimal

      {PoolMinimal} The pool object.

    • price: BigNumberish

      {BigNumberish} The price of the option.

    • spotPrice: BigNumberish

      {BigNumberish} The spot price of the underlying asset.

    Returns number

    The implied volatility of the option.

  • Gets the profit or loss for a given pool, action (buy/sell), and premium.

    Parameters

    • poolAddress: string

      The address of the pool.

    • isBuy: boolean

      Whether the action is a buy.

    • premium: BigNumberish

      The premium for the transaction.

    • Optional provider: Provider

      The custom provider to use for this call.

    Returns Promise<bigint>

    • A promise that resolves to the calculated profit or loss.
  • Calculates the strike interval size for a specific price.

    Parameters

    • price: number

      The price.

    Returns number

    The strike interval size.

  • Generates a list of suggested strike prices based on the spot price.

    Parameters

    • spotPrice: number

      The spot price.

    Returns number[]

    • An array of suggested strike prices.
  • Provides the best quotes available for each pool that matches the provided options.

    Parameters

    • options: {
          isBuy: boolean;
          isCall: boolean;
          maturity: BigNumberish;
          minimumSize?: BigNumberish;
          priceOracle?: string;
          quoteTokens?: string[];
          referrer?: string;
          size: BigNumberish;
          strike: BigNumberish;
          taker?: string;
          token: TokenOrAddress;
      }

      Multi-quote options object.

      • isBuy: boolean

        Whether the quote is for a buy or sell.

      • isCall: boolean

        Whether the quote is for a call option.

      • maturity: BigNumberish

        The maturity time.

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional priceOracle?: string

        The address of the price oracle (optional).

      • Optional quoteTokens?: string[]

        Array of quote tokens' addresses (optional).

      • Optional referrer?: string

        The address of the referrer (optional).

      • size: BigNumberish

        The size of the trade.

      • strike: BigNumberish

        The strike price.

      • Optional taker?: string

        The address of the taker (optional).

      • token: TokenOrAddress

        The token object or address.

    Returns Promise<(null | FillableQuote)[]>

    • A promise that resolves to an array of the best quotes.
  • Provides the best quote available from different sources (RFQ, Pool, Vault) based on the provided options.

    Parameters

    • options: {
          isBuy: boolean;
          maxSlippagePercent?: number;
          minimumSize?: BigNumberish;
          pool?: PoolMinimal;
          poolAddress: string;
          poolKey?: PoolKey;
          referrer?: string;
          showErrors?: boolean;
          showOrderbookErrors?: boolean;
          showPoolErrors?: boolean;
          showVaultErrors?: boolean;
          size: BigNumberish;
          taker?: string;
      }

      Quote options object.

      • isBuy: boolean

        Whether the quote is a buy or sell.

      • Optional maxSlippagePercent?: number

        The maximum slippage percent (optional).

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional pool?: PoolMinimal
      • poolAddress: string

        The pool's address.

      • Optional poolKey?: PoolKey
      • Optional referrer?: string

        The address of the referrer (optional).

      • Optional showErrors?: boolean

        Whether to show errors (optional).

      • Optional showOrderbookErrors?: boolean

        Whether to show orderbook errors (optional).

      • Optional showPoolErrors?: boolean

        Whether to show pool errors (optional).

      • Optional showVaultErrors?: boolean

        Whether to show vault errors (optional).

      • size: BigNumberish

        The size of the trade.

      • Optional taker?: string

        The address of the taker (optional).

    Returns Promise<FillableQuote>

    • A promise that resolves to the best quote.
  • Provides the best quotes available from each provider (RFQ, Pool, Vault) for each pool that matches the provided options.

    Parameters

    • options: {
          isBuy: boolean;
          isCall: boolean;
          maturity: BigNumberish;
          minimumSize?: BigNumberish;
          priceOracle?: string;
          quoteTokens?: string[];
          referrer?: string;
          size: BigNumberish;
          strike: BigNumberish;
          taker?: string;
          token: TokenOrAddress;
      }

      Quotes by provider options object.

      • isBuy: boolean

        Whether the quote is for a buy or sell.

      • isCall: boolean

        Whether the quote is for a call option.

      • maturity: BigNumberish

        The maturity time.

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional priceOracle?: string

        The address of the price oracle (optional).

      • Optional quoteTokens?: string[]

        Array of quote tokens' addresses (optional).

      • Optional referrer?: string

        The address of the referrer (optional).

      • size: BigNumberish

        The size of the trade.

      • strike: BigNumberish

        The strike price.

      • Optional taker?: string

        The address of the taker (optional).

      • token: TokenOrAddress

        The token object or address.

    Returns Promise<{
        [provider: string]: (FillableQuote | null)[];
    }>

    • A promise that resolves to an object where each key is a provider and the value is an array of the best quotes.
  • Streams best quotes available for each pool that matches the provided options. Quotes are updated in real-time and passed to a callback.

    Parameters

    • options: {
          isBuy: boolean;
          isCall: boolean;
          maturity: BigNumberish;
          maxSlippagePercent?: number;
          minimumSize?: BigNumberish;
          priceOracle?: string;
          quoteTokens?: string[];
          referrer?: string;
          size: BigNumberish;
          strike: BigNumberish;
          taker?: string;
          token: TokenOrAddress;
      }

      Quote options object.

      • isBuy: boolean

        Whether the quote is for a buy or sell.

      • isCall: boolean

        Whether the quote is for a call option.

      • maturity: BigNumberish

        The maturity time.

      • Optional maxSlippagePercent?: number

        The maximum slippage percent (optional).

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional priceOracle?: string

        The address of the price oracle (optional).

      • Optional quoteTokens?: string[]

        Array of quote tokens' addresses (optional).

      • Optional referrer?: string

        The address of the referrer (optional).

      • size: BigNumberish

        The size of the trade.

      • strike: BigNumberish

        The strike price.

      • Optional taker?: string

        The address of the taker (optional).

      • token: TokenOrAddress

        The token object or address.

    • callback: ((quotes) => void)

      Function to be called when new quotes are available.

        • (quotes): void
        • Parameters

          Returns void

    Returns Promise<void>

  • Streams the best quotes available from each provider (RFQ, Pool, Vault) for the pool that matches the provided options. The best quote among all providers is updated in real-time and passed to a callback.

    Parameters

    • options: {
          forceSendRFQ?: boolean;
          isBuy: boolean;
          maxSlippagePercent?: number;
          minimumSize?: BigNumberish;
          pool?: PoolMinimal;
          poolAddress: string;
          poolKey?: PoolKey;
          referrer?: string;
          size: BigNumberish;
          taker?: string;
      }

      Quote options object.

      • Optional forceSendRFQ?: boolean

        Whether to force sending/listening for Request-for-Quotes (optional).

      • isBuy: boolean

        Whether the quote is for a buy or sell.

      • Optional maxSlippagePercent?: number

        The maximum slippage percent (optional).

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional pool?: PoolMinimal
      • poolAddress: string

        The pool address.

      • Optional poolKey?: PoolKey
      • Optional referrer?: string

        The address of the referrer (optional).

      • size: BigNumberish

        The size of the trade.

      • Optional taker?: string

        The address of the taker (optional).

    • callback: ((quote) => void)

      Function to be called when a new best quote is available.

        • (quote): void
        • Parameters

          Returns void

    Returns Promise<void>

  • Streams best quotes available from each provider (RFQ, Pool, Vault) for each pool that matches the provided options. Quotes are updated in real-time and passed to a callback.

    Parameters

    • options: {
          forceSendRFQ?: boolean;
          isBuy: boolean;
          isCall: boolean;
          maturity: BigNumberish;
          maxSlippagePercent?: number;
          minimumSize?: BigNumberish;
          priceOracle?: string;
          quoteTokens?: string[];
          referrer?: string;
          size: BigNumberish;
          strike: BigNumberish;
          taker?: string;
          token: TokenOrAddress;
      }

      Quote options object.

      • Optional forceSendRFQ?: boolean

        Whether to force sending/listening for Request-for-Quotes (optional).

      • isBuy: boolean

        Whether the quote is for a buy or sell.

      • isCall: boolean

        Whether the quote is for a call option.

      • maturity: BigNumberish

        The maturity time.

      • Optional maxSlippagePercent?: number

        The maximum slippage percent (optional).

      • Optional minimumSize?: BigNumberish

        The minimum size of the trade (optional).

      • Optional priceOracle?: string

        The address of the price oracle (optional).

      • Optional quoteTokens?: string[]

        Array of quote tokens' addresses (optional).

      • Optional referrer?: string

        The address of the referrer (optional).

      • size: BigNumberish

        The size of the trade.

      • strike: BigNumberish

        The strike price.

      • Optional taker?: string

        The address of the taker (optional).

      • token: TokenOrAddress

        The token object or address.

    • callback: ((quotes) => void)

      Function to be called when new quotes are available.

        • (quotes): void
        • Parameters

          Returns void

    Returns Promise<void>

Generated using TypeDoc