data class autoregister



  • hi
    I dont understand how DataCls is autoregistered in backtrader.stores.IBStore.
    The code in backtrader.stores.ibstore:

    class IBStore(with_metaclass(metasingleton,object)):
        #######
        DataCls = None # DataCls will autoregister?
        @classmethed
        def getdata(##):
            return cls.DataCls(###)
    

    When I create a Singleton of class IBStore by

    store = backtrader.stores.IBStore(####)
    

    and then I can get a ibdata instance by calling the store's method as your doc explained:

    data = store.getdata(####)
    

    so how it is done?


  • administrators

    Because the data feed IBData registers itself in the store overwriting DataCls. This would allow anyone to write a different version of IBData (call it MyIBData), which would again overwrite the value of DataCls in the store.

    And consequently, getdata would return an instance of MyIBData


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.