Effacer les filtres
Effacer les filtres

IB TWS code stuck in for loop

2 vues (au cours des 30 derniers jours)
Benvaulter
Benvaulter le 11 Mai 2016
Commenté : terry dylan le 10 Jan 2019
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 commentaire
terry dylan
terry dylan le 10 Jan 2019
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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by