Is there an method already built in for incrementing by some time increment that takes into account when the market is open?
For example, I sell a stock 2 hours after I buy it. This takes place even over the end of day and over weekends. So if I buy on Friday at 3pm, then I would sell it on Monday at 10:30AM.
I could bulid one myself but was curious if it had already been implemented somewhere.
Atish Sawant
So I found this which describes regular schedules.
However, I'm still looking for the documentation on checking if a day is a trading day. I did find this
But it still doesn't quite work in Python. An example of this in python would be great.
Jared Broad
Not currently; we have similar code for days but not intraday timespans like that. We have a MarketOpen check you could use and then iterate forward in minute increments? This is how we do it for the History API.
public static DateTime GetStartTimeForTradeBars(SecurityExchangeHours exchange, DateTime end, TimeSpan barSize, int barCount, bool extendedMarketHours) { if (barSize <= TimeSpan.Zero) { throw new ArgumentException("barSize must be greater than TimeSpan.Zero", "barSize"); } var current = end.RoundDown(barSize); for (int i = 0; i < barCount;) { var previous = current; current = current - barSize; if (exchange.IsOpen(current, previous, extendedMarketHours)) { i++; } } return current; }
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.
Atish Sawant
I pieced together all the code logic to work. However I'm getting an order status of 3 on a market order that doesn't kick off an error or seem to get filled for some reason.
Alexandre Catarino
Please chekout the docs, under Order Error Codes, to get meaning of order status:
Error Code Interpretation -3 InsufficientBuyingPower - Not enough money to to submit order.
Atish Sawant
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!