Interact with a trading backend

trader(
  orders,
  trader_life = 300,
  resubmit_interval = 5,
  trading_connection,
  pricing_connection = NULL,
  pricing_spread_tolerance = 0.01,
  pricing_overrides = NULL,
  exit_if_market_closed = TRUE,
  verbose = TRUE
)

Arguments

orders

a data frame of orders

trader_life

how long, in seconds, the trader should operate before timeout

resubmit_interval

how long, in seconds, the trader should wait before cancelling all open orders, recompute price limits, and resubmit orders

trading_connection

the backend trading connection for submitting orders

pricing_connection

the backend trading connection for computing price limits

pricing_spread_tolerance

the maximum bid-ask spread which can be tolerated for a limit price to be computed

pricing_overrides

optional data frame of limit prices to assign to each symbol

exit_if_market_closed

should the trader() quit if the market is closed

verbose

TRUE/FALSE should the function be chatty?

Value

a data frame detailing the outcome of each attempted order

Examples

if (FALSE) {
t_conn <- alpaca_connect('paper',
                         Sys.getenv("ALPACA_PAPER_KEY"),
                         Sys.getenv("ALPACA_PAPER_SECRET"))
d_conn <- alpaca_connect('data',
                         Sys.getenv("ALPACA_LIVE_KEY"),
                         Sys.getenv("ALPACA_LIVE_SECRET"))

portfolio_model <- read_portfolio_model(system.file(package='rblncr','extdata/sample_portfolio.yaml'))

get_portfolio_current(t_conn) |>
  load_portfolio_targets(portfolio_model) |>
  price_portfolio(connection = d_conn, price_type = 'close') |>
  solve_portfolio() |>
  constrain_orders(d_conn) |>
  trader(trading_connection = t_conn,
         pricing_connection = d_conn,
         verbose = FALSE)
}