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/

    TypeError: error() takes 2 positional arguments but 4 were given

    General Code/Help
    3
    5
    969
    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.
    • D
      dongiulio last edited by

      Hello,

      I'm switching my strategy to paper trading on interactivebrokers, the strangest thing is happening, this is my error as logged:

      --------------------
      
      ---> pavement.run
      Traceback (most recent call last):
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/ext/EClientSocket.py", line 958, in placeOrder
          self.send(order.m_tif)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/lib/overloading.py", line 82, in __call__
          return func(*args)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/ext/EClientSocket.py", line 1754, in send_1
          self.m_dos.write(val)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/lib/__init__.py", line 152, in write
          send(pack('!c', char))
      BrokenPipeError: [Errno 32] Broken pipe
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/paver/tasks.py", line 201, in _run_task
          return do_task()
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/paver/tasks.py", line 198, in do_task
          return func(**kw)
        File "pavement.py", line 133, in run
          raise SystemExit(main([CODE_DIRECTORY] + args))
        File "/Users/me/Documents/me/trading/trader/trader/main.py", line 79, in main
          raise error
        File "/Users/me/Documents/me/trading/trader/trader/main.py", line 76, in main
          action(options)
        File "/Users/me/Documents/me/trading/trader/trader/main.py", line 40, in _live
          live.run()
        File "/Users/me/Documents/me/trading/trader/trader/live.py", line 59, in run
          self.stats = self.cerebro.run()
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/cerebro.py", line 1298, in runstrategies
          self._runnext(runstrats)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/cerebro.py", line 1630, in _runnext
          strat._next()
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/strategy.py", line 347, in _next
          super(Strategy, self)._next()
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/lineiterator.py", line 271, in _next
          self.next()
        File "/Users/me/Documents/me/trading/trader/trader/strategies/BankTradingStrategy.py", line 190, in next
          self.short_trade = self.place_short()
        File "/Users/me/Documents/me/trading/trader/trader/strategies/BankTradingStrategy.py", line 115, in place_short
          limitprice=price - limitdistance)
        File "/Users/me/Documents/me/trading/trader/trader/SupportStrategy.py", line 43, in sell_bracket
          orders = super(SupportStrategy, self).sell_bracket(**kargs)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/strategy.py", line 1217, in sell_bracket
          o = self.sell(**kargs)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/strategy.py", line 969, in sell
          **kwargs)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/brokers/ibbroker.py", line 391, in sell
          return self.submit(order)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/brokers/ibbroker.py", line 337, in submit
          self.ib.placeOrder(order.m_orderId, order.data.tradecontract, order)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/backtrader/stores/ibstore.py", line 1286, in placeOrder
          self.conn.placeOrder(orderid, contract, order)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/lib/__init__.py", line 60, in inner
          return func(*args, **kwds)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/ext/EClientSocket.py", line 1155, in placeOrder
          self.error_0(id, EClientErrors.FAIL_SEND_ORDER, str(e))
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/lib/__init__.py", line 60, in inner
          return func(*args, **kwds)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/ext/EClientSocket.py", line 1709, in error_0
          self.m_anyWrapper.error(id, errorCode, errorMsg)
        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/lib/overloading.py", line 82, in __call__
          return func(*args)
      TypeError: error() takes 2 positional arguments but 4 were given
      

      I can reproduce this with:

              (Pdb) self.sell_bracket(price= 1.1350936200039081, exectype= 4, stopprice= 1.1373796835411358, limitprice= 1.1298980210556635)
              *** TypeError: error() takes 2 positional arguments but 4 were given
              (Pdb) self.sell_bracket(price= 1.1350936200039081, exectype= 4, stopprice= 1.1373796835411358, limitprice= 1.1298980210556635)
              [<backtrader.brokers.ibbroker.IBOrder object at 0x12b0b9668>, <backtrader.brokers.ibbroker.IBOrder object at 0x12b0b9908>, <backtrader.brokers.ibbroker.IBOrder object at 0x12b0b9ac8>]
              (Pdb)
      

      basically sell_bracket fails only at the first call. the following ones see no problems

      any ideas?

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

        You could let us know that exectype=4 is StopLimit which differs from the standard Limit which is shown by Interactive Brokers for bracket oerder.

        @dongiulio said in TypeError: error() takes 2 positional arguments but 4 were given:

        File "/Users/me/Documents/me/trading/trader/trader_venv/lib/python3.7/site-packages/ib/ext/EClientSocket.py", line 1155, in placeOrder
            self.error_0(id, EClientErrors.FAIL_SEND_ORDER, str(e))
        

        You could then look at this, which means the order wasn't sent and Interactive Brokers is probably giving you a huge warning and the TWS console is showing something, including orders which may have been created but not sent.

        Since you try again, TWS interprets you are ok with the huge ignored warning.

        1 Reply Last reply Reply Quote 0
        • D
          dongiulio last edited by

          Apologies for the late response, somehow I ran out of free time for this project, and was busy with something else.

          @backtrader said in TypeError: error() takes 2 positional arguments but 4 were given:

          You could let us know that exectype=4 is StopLimit which differs from the standard Limit which is shown by Interactive Brokers for bracket oerder.

          exectype=4 is the result of exectype=bt.Order.StopLimit, I got that value by copy pasting the params for the method call.

          You could then look at this, which means the order wasn't sent and Interactive Brokers is probably giving you a huge warning and the TWS console is showing something, including orders which may have been created but not sent.
          Since you try again, TWS interprets you are ok with the huge ignored warning.

          I checked on TWS log, it complains about number format,

          2019-03-15 17:00:59.175 [HR] ERROR [JTS-EServerSocket-372] - [35:62:76:1:0:0:0:ERR] Client socket broken - 
          java.lang.NumberFormatException: For input string: "1.132"
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
            at java.lang.Integer.parseInt(Integer.java:580)
            at java.lang.Integer.parseInt(Integer.java:615)
            at jextend.bb.p(bb.java:908)
            at jextend.dI.aZ(dI.java:2517)
            at jextend.dI.run(dI.java:2114)
            at java.lang.Thread.run(Thread.java:748)
          

          obviously my entry price (1.132) is not an Int, I'm not sure how should I represent my entry price as an int.

          1 Reply Last reply Reply Quote 0
          • D
            dongiulio last edited by

            found my issue:

            A StopLimit order requires the plimit parameter, to specify at which price to activate the limit order, somehow I managed to get through backtesting without setting it, but interactive broker didn't like it.

            apologies for the noise.

            1 Reply Last reply Reply Quote 2
            • Purinda Gunasekara
              Purinda Gunasekara last edited by

              @dongiulio thanks for coming back and posting the solution, helped me get through the IB integration.

              cheers

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