Debugging a paper-trading algo in after hours I got this error on the blotter. Looks like it's because the adaptive algo can't run outside of regular hours.
Do I need to set a midpoint LMT or "Fill or Kill" in after hours?
Current Moonshot orders.
Debugging a paper-trading algo in after hours I got this error on the blotter. Looks like it's because the adaptive algo can't run outside of regular hours.
Do I need to set a midpoint LMT or "Fill or Kill" in after hours?
Current Moonshot orders.
AFAIK IB would only accept ordinary limit orders for outside RTH. Not only you will have to specify LMT order type but also set proper 'LmtPrice' in your order_stubs_to_orders function. You may want to do something like:
closes = prices.loc["Close"]
slippage = 0.005
prior_closes = closes.shift()
prior_closes = self.reindex_like_orders(prior_closes, orders)
orders["OrderType"] = "LMT"
sell_limits = (prior_closes - (prior_closes * slippage)).round(2)
buy_limits = (prior_closes + (prior_closes * slippage)).round(2)
orders["LmtPrice"] = sell_limits.where(orders["Action"] == "SELL").fillna(buy_limits)
# Send SMART-routed market orders
orders["Exchange"] = "SMART"
orders["Tif"] = "DAY"
orders["OutsideRth"] = 1
# Optionally attach exit orders
# child_orders = self.orders_to_child_orders(orders)
# child_orders.loc[:, "OrderType"] = "MOC"
# orders = pd.concat([orders, child_orders])
return orders
And don't forget to cancel all open orders for this strategy using 'quantrocket blotter cancel' before running the strategy next time. Since these are LMT orders they are not guaranteed to execute, so if you run strategy sooner than next day some orders may remain open and your balance will be off.
Actually I think there is a lot more logic to implement proper outside RTH trading, so good luck
@govorunov I appreciate the thoughts. I had found that only LMT orders will work after hours. I appreciate the train of thought on the logic, and yes it will run intraday (including extended hours) so needing the proper cancellation with the blotter is needed as well.