Alpa.Options.Contracts (AlpaEx v1.0.3)

View Source

Options contract operations for the Alpaca Trading API.

Summary

Functions

Get a specific option contract by symbol or ID.

Get option contracts with filtering.

Search for option contracts by underlying symbol with common filters.

Functions

get(symbol_or_id, opts \\ [])

@spec get(
  String.t(),
  keyword()
) :: {:ok, Alpa.Models.OptionContract.t()} | {:error, Alpa.Error.t()}

Get a specific option contract by symbol or ID.

Examples

iex> Alpa.Options.Contracts.get("AAPL230120C00150000")
{:ok, %Alpa.Models.OptionContract{...}}

list(opts \\ [])

@spec list(keyword()) ::
  {:ok,
   %{
     contracts: [Alpa.Models.OptionContract.t()],
     next_page_token: String.t() | nil
   }}
  | {:error, Alpa.Error.t()}

Get option contracts with filtering.

Options

  • :underlying_symbols - List of underlying symbols to filter by
  • :status - Contract status: "active", "inactive"
  • :expiration_date - Exact expiration date (Date or "YYYY-MM-DD")
  • :expiration_date_gte - Expiration date >= (Date or "YYYY-MM-DD")
  • :expiration_date_lte - Expiration date <= (Date or "YYYY-MM-DD")
  • :root_symbol - Option root symbol
  • :type - Option type: "call", "put"
  • :style - Option style: "american", "european"
  • :strike_price_gte - Strike price >=
  • :strike_price_lte - Strike price <=
  • :limit - Max contracts to return (default 100, max 10000)
  • :page_token - Pagination token

Examples

iex> Alpa.Options.Contracts.list(underlying_symbols: ["AAPL"], type: "call")
{:ok, %{contracts: [%Alpa.Models.OptionContract{...}], next_page_token: nil}}

search(underlying_symbol, opts \\ [])

@spec search(
  String.t(),
  keyword()
) ::
  {:ok,
   %{
     contracts: [Alpa.Models.OptionContract.t()],
     next_page_token: String.t() | nil
   }}
  | {:error, Alpa.Error.t()}

Search for option contracts by underlying symbol with common filters.

This is a convenience function that wraps list/1.

Examples

iex> Alpa.Options.Contracts.search("AAPL", type: :call, expiration_date_gte: ~D[2024-03-01])
{:ok, %{contracts: [...], next_page_token: nil}}