Alpa.Trading.Account (AlpaEx v1.0.3)

View Source

Account operations for the Alpaca Trading API.

Summary

Functions

Get account information.

Get account activities.

Get account activities for a specific activity type.

Get account configurations.

Get portfolio history.

Update account configurations.

Functions

get(opts \\ [])

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

Get account information.

Returns the current account state including buying power, cash, portfolio value, and trading status.

Examples

iex> Alpa.Trading.Account.get()
{:ok, %Alpa.Models.Account{...}}

get_activities(opts \\ [])

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

Get account activities.

Returns a list of account activities like fills, dividends, and fees.

Options

  • :activity_types - List of activity types to filter (e.g., ["FILL", "DIV"])
  • :date - Date to filter (format: "YYYY-MM-DD")
  • :until - Filter activities until this time
  • :after - Filter activities after this time
  • :direction - Sort direction ("asc" or "desc")
  • :page_size - Number of results per page (max 100)
  • :page_token - Pagination token

Examples

iex> Alpa.Trading.Account.get_activities(activity_types: ["FILL"])
{:ok, [%{...}]}

get_activities_by_type(activity_type, opts \\ [])

@spec get_activities_by_type(
  String.t(),
  keyword()
) :: {:ok, [Alpa.Models.Activity.t()]} | {:error, Alpa.Error.t()}

Get account activities for a specific activity type.

Activity Types

Common types: "FILL", "TRANS", "MISC", "ACATC", "ACATS", "CSD", "CSW", "DIV", "JNLC", "JNLS", "MA", "NC", "OPASN", "OPEXP", "OPXRC", "PTC", "PTR", "SSO", "SSP"

Options

  • :date - Date to filter (format: "YYYY-MM-DD")
  • :until - Filter activities until this time
  • :after - Filter activities after this time
  • :direction - Sort direction ("asc" or "desc")
  • :page_size - Number of results per page (max 100)
  • :page_token - Pagination token

Examples

iex> Alpa.Trading.Account.get_activities_by_type("FILL")
{:ok, [%{...}]}

get_configurations(opts \\ [])

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

Get account configurations.

Returns configuration settings like day trade margin call handling, trade confirmation emails, and trading restrictions.

Examples

iex> Alpa.Trading.Account.get_configurations()
{:ok, %{
  "dtbp_check" => "entry",
  "trade_confirm_email" => "all",
  "suspend_trade" => false,
  "no_shorting" => false,
  "fractional_trading" => true,
  "max_margin_multiplier" => "4",
  "pdt_check" => "entry",
  "ptp_no_exception_entry" => false
}}

get_portfolio_history(opts \\ [])

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

Get portfolio history.

Returns historical portfolio values over a time period.

Options

  • :period - Time period ("1D", "1W", "1M", "3M", "1A", "all", "intraday")
  • :timeframe - Resolution ("1Min", "5Min", "15Min", "1H", "1D")
  • :intraday_reporting - Intraday reporting type ("market_hours", "extended_hours", "continuous")
  • :start - Start date (format: "YYYY-MM-DD")
  • :end - End date (format: "YYYY-MM-DD")
  • :pnl_reset - Reset PnL calculations ("per_day")
  • :date_end - Deprecated, use :end instead

Examples

iex> Alpa.Trading.Account.get_portfolio_history(period: "1M", timeframe: "1D")
{:ok, %{
  "timestamp" => [...],
  "equity" => [...],
  "profit_loss" => [...],
  "profit_loss_pct" => [...],
  "base_value" => 100000.0,
  "timeframe" => "1D"
}}

update_configurations(settings)

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

Update account configurations.

Options

  • :dtbp_check - Day trade buying power check ("both", "entry", "exit")
  • :trade_confirm_email - Trade confirmation emails ("all", "none")
  • :suspend_trade - Suspend trading (boolean)
  • :no_shorting - Disable shorting (boolean)
  • :fractional_trading - Enable fractional trading (boolean)
  • :max_margin_multiplier - Max margin multiplier ("1", "2", "4")
  • :pdt_check - Pattern day trader check ("entry", "exit", "both")
  • :ptp_no_exception_entry - PTP no exception entry (boolean)

Examples

iex> Alpa.Trading.Account.update_configurations(suspend_trade: true)
{:ok, %{...}}