IB TWS code stuck in for loop

4 次查看(过去 30 天)
Benvaulter
Benvaulter 2016-5-11
Hey everyone,
I am using the Trading Toolbox to establish a connection to the IB TWS. In general, the API works fine and my code executes my intentions like retrieving real time data and executing orders.
What I would like to do now is executing my code block in a for-loop (to run through multiple strategies), but as soon as I attempt to execute the code in a for loop, the code appears to be stuck in an infinite loop, which I can only break by shutting down Matlab (even CTRL + c, won't do the trick in this case). My command window then rapdily displays IB error msgs like "Cannot unregister ‘xxx'", where xxx is a variety of IB functions such as tickPrice, tickData, etc..
The odd thing is, that when I manually highlight the code and run it (with F9), everything works like a charm. From my research it appears that it has something to do with the way the ib connection is handled. I open the ib connection at the beginning of the for loop (inside of it) and close it and the end of the loop (also inside the loop). I already attempted to pause the execution for 1-2 seconds after the "close"-command to ensure sufficient time for the connection to be properly closed but with no effect.
Can anyone help me out here or has an idea on how to tackle this problem?
Many thanks in advance!
  1 个评论
terry dylan
terry dylan 2019-1-10
i have encountered a similar problem, when connecting to IB, if i disconnect from IB using "clear ib", then the next time i connect to IB, and request data, the code will stuck in a while loop drawnow . The only way then is to re-open Matlab, or re-open TWS
I wonder if you have solved this problem, Please let me know
Best regards
Terry

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by