Would someone please help. I keep getting object has no attribute here.
def CheckAndTrade(self):
if self.Portfolio.Cash < 100:
return
for symbol in self.crypto_symbol_list:
current_volume = self.Securities[symbol].Volume
avg_volume = self.Securities[symbol].AverageData['Volume'][self.lookback_period]
if (current_volume > self.volume_threshold * avg_volume
and self.Securities[symbol].BidVolume > self.bid_ask_ratio_threshold * self.Securities[symbol].AskVolume
and current_volume > self.min_daily_volume
and self.Securities[symbol].Exchange.DateTimeIsOpen(self.Time)):
self.BuyCrypto(symbol)
Mia Alissi
Based on the information provided in the extracts, it seems like the error is due to trying to access an attribute that doesn't exist for the object. In this case, it could be due to trying to access the
Volume,AverageData,BidVolume,AskVolume, orExchange.DateTimeIsOpenattributes of theSecurities[symbol]object.In QuantConnect, the
Securitiesobject is a dictionary where the key is the symbol of the security and the value is aSecurityobject. TheSecurityobject has aPriceattribute, but it doesn't haveVolume,AverageData,BidVolume,AskVolume, orExchange.DateTimeIsOpenattributes.To get the volume of a security, you can use the
Volumeattribute of aTradeBarobject. You can get the currentTradeBarobject for a security from theCurrentSliceobject in theOnDatamethod. Here is an example:To get the average volume, you can use the
SimpleMovingAverageindicator. Here is an example:To get the bid and ask volumes, you can use the
BidSizeandAskSizeattributes of aQuoteBarobject. Here is an example:To check if the exchange is open at the current time, you can use the
Exchangeproperty of theSecurityobject and theDateTimeIsOpenmethod. Here is an example:Please note that you need to replace
self.symbolwith the actual symbol of the security you are interested in. Also, you need to make sure that you have data for the security at the current time step. You can do this by checking ifdata.ContainsKey(self.symbol)isTrue.Sources:
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.
Ferjo Ombwayo
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!