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/

    weird error TypeError: __call__() got an unexpected keyword argument 'data'

    General Discussion
    2
    3
    27
    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.
    • Shaoqiang Ran
      Shaoqiang Ran last edited by

      
      
        File "/Users/django/Documents/inv/xsk/venv/lib/python3.9/site-packages/backtrader/strategy.py", line 309, in _oncepost
          self.next()
        File "/Users/django/Documents/inv/xsk/xsk_strategy/zigzag_ema.py", line 72, in next
          self.order_target_percent(self.datas[0], self.p.max_position)
        File "/Users/django/Documents/inv/xsk/venv/lib/python3.9/site-packages/backtrader/strategy.py", line 1376, in order_target_percent
          return self.order_target_value(data=data, target=target, **kwargs)
        File "/Users/django/Documents/inv/xsk/venv/lib/python3.9/site-packages/backtrader/strategy.py", line 1322, in order_target_value
          return self.buy(data=data, size=size, price=price, **kwargs)
      TypeError: __call__() got an unexpected keyword argument 'data'
      

      when i run strategy's buy function i got this error, i go into the source code and cannot find anything wrong.

      here is the calling statement

        if target > value:
                      size = comminfo.getsize(price, target - value)
                      return self.buy(data=data, size=size, price=price, **kwargs)
      

      and here is buy function:

        def buy(self, data=None,
                  size=None, price=None, plimit=None,
                  exectype=None, valid=None, tradeid=0, oco=None,
                  trailamount=None, trailpercent=None,
                  parent=None, transmit=True,
                  **kwargs):
      

      it's really weird, can some one help solve this ?

      1 Reply Last reply Reply Quote 0
      • L
        Lennie last edited by

        I'm going to guess that you are missing the self object as in
        data=self.data

        Shaoqiang Ran 1 Reply Last reply Reply Quote 0
        • Shaoqiang Ran
          Shaoqiang Ran @Lennie last edited by

          @Lennie ```
          if self.buy[0]: # 买入
          self.show_status()
          if port_perc <= 0:
          self.order_target_percent(self.datas[0], self.p.max_position)

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