Hi All,

I'm using custom data. A lot of it is actually trading data - plain good old OHLCV bars/candles.

It just came to me that instead of using the usual way, documented here https://www.quantconnect.com/docs/algorithm-reference/importing-custom-data, basically returning a custom class object to encapsulate your custom data and then having to look into the fields of that custom object to access your data, if your custom data is basically TradeBar, you can simply return a TradeBar object that you create from your custom data, as such:

class MyCustomData(PythonData):
    def GetSource(self, config, date, isLive):
        source = "My source goes here for the given date"
        return SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile) # Could also be remote

    def Reader(self, config, line, date, isLive):
        data = line.split(",")
        return TradeBar(<Use data fields, for instance data[0], date and datetime.strptime() to compute the correct date and time for the beginning of the bar>, config.Symbol, float(data[1]), float(data[2]), float(data[3]), float(data[4]), float(data[5]), <Use timedelta to provide the period of the bar, for instance timedelta(minutes=1)>)

Then, when LEAN gives you your custom data, for instance in OnData, it is already TradeBar instead of your custom object, from which, oftentimes, you need to create a TradeBar anyway.

I guess I was somewhat blinded by the custom data documentation and did not think about it before now. Good thing if everyone else already thought about it. Also good thing if this helps at least one mate out there.

Fred