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/

    AttributeError: module 'oandapy' has no attribute 'OandaError'

    General Discussion
    2
    3
    517
    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.
    • M
      mayuequn last edited by

      when run the 'backtrader' example, it shows the error,
      do anyone have the solution to it?

      python code:

      from datetime import datetime
      import backtrader as bt
      
      # Create a subclass of Strategy to define the indicators and logic
      
      class SmaCross(bt.Strategy):
          # list of parameters which are configurable for the strategy
          params = dict(
              pfast=10,  # period for the fast moving average
              pslow=30   # period for the slow moving average
          )
      
          def __init__(self):
              sma1 = bt.ind.SMA(period=self.p.pfast)  # fast moving average
              sma2 = bt.ind.SMA(period=self.p.pslow)  # slow moving average
              self.crossover = bt.ind.CrossOver(sma1, sma2)  # crossover signal
      
          def next(self):
              if not self.position:  # not in the market
                  if self.crossover > 0:  # if fast crosses slow to the upside
                      self.buy()  # enter long
      
              elif self.crossover < 0:  # in the market & cross to the downside
                  self.close()  # close long position
      
      
      cerebro = bt.Cerebro()  # create a "Cerebro" engine instance
      
      # Create a data feed
      data = bt.feeds.YahooFinanceData(dataname='MSFT',
                                       fromdate=datetime(2011, 1, 1),
                                       todate=datetime(2012, 12, 31))
      
      cerebro.adddata(data)  # Add the data feed
      
      cerebro.addstrategy(SmaCross)  # Add the trading strategy
      cerebro.run()  # run it all
      cerebro.plot()  # and plot it with a single command
      

      it shows error:

      Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]
      Type "copyright", "credits" or "license" for more information.

      IPython 7.10.2 -- An enhanced Interactive Python.

      runfile('D:/Python Project/MT5/test3.py', wdir='D:/Python Project/MT5')
      Traceback (most recent call last):

      File "D:\Python Project\MT5\test3.py", line 9, in <module>
      import backtrader as bt

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader_init_.py", line 62, in <module>
      from .cerebro import *

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader\cerebro.py", line 35, in <module>
      from .brokers import BackBroker

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader\brokers_init_.py", line 35, in <module>
      from .vcbroker import VCBroker

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader\brokers\vcbroker.py", line 35, in <module>
      from backtrader.stores import vcstore

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader\stores_init_.py", line 38, in <module>
      from .oandastore import OandaStore

      File "d:\winpython\python-3.7.6.amd64\lib\site-packages\backtrader\stores\oandastore.py", line 41, in <module>
      class OandaRequestError(oandapy.OandaError):

      AttributeError: module 'oandapy' has no attribute 'OandaError'

      anyone can help this?? Many thanks.

      Nick

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Please take a look at the following post: https://community.backtrader.com/topic/1879/backtrader-oandapy-and-oandaerror-issues

        Could it be relevant ?

        1 Reply Last reply Reply Quote 0
        • M
          mayuequn last edited by

          :), Many thanks. It indeed solved the issue!!

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