alpa v0.1.6 Alpa View Source

api wrapper for alpaca.markets

calls return:

{:ok, result} on success

{:error, reason} on failure

https://docs.alpaca.markets/api-documentation/api-v2/

Link to this section Summary

Functions

gets account info

get account config

get asset by id or symbol

list assets

list bars

buy day market order wrapper

get the market clock

close a position by symbol

close all positions

delete all orders

delete an order

delete a watchlist by id

auth headers for api

get market open status

get an order

get an order by client order id

list all orders

get asset by id or symbol

list open positions

sell day market order wrapper

get watchlists by id

add an asset to a watchlist

gets id of watchlist by name

list watchlists

Link to this section Functions

gets account info

get account config

get asset by id or symbol

list assets

list bars

paper money account, IEX data only

(uses 'v1')

https://docs.alpaca.markets/api-documentation/api-v2/market-data/bars/

Retrieves a list of bars for each requested symbol. It is guaranteed all bars are in ascending order by time.

for alpaca api, timestamps are ISO 8601 ('2019-04-15T09:30:00-04:00')

for Alpa, timestamps are Elixir DateTimes

params: alpaca api type/Elixir type

  • timeframe: string, default = "1Min" ["minute", "1Min", "5Min", "15Min", "day" or "1D"]
  • symbols: string, (comma separated list)
  • limit : int, default = 100 (1000 max)
  • start_time : timestamp, (cannot be used with :after)
  • end_time : timestamp, (cannot be used with :until)
  • after : timestamp, (cannot be used with :start)
  • until : timestamp, (cannot be used with :until)

note: :end, :after, :until -> :*_time due to Elixir keyword conflict

returns Bars response (list of symbols with lists of bar objects)

%{:ok,
  [
    %{symbol: "AAPL",
      [
      %{t: 1544129220,
        o: 172.26,
        h: 172.3,
        l: 172.16,
        c: 172.18,
        v: 3892,
        }
      ]
    }
  ]
}
  • t : the beginning time of this bar as a Unix epoch in seconds, int
  • o : open price, float
  • h : high price, float
  • l : low price, float
  • c : close price, float
  • v : volume, int

buy day market order wrapper

Link to this function

calendar(start_time \\ Date.utc_today, end_time \\ Date.utc_today)

View Source

get the calendar

1970 - 2029

get the market clock

close a position by symbol

close all positions

Link to this function

create_watchlist(name, symbols \\ [])

View Source

create a watchlist

delete all orders

delete an order

delete a watchlist by id

auth headers for api

Link to this function

history(period \\ "1M", timeframe \\ "1D", date_end \\ Date.utc_today, extended_hours \\ false)

View Source

get portfolio history

get market open status

get an order

Link to this function

order_by_client_order_id(client_order_id)

View Source

get an order by client order id

list all orders

Link to this function

place_order(symbol, qty, side, type, time_in_force \\ "day", limit_price \\ nil, stop_price \\ nil)

View Source

places an order

get asset by id or symbol

list open positions

sell day market order wrapper

Link to this function

update_account_config(dtbp_check \\ "entry", trade_confirm_email \\ "all", suspend_trade \\ false, no_shorting \\ false)

View Source

update account config

  • dtbp_check : string, [both, entry, or exit] Controls Day Trading Margin Call (DTMC) checks.
  • trade_confirm_email : string [all or none]
  • suspend_trade : bool
  • no_shorting : bool
Link to this function

update_order(order_id, qty, time_in_force \\ "day", limit_price \\ nil, stop_price \\ nil)

View Source

updates an order

get watchlists by id

Link to this function

watchlist_add_asset(id, symbol)

View Source

add an asset to a watchlist

Link to this function

watchlist_id_by_name(name)

View Source

gets id of watchlist by name

returns:

{:ok, id} on success

{:error, reason} on failure

list watchlists