Alpa.Trading.Market (AlpaEx v1.0.3)

View Source

Market clock and calendar operations for the Alpaca Trading API.

Summary

Functions

Get the market calendar.

Get the current market clock.

Get the next market close time.

Get the next market open time.

Check if the market is currently open.

Functions

get_calendar(opts \\ [])

@spec get_calendar(keyword()) ::
  {:ok, [Alpa.Models.Calendar.t()]} | {:error, Alpa.Error.t()}

Get the market calendar.

Returns trading days and their open/close times for a date range.

Options

  • :start - Start date (format: "YYYY-MM-DD" or Date)
  • :end - End date (format: "YYYY-MM-DD" or Date)

Examples

iex> Alpa.Trading.Market.get_calendar(start: ~D[2024-01-01], end: ~D[2024-01-31])
{:ok, [
  %{"date" => "2024-01-02", "open" => "09:30", "close" => "16:00", ...},
  ...
]}

get_clock(opts \\ [])

@spec get_clock(keyword()) :: {:ok, Alpa.Models.Clock.t()} | {:error, Alpa.Error.t()}

Get the current market clock.

Returns whether the market is open and the next open/close times.

Examples

iex> Alpa.Trading.Market.get_clock()
{:ok, %Alpa.Models.Clock{
  timestamp: ~U[2024-01-15 14:30:00Z],
  is_open: true,
  next_open: ~U[2024-01-16 14:30:00Z],
  next_close: ~U[2024-01-15 21:00:00Z]
}}

next_close(opts \\ [])

@spec next_close(keyword()) :: {:ok, DateTime.t()} | {:error, Alpa.Error.t()}

Get the next market close time.

Examples

iex> Alpa.Trading.Market.next_close()
{:ok, ~U[2024-01-15 21:00:00Z]}

next_open(opts \\ [])

@spec next_open(keyword()) :: {:ok, DateTime.t()} | {:error, Alpa.Error.t()}

Get the next market open time.

Examples

iex> Alpa.Trading.Market.next_open()
{:ok, ~U[2024-01-16 14:30:00Z]}

open?(opts \\ [])

@spec open?(keyword()) :: {:ok, boolean()} | {:error, Alpa.Error.t()}

Check if the market is currently open.

Examples

iex> Alpa.Trading.Market.open?()
{:ok, true}