Navigation

    Backtrader Community

    • Register
    • 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/

    sell_bracket() order: sell() got an unexpected keyword argument 'size'

    General Code/Help
    2
    3
    25
    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.
    • Healy Fuess
      Healy Fuess last edited by

      Re: TypeError: init() got an unexpected keyword argument 'size'

      Hello, I was looking at this post from last year and don't know whether it was solved or not. It looks like the sell() method isn't computing the size parameter properly when calling the sell_bracket() method.

      This is my python error:

      sell() got an unexpected keyword argument 'size'

      This is my code below:

      def sell(self, pivot_point_price, asset_key, target_retracement):
              entry_price = pivot_point_price - .1
              entry_price = round(entry_price, 2)
              exit_price = entry_price - target_retracement
              exit_price = round(exit_price, 2)
              stop_price = entry_price + (.5 * target_retracement)
              stop_price = round(stop_price, 2)
              size = utilities.determine_position_size(entry_price, stop_price)
      
              if type(self).__base__.__name__ == 'Strategy':
                  # TODO: what's going on with the size param?
                  super().sell_bracket(limitprice=exit_price, price=entry_price, stopprice=stop_price, size=1,
                                       valid=constants.VALID_ORDER_TIMEDELTA)
              else:
      
                  api.send_entry_trigger_oco_order_short(
                      entry_price, exit_price, stop_price, asset_key, size)
      
              self.order_list.append(asset_key)
      

      Stepping through the sell_bracket order I verified that the size parameter is being passed properly to the kwargs that then gets passed to self.sell(**kargs)

      Has anyone else experienced this? Let me know if you need anything else from me. Thanks.

      1 Reply Last reply Reply Quote 0
      • Healy Fuess
        Healy Fuess last edited by

        This is the full error:

        File "/Users/hfuess/trading/quantstream/env/lib/python3.9/site-packages/backtrader/strategy.py", line 1217, in sell_bracket o = self.sell(**kargs) TypeError: sell() got an unexpected keyword argument 'size'

        1 Reply Last reply Reply Quote 0
        • B
          BorutF last edited by

          Seems unusual to me.

          May I ask why do you even call super().sell_bracket ?

          Why not just self.sell_bracket ? Did you change sell_bracket somehow?

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