Alpa (AlpaEx v1.0.3)

View Source

Elixir client library for the Alpaca Trading API.

Quick Start

Set your API credentials as environment variables:

export APCA_API_KEY_ID="your-key"
export APCA_API_SECRET_KEY="your-secret"
export APCA_USE_PAPER="true"  # optional, defaults to true

Then use the API:

# Get account info
{:ok, account} = Alpa.account()

# Place a market order
{:ok, order} = Alpa.buy("AAPL", 10)

# Get positions
{:ok, positions} = Alpa.positions()

# Get market data
{:ok, bars} = Alpa.bars("AAPL", timeframe: "1Day")

# Get a market snapshot
{:ok, snapshot} = Alpa.snapshot("AAPL")

Modules

For more advanced usage, use the specific modules:

Configuration

Configuration can be set via:

  1. Environment variables (recommended for credentials)
  2. Application config
  3. Options passed directly to functions

See Alpa.Config for details.

Summary

Functions

Get account information.

Get account configurations.

Get a specific asset.

Get all assets.

Get historical bars for a symbol.

Get historical bars for multiple symbols.

Place a market buy order.

Get the market calendar.

Cancel all orders.

Get the market clock.

Close all positions.

Get a specific corporate action announcement.

Get corporate action announcements.

Create a watchlist.

Get all available crypto assets.

Get historical crypto bars for a symbol.

Buy crypto with a market order.

Get latest crypto bars for a symbol.

Get latest crypto quotes for a symbol.

Get latest crypto trades for a symbol.

Place a crypto order.

Get all crypto positions.

Get historical crypto quotes for a symbol.

Sell crypto with a market order.

Get crypto snapshots for one or more symbols.

Get historical crypto trades for a symbol.

Get a specific crypto transfer.

List crypto funding transfers.

List crypto wallets.

Request a crypto withdrawal.

Get account activities.

Get account activities for a specific activity type.

Get an order by client order ID.

Get portfolio history.

Get the latest bar for a symbol.

Get latest bars for multiple symbols.

Get the latest quote for a symbol.

Get latest quotes for multiple symbols.

Get the latest trade for a symbol.

Get latest trades for multiple symbols.

Check if the market is open.

Get a specific option contract by symbol or ID.

Get option contracts with filtering.

Search for option contracts by underlying symbol.

Get a specific order.

Get all orders.

Place a new order.

Get a specific position.

Get all positions.

Get historical quotes for a symbol.

Get historical quotes for multiple symbols.

Replace (modify) an existing order.

Place a market sell order.

Get a market snapshot for a symbol.

Get market snapshots for multiple symbols.

Get historical trades for a symbol.

Get historical trades for multiple symbols.

Update account configurations.

Get a specific watchlist.

Get all watchlists.

Functions

account(opts \\ [])

Get account information.

See Alpa.Trading.Account.get/1 for details.

account_config(opts \\ [])

Get account configurations.

See Alpa.Trading.Account.get_configurations/1 for details.

asset(symbol, opts \\ [])

Get a specific asset.

See Alpa.Trading.Assets.get/2 for details.

assets(opts \\ [])

Get all assets.

See Alpa.Trading.Assets.list/1 for details.

bars(symbol, opts \\ [])

Get historical bars for a symbol.

See Alpa.MarketData.Bars.get/2 for details.

bars_multi(symbols, opts \\ [])

Get historical bars for multiple symbols.

See Alpa.MarketData.Bars.get_multi/2 for details.

buy(symbol, qty, opts \\ [])

Place a market buy order.

See Alpa.Trading.Orders.buy/3 for details.

calendar(opts \\ [])

Get the market calendar.

See Alpa.Trading.Market.get_calendar/1 for details.

cancel_all_orders(opts \\ [])

Cancel all orders.

See Alpa.Trading.Orders.cancel_all/1 for details.

cancel_order(order_id, opts \\ [])

Cancel an order.

See Alpa.Trading.Orders.cancel/2 for details.

clock(opts \\ [])

Get the market clock.

See Alpa.Trading.Market.get_clock/1 for details.

close_all_positions(opts \\ [])

Close all positions.

See Alpa.Trading.Positions.close_all/1 for details.

close_position(symbol, opts \\ [])

Close a position.

See Alpa.Trading.Positions.close/2 for details.

corporate_action(id, opts \\ [])

Get a specific corporate action announcement.

See Alpa.Trading.CorporateActions.get/2 for details.

corporate_actions(opts \\ [])

Get corporate action announcements.

See Alpa.Trading.CorporateActions.list/1 for details.

create_watchlist(params)

Create a watchlist.

See Alpa.Trading.Watchlists.create/1 for details.

crypto_assets(opts \\ [])

Get all available crypto assets.

See Alpa.Crypto.Trading.assets/1 for details.

crypto_bars(symbol, opts \\ [])

Get historical crypto bars for a symbol.

See Alpa.Crypto.MarketData.bars/2 for details.

crypto_buy(symbol, qty, opts \\ [])

Buy crypto with a market order.

See Alpa.Crypto.Trading.buy/3 for details.

crypto_latest_bars(symbol, opts \\ [])

Get latest crypto bars for a symbol.

See Alpa.Crypto.MarketData.latest_bars/2 for details.

crypto_latest_quotes(symbol, opts \\ [])

Get latest crypto quotes for a symbol.

See Alpa.Crypto.MarketData.latest_quotes/2 for details.

crypto_latest_trades(symbol, opts \\ [])

Get latest crypto trades for a symbol.

See Alpa.Crypto.MarketData.latest_trades/2 for details.

crypto_place_order(params)

Place a crypto order.

See Alpa.Crypto.Trading.place_order/1 for details.

crypto_positions(opts \\ [])

Get all crypto positions.

See Alpa.Crypto.Trading.positions/1 for details.

crypto_quotes(symbol, opts \\ [])

Get historical crypto quotes for a symbol.

See Alpa.Crypto.MarketData.quotes/2 for details.

crypto_sell(symbol, qty, opts \\ [])

Sell crypto with a market order.

See Alpa.Crypto.Trading.sell/3 for details.

crypto_snapshots(symbols, opts \\ [])

Get crypto snapshots for one or more symbols.

See Alpa.Crypto.MarketData.snapshots/2 for details.

crypto_trades(symbol, opts \\ [])

Get historical crypto trades for a symbol.

See Alpa.Crypto.MarketData.trades/2 for details.

crypto_transfer(id, opts \\ [])

Get a specific crypto transfer.

See Alpa.Crypto.Funding.get_transfer/2 for details.

crypto_transfers(opts \\ [])

List crypto funding transfers.

See Alpa.Crypto.Funding.list_transfers/1 for details.

crypto_wallets(opts \\ [])

List crypto wallets.

See Alpa.Crypto.Funding.list_wallets/1 for details.

crypto_withdraw(params)

Request a crypto withdrawal.

See Alpa.Crypto.Funding.create_transfer/1 for details.

delete_watchlist(watchlist_id, opts \\ [])

Delete a watchlist.

See Alpa.Trading.Watchlists.delete/2 for details.

get_activities(opts \\ [])

Get account activities.

See Alpa.Trading.Account.get_activities/1 for details.

get_activities_by_type(activity_type, opts \\ [])

Get account activities for a specific activity type.

See Alpa.Trading.Account.get_activities_by_type/2 for details.

get_order_by_client_id(client_order_id, opts \\ [])

Get an order by client order ID.

See Alpa.Trading.Orders.get_by_client_id/2 for details.

history(opts \\ [])

Get portfolio history.

See Alpa.Trading.Account.get_portfolio_history/1 for details.

latest_bar(symbol, opts \\ [])

Get the latest bar for a symbol.

See Alpa.MarketData.Bars.latest/2 for details.

latest_bars_multi(symbols, opts \\ [])

Get latest bars for multiple symbols.

See Alpa.MarketData.Bars.latest_multi/2 for details.

latest_quote(symbol, opts \\ [])

Get the latest quote for a symbol.

See Alpa.MarketData.Quotes.latest/2 for details.

latest_quotes_multi(symbols, opts \\ [])

Get latest quotes for multiple symbols.

See Alpa.MarketData.Quotes.latest_multi/2 for details.

latest_trade(symbol, opts \\ [])

Get the latest trade for a symbol.

See Alpa.MarketData.Trades.latest/2 for details.

latest_trades_multi(symbols, opts \\ [])

Get latest trades for multiple symbols.

See Alpa.MarketData.Trades.latest_multi/2 for details.

market_open?(opts \\ [])

Check if the market is open.

See Alpa.Trading.Market.open?/1 for details.

option_contract(symbol_or_id, opts \\ [])

Get a specific option contract by symbol or ID.

See Alpa.Options.Contracts.get/2 for details.

option_contracts(opts \\ [])

Get option contracts with filtering.

See Alpa.Options.Contracts.list/1 for details.

option_search(underlying_symbol, opts \\ [])

Search for option contracts by underlying symbol.

See Alpa.Options.Contracts.search/2 for details.

order(order_id, opts \\ [])

Get a specific order.

See Alpa.Trading.Orders.get/2 for details.

orders(opts \\ [])

Get all orders.

See Alpa.Trading.Orders.list/1 for details.

place_order(params)

Place a new order.

See Alpa.Trading.Orders.place/1 for details.

position(symbol, opts \\ [])

Get a specific position.

See Alpa.Trading.Positions.get/2 for details.

positions(opts \\ [])

Get all positions.

See Alpa.Trading.Positions.list/1 for details.

quotes(symbol, opts \\ [])

Get historical quotes for a symbol.

See Alpa.MarketData.Quotes.get/2 for details.

quotes_multi(symbols, opts \\ [])

Get historical quotes for multiple symbols.

See Alpa.MarketData.Quotes.get_multi/2 for details.

replace_order(order_id, params)

Replace (modify) an existing order.

See Alpa.Trading.Orders.replace/2 for details.

sell(symbol, qty, opts \\ [])

Place a market sell order.

See Alpa.Trading.Orders.sell/3 for details.

snapshot(symbol, opts \\ [])

Get a market snapshot for a symbol.

See Alpa.MarketData.Snapshots.get/2 for details.

snapshots(symbols, opts \\ [])

Get market snapshots for multiple symbols.

See Alpa.MarketData.Snapshots.get_multi/2 for details.

trades(symbol, opts \\ [])

Get historical trades for a symbol.

See Alpa.MarketData.Trades.get/2 for details.

trades_multi(symbols, opts \\ [])

Get historical trades for multiple symbols.

See Alpa.MarketData.Trades.get_multi/2 for details.

update_configurations(settings)

Update account configurations.

See Alpa.Trading.Account.update_configurations/1 for details.

watchlist(watchlist_id, opts \\ [])

Get a specific watchlist.

See Alpa.Trading.Watchlists.get/2 for details.

watchlists(opts \\ [])

Get all watchlists.

See Alpa.Trading.Watchlists.list/1 for details.