Hello all,

I am trying to read in local forex data from .csv files. The files are located under ./Data/own. To do this, I have created a class in Python that implements the GerSource() and Reader() methods of the PythonData base class. After processing the method Initialize() in main, the following error message appears.

main.py

  1. from AlgorithmImports import *
  2. from dataReader import MyDataReader
  3. class RetrospectiveOrangeBat(QCAlgorithm):
  4. def Initialize(self):
  5. self.SetStartDate(2013, 10, 7) # Set Start Date
  6. self.SetEndDate(2013, 10, 11) # Set End Date
  7. self.SetCash(100000) # Set Strategy Cash
  8. self.pair = self.AddData(MyDataReader, 'EURUSD', Resolution.Daily, leverage=20).Symbol
  9. def OnData(self, data: Slice):
  10. if not self.Portfolio.Invested:
  11. self.MarketOrder(self.pair, 10000)

datareader.py

  1. from AlgorithmImports import *
  2. from pathlib import Path
  3. from datetime import datetime, timedelta
  4. class MyDataReader(PythonData):
  5. def GetSource(self, config : SubscriptionDataConfig, date : datetime, isLiveMode : bool) -> SubscriptionDataSource:
  6. fileName = '2013.csv'
  7. path2file = Path(Globals.DataFolder, 'own', fileName)
  8. return SubscriptionDataSource(path2file.as_posix(), SubscriptionTransportMedium.LocalFile)
  9. def Reader(self, config : SubscriptionDataConfig, line : str, date : datetime, isLiveMode : bool) -> BaseData:
  10. print(line)
  11. bar = TradeBar()
  12. data = line.split(',')
  13. bar.Time = datetime.strptime(data[0], "%Y-%m-%d %H:%M:%S")
  14. bar.EndTime = bar.Time + timedelta(days=1) - timedelta(milliseconds=1)
  15. bar.Value = data[4]
  16. bar.Open = float(data[1])
  17. bar.High = float(data[2])
  18. bar.Low = float(data[3])
  19. bar.Close = float(data[4])
  20. bar.Volume = 0.0
  21. return bar
+ Expand

 

20231024 13:27:30.940 ERROR:: <>c__DisplayClass1_0.b__0(): Subscription worker task exception EURUSD,#0,EURUSD,Daily,PythonData,Trade,Adjusted,OpenInterest. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference at CallSite.Target(Closure , CallSite , Object , SubscriptionDataConfig , DateTime , Boolean ) at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) at QuantConnect.Python.PythonData.GetSource(SubscriptionDataConfig config, DateTime date, Boolean isLiveMode) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Python/PythonData.cs:line 99 at QuantConnect.Lean.Engine.DataFeeds.SubscriptionDataReader.UpdateDataEnumerator(Boolean endOfEnumerator) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/SubscriptionDataReader.cs:line 413 at QuantConnect.Lean.Engine.DataFeeds.SubscriptionDataReader.Initialize() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/SubscriptionDataReader.cs:line 251 at QuantConnect.Lean.Engine.DataFeeds.SubscriptionDataReader.MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/SubscriptionDataReader.cs:line 269 at QuantConnect.Lean.Engine.DataFeeds.Enumerators.SynchronizingEnumerator`1.GetBruteForceMethod(IEnumerator`1[] enumerators)+MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/Enumerators/SynchronizingEnumerator.cs:line 143 at QuantConnect.Lean.Engine.DataFeeds.Enumerators.SynchronizingEnumerator`1.MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/Enumerators/SynchronizingEnumerator.cs:line 91 at QuantConnect.Lean.Engine.DataFeeds.Enumerators.SubscriptionFilterEnumerator.MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/Enumerators/SubscriptionFilterEnumerator.cs:line 123 at QuantConnect.Lean.Engine.DataFeeds.SubscriptionUtils.<>c__DisplayClass1_0.b__0(Int32 workBatchSize) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/SubscriptionUtils.cs:line 93


I am using the latest docker image from lean cli. Do you have any ideas why this error message appears?

Author

Simon

October 2023