alpa v0.1.4 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 asset by id or symbol

list assets

list bars

buy day market order wrapper

close a position by symbol

close all positions

delete all orders

delete an order

delete a watchlist by id

auth headers for api

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 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 symbol 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

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

Link to this function

place_order(symbol, qty, side, type, time_in_force, 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

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