Alpa.Config (AlpaEx v1.0.3)

View Source

Configuration management for the Alpa client.

Configuration can be provided via:

  1. Application config (config/runtime.exs recommended)
  2. Environment variables
  3. Explicit options passed to functions

Environment Variables

APCA_API_KEY_ID      - Your Alpaca API key
APCA_API_SECRET_KEY  - Your Alpaca API secret
APCA_USE_PAPER       - "true" for paper trading (default), "false" for live

Application Config

config :alpa_ex,
  api_key: "your-key",
  api_secret: "your-secret",
  use_paper: true

Priority (highest to lowest)

  1. Options passed directly to functions
  2. Environment variables
  3. Application config

Summary

Functions

Get the market data URL.

Check if configuration has valid credentials.

Build configuration from application config and options.

Get the base trading URL based on paper/live mode.

Types

t()

@type t() :: %Alpa.Config{
  api_key: String.t() | nil,
  api_secret: String.t() | nil,
  data_url: String.t(),
  receive_timeout: pos_integer(),
  timeout: pos_integer(),
  trading_url: String.t(),
  use_paper: boolean()
}

Functions

data_url(config)

@spec data_url(t()) :: String.t()

Get the market data URL.

has_credentials?(config)

@spec has_credentials?(t()) :: boolean()

Check if configuration has valid credentials.

new(opts \\ [])

@spec new(keyword()) :: t()

Build configuration from application config and options.

Options override application config values.

Options

  • :api_key - Alpaca API key (required for authenticated requests)
  • :api_secret - Alpaca API secret (required for authenticated requests)
  • :use_paper - Use paper trading endpoint (default: true)
  • :timeout - Request timeout in milliseconds (default: 30_000)
  • :receive_timeout - Response receive timeout in milliseconds (default: 30_000)

trading_url(config)

@spec trading_url(t()) :: String.t()

Get the base trading URL based on paper/live mode.

If a custom trading_url (different from the default) was explicitly set, it is used regardless of the use_paper flag. Otherwise, use_paper: true resolves to the paper trading URL.