Hi,
I want to trade during and pre and post market hours (extended market hours). I set the following already:
def Initialize(self):
self.spy = self.AddEquity("AAPL", Resolution.Minute, extendedMarketHours=True)
def OnData(self, data):
order_properties = InteractiveBrokersOrderProperties()()
order_properties.OutsideRegularTradingHours = True
but the market orders I place during off-market hours are still becoming market on open orders. What is wrong?
Mia Alissi
Hi Shiven,
The issue you're facing is due to the fact that market orders placed when the market is closed are automatically converted into market on open orders by LEAN, the trading engine that powers QuantConnect (source). This is a common occurrence when using daily or hourly data, which your algorithm can receive even when the market is closed.
To avoid this, you should place your orders when the market is open. You can check if the market is open by calling the
IsMarketOpen
method. Here's how you can do it:If you want to place orders during extended market hours, you should use limit orders instead of market orders. This is because US Equity markets don't support market orders after market close due to limited liquidity (source).
Here's how you can place a limit order:
This code will place a limit order that can be filled during extended market hours (source).
I hope this helps! Let me know if you have any other questions.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Shiven Garg
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!