Build a Buy Order

Helper for creating a buy order

analysis_engine.build_buy_order.build_buy_order(ticker, num_owned, close, balance, commission, date, details, use_key, minute=None, shares=None, version=1, auto_fill=True, is_live_trading=False, backtest_shares_default=10, reason=None)[source]

Create an algorithm buy order as a dictionary


setting the minute is required to build a minute-by-minute Trading History

  • ticker – ticker
  • num_owned – integer current owned number of shares for this asset
  • close – float closing price of the asset
  • balance – float amount of available capital
  • commission – float for commission costs
  • date – string trade date for that row usually COMMON_DATE_FORMAT (YYYY-MM-DD)
  • minute – optional - string with the minute that the order was placed. format is COMMON_TICK_DATE_FORMAT (YYYY-MM-DD HH:MM:SS)
  • details – dictionary for full row of values to review all buys after the algorithm finishes. (usually row.to_json())
  • use_key – string for redis and s3 publishing of the algorithm result dictionary as a json-serialized dictionary
  • shares – optional - integer number of shares to buy if None buy max number of shares at the close with the available balance amount.
  • version – optional - version tracking integer
  • auto_fill – optional - bool for not assuming the trade filled (default True)
  • is_live_trading – optional - bool for filling trades for live trading or for backtest tuning filled (default False which is backtest mode)
  • backtest_shares_default – optional - integer for simulating shares during a backtest even if there are not enough funds (default 10)
  • reason – optional - string for recording why the algo decided to buy for review after the algorithm finishes