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
)
a data frame of orders
how long, in seconds, the trader should operate before timeout
how long, in seconds, the trader should wait before cancelling all open orders, recompute price limits, and resubmit orders
the backend trading connection for submitting orders
the backend trading connection for computing price limits
the maximum bid-ask spread which can be tolerated for a limit price to be computed
optional data frame of limit prices to assign to each symbol
should the trader()
quit if the market is closed
TRUE/FALSE should the function be chatty?
a data frame detailing the outcome of each attempted order
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)
}