添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I have been running TWS API with Python for years without many issues. Suddenly my code that worked yesterday is no longer working. Any file I run, I get an error like this:

Traceback (most recent call last):
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 296, in <module>
main()
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 287, in main
app.run()
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 409, in run
self.decoder.interpret(fields)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1377, in interpret
self.interpretWithSignature(fields, handleInfo)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1358, in interpretWithSignature
method(*args)
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 515, in nextValidId
self.start()
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 137, in start
self.runWithoutSchedule()
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 466, in runWithoutSchedule
self.decoder.interpret(fields)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1379, in interpret
handleInfo.processMeth(self, iter(fields))
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1273, in processErrorMsg
self.wrapper.error(reqId, errorCode, errorString, advancedOrderRejectJson)
TypeError: TestApp.error() takes 4 positional arguments but 5 were given

I am running Windows 10, TWS Latest, API Latest. About the time this error started, I had to switch from Visual Studio Code to Visual Studio Code Insiders. Python files run regularly under VS Code Insiders just fine.

What could cause this to happen?
I came across this the other day.  I believe that IB has been making major changes to the API (in minor patch releases).

Look for your definition of error().  It now takes 5 arguments and not 4.

So something like this:

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

Needs to be changed to:

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

Take a look at the API Docs.  They have some boilerplate code around using that new advancedOrderRejectionJson parameter.

-s

toggle quoted message Show quoted text
On Thu, Aug 11, 2022, at 6:27 PM, Joel Gross wrote:
I have been running TWS API with Python for years without many issues. Suddenly my code that worked yesterday is no longer working. Any file I run, I get an error like this:


Traceback (most recent call last):
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 296, in <module>
main()
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 287, in main
app.run()
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 409, in run
self.decoder.interpret(fields)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1377, in interpret
self.interpretWithSignature(fields, handleInfo)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1358, in interpretWithSignature
method(*args)
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 515, in nextValidId
self.start()
File "c:\Users\joel\joelvscode\ib\ibapp\ibapi\value_stock_picker\11_get_tws_fundamental_data.py", line 137, in start
self.runWithoutSchedule()
File "c:\users\joel\joelvscode\ib\ibapp\ibapi\launchLoop.py", line 466, in runWithoutSchedule
self.decoder.interpret(fields)
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1379, in interpret
handleInfo.processMeth(self, iter(fields))
File "c:\Users\joel\joelvscode\.venv\lib\site-packages\ibapi\decoder.py", line 1273, in processErrorMsg
self.wrapper.error(reqId, errorCode, errorString, advancedOrderRejectJson)
TypeError: TestApp.error() takes 4 positional arguments but 5 were given

I am running Windows 10, TWS Latest, API Latest. About the time this error started, I had to switch from Visual Studio Code to Visual Studio Code Insiders. Python files run regularly under VS Code Insiders just fine.

What could cause this to happen?

Nope. The advancedOrderRejectJson field was introduced in API version 10.14.01 in January 2022 and went through beta and is, obviously, in the current "latest" version 10.17.01.

Version 10 has many and large changes compared with the current stable version 9.81 and is still rapidly getting new features.

Jürgen

On Thu, Aug 11, 2022 at 06:20 PM, @sbank wrote:

Well, if your code was written against a version 9 API, you might want to stay with the stable API  9.81 track for now. You can still run your code against all (even the latest and beta) TWS and IBGW versions. It's a good practice to lock the API version in and to avoid automatic and uncontrolled version changes.

But by its nature, the stable track is a couple years old and is lacking the latest features version 10 provides. So you might want to start the development, unit, system, and regression testing cycles so that you can eventually move to the version 10 API.

Jürgen

On Thu, Aug 11, 2022 at 08:44 PM, Joel Gross wrote: