My algorithm requires to store internal state in order to functional correctly. I planned to use ObjectStore for that purpose.
However, same ObjectStore shared between all backtests, live and paper modes. Obviously each algorithm session requires to have its own state and I definitely don't want to corrupt state of my live trading. So I need somehow to distinguish between backtest, paper and live modes - so I could store different keys in ObjectStore and this way to maintain separation.
Moreover, my broker is IBKR, and I intend to use it both for live and paper trading (it supports paper trading). So I need to know whether I'm running in live or paper mode.
I'm aware about “LiveMode” property but its boolean - so using it I can know only whether I'm in backtest or not - but that doesn't help to determine whether its paper or live modes. Also, for a question why I not using QC for paper trading - its because I want my paper trading to be close as possible to live, so I prefer to use IBKR for both, to accurately simulate fees, margins, etc.
Mia Alissi
To manage different algorithm modes effectively using the
ObjectStore
in QuantConnect, address the following:AlgorithmMode
andBrokerageEnvironment
.Here's an example of how you might implement this in your algorithm:
Key Points:
get_environment_mode
andget_brokerage_environment
methods are correctly implemented to ascertain the current mode and brokerage environment.construct_object_store_key
builds a key based on detected mode.Sources: Object Store - QuantConnect.com, Object Store - QuantConnect.com, Object Store Example Algorithm, Object Store - QuantConnect.com, Brokerage Model Algorithm
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.
Evgeni Aizikovich
One possible way to know whether I run in live or paper in IBKR, is by account id (live starts with “U” and paper starts with “D”). However, I can't find a way to locate current broker account ID. Does such API exists?
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.
Evgeni Aizikovich
Well, if I would know how to implement “get_brokerage_environment” or “get_environment_mode” - I won't be asking this question in the first place…
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.
Louis Szeto
Hi Evgeni
We cannot access that within the algorithm, but you can use the project ID to create a new folder in the object store:
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.
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!