Hi all,

I would like to combine custom and quantconnect data in a custom data source. My use case: the KMLM ETF was issued End of 2020. I have more historical data from the underlying index. Therefore, I would like to combine both in a custom datasource that uses historical index data before 2021, and quantconnect data for the ETF after 2021-1-1. Since the algo trades a lot of different tickers, i would like to combine both data source into a single custom data source. 

Yet, I cannot figure out, how to access quantconnect data inside the custom data function. Here is my current approach. Any suggestions are highly appreciated:  

import pandas as pd
from datetime import datetime
from AlgorithmImports import *

class HybridKMLMXData(PythonData):
    def __init__(self):
        super().__init__()
        self.equity_symbol = Symbol.Create("KMLM", SecurityType.Equity, Market.USA)
        
    def GetSource(self, config, date, isLiveMode):
        source = "https://gist.githubusercontent.com/chrswrmr/3a7522de7c9429e6dc2c8d29627e6e33/raw/510aeeaa5dc64dbd2e59ee5138ac66edff9018ca/KMLMX_rev.csv"
        return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)
        
    def Reader(self, config, line, date, isLiveMode):
        try:
            if not line.strip() or line.startswith("date"):
                return None
                
            parts = line.split(",")
            parsed_date = pd.Timestamp(parts[0])
            
            if parsed_date < datetime(2021, 1, 1):
                data = HybridKMLMXData()
                data.Symbol = config.Symbol
                data.Time = parsed_date
                value = round(float(parts[1]), 4)
                data.Value = value
                data.Close = value
                return data
            else:
                data = HybridKMLMXData()
                data.Symbol = config.Symbol
                data.Time = parsed_date
                
                try:
                    equity_data = SubscriptionManager.GetDataPoint(self.equity_symbol, date, Resolution.Daily)
                    if equity_data is not None:
                        data.Value = equity_data
                        data.Close = equity_data
                    else:
                        data.Value = float(parts[1])  # Fallback to CSV data
                        data.Close = float(parts[1])
                except:
                    data.Value = float(parts[1])  # Fallback to CSV data
                    data.Close = float(parts[1])
                
                return data
                
        except Exception as e:
            print(f"Error processing data: {e}")
            return None

class CustomDataAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 12, 1)
        self.SetEndDate(2021, 1, 31)
        self.SetCash(100000)
        
        # Only add the hybrid data source
        self.symbol = self.AddData(HybridKMLMXData, "KMLMX", Resolution.Daily).Symbol
        
    def OnData(self, slice):
        # Access KMLMX data
        data = slice.Get(HybridKMLMXData).get(self.symbol)
        if data:
            self.Log(f"KMLMX - Date: {data.Time}, Close: {data.Close}")