Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    DataCls does autoregister

    General Discussion
    3
    4
    424
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kevin Galkov
      Kevin Galkov last edited by

      Hi, Backtrader Community!

      I am looking to use oandapyV20 instead of oandapy for the Oanda datastore that is in the codebase.
      My account needs to use the new api, that's why.

      I am confused about how the DataCls attribute [0] of the OandaStore is supposed to "auto" register?

      If I run the mementum/backtrader/samples/oandatest/oandatest.py , it complains:

      Traceback (most recent call last):
        File "/Users/kevin/pdev/tgkj/external/github/mementum/backtrader/samples/oandatest/oandatest.py", line 498, in <module>
          runstrategy()
        File "/Users/kevin/pdev/tgkj/external/github/mementum/backtrader/samples/oandatest/oandatest.py", line 310, in runstrategy
          cerebro.run(exactbars=args.exactbars)
        File "/usr/local/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "/usr/local/lib/python3.7/site-packages/backtrader/cerebro.py", line 1264, in runstrategies
          strat._start()
        File "/usr/local/lib/python3.7/site-packages/backtrader/strategy.py", line 413, in _start
          self.start()
        File "/Users/kevin/pdev/tgkj/external/github/mementum/backtrader/samples/oandatest/oandatest.py", line 180, in start
          if self.data0.contractdetails is not None:
        File "/usr/local/lib/python3.7/site-packages/backtrader/lineseries.py", line 461, in __getattr__
          return getattr(self.lines, name)
      AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'contractdetails'
      

      I think I might just want to specify: --no-store true , and then it will utilize OandaData?

      Otherwise, what do we mean by auto register?

      [0]
      https://github.com/mementum/backtrader/blob/93ad8e2e2d3674e4b1bc0207cea265091747e737/backtrader/stores/oandastore.py#L193

      vladisld B 2 Replies Last reply Reply Quote 0
      • vladisld
        vladisld @Kevin Galkov last edited by

        @Kevin-Galkov said in DataCls does autoregister:

        I am confused about how the DataCls attribute [0] of the OandaStore is supposed to "auto" register?

        I suppose the question is at which point the DataCls attribute of the OandaStore is initialized. This is happening during the instantiation of OandaData's metaclass (which by itself is happening during the chain of imports when the Backtrader module is imported into your code)

        class MetaOandaData(DataBase.__class__):
            def __init__(cls, name, bases, dct):
                '''Class has already been created ... register'''
                # Initialize the class
                super(MetaOandaData, cls).__init__(name, bases, dct)
        
                # Register with the store
                oandastore.OandaStore.DataCls = cls
        
        class OandaData(with_metaclass(MetaOandaData, DataBase)):
        ...
        

        This is done in order to support two different usage scenarios:

        1. The case where OandaData instance is instantiated directly, like:
        data0 = OandaData(dataname=args.data0, **datakwargs)
        
        1. The case where the OandaStore.getdata method is used for the same purpose:
        data0 = bt.stores.OandaStore.getdata(dataname=args.data0, **datakwargs)
        

        In case you need to use a different data class (like OandaV20), I'm afraid the new OandaStoreV2 should be introduced and initialized in a way similar to the original OandaStore. But probably there is another way and more experienced forum members may point it out.

        1 Reply Last reply Reply Quote 2
        • B
          backtrader administrators last edited by

          You have to use this:

          • https://github.com/ftomassetti/backtrader-oandav20

          The built-in module is only compatible with the old Oanda API.

          And oandatest.py works with the old built-in module.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @Kevin Galkov last edited by

            @Kevin-Galkov said in DataCls does autoregister:

            If I run the mementum/backtrader/samples/oandatest/oandatest.py , it complains:

            In any, it does complay because you don't have the proper package installed, you have something for v20.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors