IBRK TWS API error() takes 4 positional arguments but 5 were given

Question:

If I run a basic TWS example, I receive the error message . If I comment out the error() call back it runs fine. I’ve tried this on several examples and get the same result.

    Exception has occurred: TypeError
    
    error() takes 4 positional arguments but 5 were given
    
    File "/Users/jayurbain/Dropbox/twsapi/Algorithmic Trading using Interactive Broker's 
    Python API /ib_basic_app.py", line 20, in <module> app.run()

Please advise.

Here’s the call back that is being overridden in wrapper.py:

    def error(self, reqId:TickerId, errorCode:int, errorString:str, advancedOrderRejectJson = ""):

Here is the entire code:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
 
class TradingApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self,self)
        
    def error(self, reqId, errorCode, errorString):
        print("Error {} {} {}".format(reqId,errorCode,errorString))
 
app = TradingApp()      
app.connect("127.0.0.1", 7497, clientId=1)
app.run()
Asked By: jayurbain

||

Answers:

There are breaking API changes in versions starting 10.14.
Since there is another argument for the error callback, you need to include it in args.

def error(self, reqId, errorCode, errorString, advancedOrderRejectJson):
    print("Error {} {} {}".format(reqId,errorCode,errorString))
Answered By: misantroop

The solution to the problem was to execute python setup install rather than using pip to install ibapi. Thanks for your answers.

Answered By: jayurbain

I had the same problem with IBAPI version 1019.01 as well as 1025.01.

I just added a dummy argument to def error() in wrapper.py :

def error(self, reqId:TickerId, errorCode:int, errorString:str, advancedOrderRejectJson = "", arg5 = ""):
Answered By: Kishore
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.