watchlist: Access all Watchlist Endpoints

View source: R/Watchlist.R

watchlistR Documentation

Access all Watchlist Endpoints

Description

Access all Watchlist endpoints. See link for details. \lifecyclestable

Usage

watchlist(
  watchlist_id = NULL,
  symbols = NULL,
  action = "get",
  new_name,
  live = get_live()
)

Arguments

watchlist_id

(character) Watchlist Name or ID. If NULL Default, the array of all saved Watchlist will be returned. All other actions to be performed on the provided Watchlist name or ID must be explicitly specified via action. See below for description of the behavior of this argument based on the value supplied to action.

symbols

(character) Vector of symbols. Must be specified with a watchlist_id. If the action is:

  • "get" **Default** action assumed to be add and symbols will be added.

  • "create" A Watchlist called watchlist_id will be created with symbols. If symbols are missing the new Watchlist will be empty.

  • "add" The symbols will be added to the specified watchlist_id. If this argument is specified with watchlist_id and new_name the Watchlist will be renamed to new_name and the symbols will be added. Set action = "update" explicitly to replace existing symbols with symbols when renaming.

  • "update" The symbols will replace those in watchlist_id.

  • "delete" If this argument is specified with watchlist_id, the symbols will be deleted from the Watchlist. If symbols is missing the Watchlist will be deleted.

action

(character) The action to take. See other parameters for detailed descriptions of how this argument determines the action when combinations of parameters are specified. This argument can be abbreviated with a single non-case-sensitive letter. One of:

  • "get"/"g" Default If no watchlist_id is specified, an array of all Watchlist will be returned, otherwise a the watchlist specified by watchlist_id will be returned. If symbols are specified, the symbols will be added to the watchlist_id.

  • "create"/"c" A Watchlist will be created named according to watchlist_id with any symbols provided.

  • "add"/"a" the watchlist_id will have symbols added. If new_name is also specified, symbols will be added (unless action = "update")

  • "update"/"u" watchlist_id is required and will have it's symbols replaced by those provided to symbols. If new_name and symbols are provided the Watchlist will be renamed and the symbols will replace the existing ones. If the symbols are meant to be added, do not set action, or set as "add".

  • "delete"/"d" If action = "delete" with watchlist_id, the symbols will be deleted from the Watchlist. If symbols is missing the Watchlist with id/name watchlist_id will be deleted.

new_name

(character) arbitrary name string, up to 64 characters. If present, then action = "update" is assumed and the Watchlist specified by watchlist_id will be renamed to new_name preserving existing symbols, unless symbols is present, in which case they will replace the existing.

live

(logical) TRUE / FALSE if you are connecting to a live account. Default to FALSE, so it will use the paper url if nothing was provided.

Value

Watchlist (tibble) If watchlist() is called with no arguments, an tibble of Watchlist Object. For all others actions, a tibble of Asset Objects with the Watchlist stored as an attribute retrieved with attr(Asset, "info") and query metadata stored as attr(Asset, "query"). A Watchlist object has the following information:

  • name(character) The name of the watchlist.

  • updated_at(POSIXct) The timestamp of the last update.

  • id(character) Watchlist ID

  • account_id(character) The account ID associated with the watchlist

  • created_at(POSIXct) The timestamp of the watchlist creation.

Examples

## Not run: 
# get the existing watchlists
watchlist()
# create a watchlist named test with Microsoft
(wl <- watchlist("test", symbols = "AAPL", action = "c"))
# See it in the list of watchlists
watchlist()
# Get it
(test <- watchlist("test"))
all.equal(test,wl, check.attributes = FALSE)
# Get that Watchlist's info
attr(wl, "info")
# Add "FB", "AMZN", "NFLX", "GOOG" and update the watchlist name to "FAANG"
(wl <- watchlist("test", new_name = "FAANG", symbols = c("FB", "AMZN", "NFLX", "GOOG")))
# Add individual stocks by specifying symbols (action assumed to be add when symbols are present)
(wl <- watchlist("FAANG", symbol = "GOOGL"))
# Delete individual items (or multiple)
(wl <- watchlist("FAANG", action = "d", symbols = "GOOGL"))
# Rename it appropriately and replace the symbols to match the name by specifying action = "update" explicitly.
(wl <- watchlist("FAANG", new_name = "FANG", symbols = c("FB", "AAPL", "NFLX", "GOOG"), action = "u"))
# Delete it using a partial argument (may cause a warning)
watchlist("FANG", a = "d")

## End(Not run)

jagg19/AlpacaforR documentation built on July 3, 2023, 12:14 p.m.