I'm using minute-resolution data and have found cases where the algorithm places an order at 16:00 and it gets filled the next day at 09:31. But I'm placing the order like this:
props = OrderProperties()
props.TimeInForce = TimeInForce.Day
order = self.MarketOrder(symbol, 100, orderProperties=props)
I thought this would ensure the order is not valid the next day. Am I misunderstanding how a Market “Day” Order works in QC? This seems inconsistent with how the brokers would work.
Varad Kabade
Hi David Avraamides,
The market is closed at 16.00 and market orders are automatically converted to OnMarketOpen order valid till 16.00 in the next day.
Best,
Varad Kabade
David Avraamides
That doesn't make sense and I would call it a bug. If I explicitly specify a TimeInForce of Day, it should never change that to an order that would be valid the following day - no matter what time that order is sent. No real broker would ever do that to an order. Instead, they would cancel it and say the market was closed.
Alexandre Catarino
Hi David,
What would a real broker do?
Say it's 4 pm, the market is closed, we want to place a market order using IB TWS. It wouldn't be possible, right? TWS would not let you place a market order. So what are our options? We can place a market-on-open order at that moment or place a market order on the following day. I don't think there is any “they would cancel it” option since they would not allow the submission or, if they allow it, a human would never place that order.
We have decided that the best option, from the automation standpoint, would be option #1: convert the market order to a market-on-open order. If you don't think the market order should not be converted, then your algorithm should not place orders when the market is closed.
Best regards,
Alex
David Avraamides
I understand how your design decision makes sense if people are doing backtests using data with a daily resolution (or of longer resolutions) but it doesn't make as much sense for more granular time resolutions like hour, minute, second or tick. There is too much overnight gap risk.
To your question, if I try and place a TIF day order at any broker after 4pm it will just be rejected - if they allowed it at all. They probably wouldn't allow it through their UI, but if I was placing it through an API, I could certainly try to send an order past 4pm and it would not be placed, nor would it be converted to a market-on-open order and sent out the next day. That would be a huge liability for the broker.
Also, is there a method where I can check if an exchange is closed rather than checking if the time is 4pm (which won't work on the day after Thanksgiving or New Year's Eve when the markets close early)?
Louis Szeto
Hi David
We can access if the market is opened by:
Alternatively, you can also call a good-till-date order using Time In Force by:
The market-on-open order will be canceled when the current day past.
Best
Louis
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.
David Avraamides
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!