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.DateTimeIsOpen
attributes of theSecurities[symbol]
object.In QuantConnect, the
Securities
object is a dictionary where the key is the symbol of the security and the value is aSecurity
object. TheSecurity
object has aPrice
attribute, but it doesn't haveVolume
,AverageData
,BidVolume
,AskVolume
, orExchange.DateTimeIsOpen
attributes.To get the volume of a security, you can use the
Volume
attribute of aTradeBar
object. You can get the currentTradeBar
object for a security from theCurrentSlice
object in theOnData
method. Here is an example:To get the average volume, you can use the
SimpleMovingAverage
indicator. Here is an example:To get the bid and ask volumes, you can use the
BidSize
andAskSize
attributes of aQuoteBar
object. Here is an example:To check if the exchange is open at the current time, you can use the
Exchange
property of theSecurity
object and theDateTimeIsOpen
method. Here is an example:Please note that you need to replace
self.symbol
with 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!