If using AddSecurity/Equity/Option, how can I list out the active subscriptions? Iterating over .Securities doesn't work as it's a growing list. HasData does not seem to work properly either and I believe Security.Subscriptions is also a growing list?
Cole S
ActiveSecurities contains only the Active subscriptions
Peter Dimov
I believe ActiveSecurities only gets filled if you are adding them in your universe selection. If using AddSecurity, this list remains empty
Cole S
Hi Peter,
That's good to know. The other way I have done it is to manage the list myself in OnSecuritiesChanged. I usually have a dictionary of SymbolData objects that I store anyway so I just add/remove from that as Securities are added or removed.
Peter Dimov
Ah that's unfortunate, I was looking for a way to find the answer backward lookingly (audit the securities that are actively subscribed to) as opposed to forward looking (monitor what I am attempting to sub to).
Jared Broad
>If using AddSecurity, this list remains empty
I think this should be a bug; we'll make it so manually Added securities are also counted as active.
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.
Jared Broad
It looks fine to me, can you please post an example of what you think is broken?
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.
Peter Dimov
Hey Jared,
Looks like it was more a question of timing that was leading to confusion on my end. If you take a look at the snippet below the first debug statement returns 0. I assume this is due to the task queuing as far as adding securities goes and the ActiveSecurities will only reflect the added on a subsequent loop.
class VentralParticleFlange(QCAlgorithm): def tryMe(self): self.AddSecurity(SecurityType.Equity, "AAPL", Resolution.Minute) self.AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute) self.Debug(len(list(self.ActiveSecurities.Keys))) def Initialize(self): self.SetStartDate(2020, 12, 20) self.SetCash(100000) self.tryMe() def OnData(self, data): self.Debug(len(list(self.ActiveSecurities.Keys)))
Peter Dimov
Followed up here:
https://www.quantconnect.com/forum/discussion/10230/manually-adding-and-removing-securities-unexpected-behaviour/p1Peter Dimov
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!