Hello Mia! I'm encountering API compatibility issues when deploying my Smart Stock Scanner to QuantConnect. I need your help to ensure I'm using the correct QuantConnect API methods and properties.

 

Current Errors:

Error 1: ATR Indicator

Plain Text

 

TypeError: Trying to dynamically access a method that does not exist
at: self.atr = algorithm.ATR(symbol, config.ATR_PERIOD, MovingAverageType.Simple, Resolution.Daily)
in symbol_data.py: line 60

My current code:

Python

 

from QuantConnect.Indicators import MovingAverageType
self.atr = algorithm.ATR(symbol, config.ATR_PERIOD, MovingAverageType.Simple, Resolution.Daily)

Questions:

  • Is this the correct way to create an ATR indicator in QuantConnect?
  • Should I use algorithm.ATR() or a different method?
  • What are the correct parameters for ATR?
  • Do I need to warm up the indicator?

 

Error 2: Slice Data Access

Plain Text

 

TypeError: method does not exist
at: if not slice_data.ContainsKey(BenzingaNews):
at: news_data = slice_data.Get(BenzingaNews)

My current code:

Python

 

if not slice_data.ContainsKey(BenzingaNews):
    return
news_data = slice_data.Get(BenzingaNews)

Questions:

  • Is ContainsKey and Get the correct way to access slice data?
  • Should I use slice_data.ContainsKey(BenzingaNews) or BenzingaNews in slice_data?
  • What's the correct way to check if news data exists in a slice?

 

Error 3: Bar Properties

Python

 

# My current code:
symbol_data.update_price(bar.Close)
symbol_data.update_volume(bar.Volume)

Questions:

  • Is bar.Close and bar.Volume correct (PascalCase)?
  • Or should I use bar.close and bar.volume (snake_case)?

 

Error 4: ObjectStore Access

Python

 

# My current code:
if self.object_store.ContainsKey(config.OBJECTSTORE_KEY):
    symbols_str = self.object_store.Read(config.OBJECTSTORE_KEY)

Questions:

  • Is ContainsKey and Read correct for ObjectStore?
  • Or should I use different methods?

 

General Questions:

Python vs C# API:

  • QuantConnect uses C# API with Python wrapper
  • Should I use PascalCase (C# style) or snake_case (Python style)?
  • When should I use which naming convention?

Common Mistakes:

  • What are the most common API mistakes when using QuantConnect with Python?
  • Are there any methods that look similar but behave differently?

Best Practices:

  • What's the recommended way to access slice data?
  • What's the recommended way to create indicators?
  • Should I check indicator readiness before using values?

Code Review:

  • Can you review my code snippets above and point out any issues?
  • Are there any other potential API compatibility problems?

 

My Environment:

  • Platform: QuantConnect Cloud
  • Language: Python
  • Mode: Live Trading (Paper)
  • Data: Benzinga News + Equity data
  • Indicators: ATR, RSI, MACD, Bollinger Bands

 

Please provide:

  1. Correct code examples for each error
  2. Explanation of the correct API usage
  3. Any other potential issues you see
  4. Best practices for QuantConnect Python API

Thank you for your help! 🙏"**