Open vocsong opened 2 hours ago
Some other related TWS logs:
2024-10-18 21:12:54.373 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 730443243 no sec defs returned forSecDef reqId=PreferredReqByConid237
2024-10-18 21:12:54.373 [QY] INFO [JTS-Async-35] - CM IB PORT Uxxxxxxx./1/147565047: Getting unknown EC instance for conid 730443243...
2024-10-18 21:12:54.373 [QY] WARN [JTS-Async-35] - Requesting unknown Ec for conid 730443243
2024-10-18 21:12:54.373 [QY] ERROR [AWT-EventQueue-0] - Instrumented AsyncScheduler action stats in OLT min: 0, max: 0, avg: 0 size: 0
2024-10-18 21:12:54.373 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 730443243
2024-10-18 21:12:54.373 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 730443243
2024-10-18 21:12:54.374 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 730443310 no sec defs returned forSecDef reqId=PreferredReqByConid238
2024-10-18 21:12:54.374 [QY] INFO [JTS-Async-35] - CM IB PORT Uxxxxxxx./1/147565047: Getting unknown EC instance for conid 730443310...
2024-10-18 21:12:54.374 [QY] WARN [JTS-Async-35] - Requesting unknown Ec for conid 730443310
2024-10-18 21:12:54.374 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 730443310
2024-10-18 21:12:54.374 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 730443310
2024-10-18 21:12:54.375 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 728290422 no sec defs returned forSecDef reqId=PreferredReqByConid240
2024-10-18 21:12:54.375 [QY] INFO [JTS-Async-35] - CM IB PORT Uxxxxxxx./1/147565047: Getting unknown EC instance for conid 728290422...
2024-10-18 21:12:54.375 [QY] WARN [JTS-Async-35] - Requesting unknown Ec for conid 728290422
2024-10-18 21:12:54.375 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 728290422
2024-10-18 21:12:54.375 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 728290422
2024-10-18 21:12:54.373 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 730443243
2024-10-18 21:12:54.373 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 730443243
2024-10-18 21:12:54.374 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 730443310 no sec defs returned forSecDef reqId=PreferredReqByConid238
2024-10-18 21:12:54.374 [QY] INFO [JTS-Async-35] - CM IB PORT Uxxxxxxx./1/147565047: Getting unknown EC instance for conid 730443310...
2024-10-18 21:12:54.374 [QY] WARN [JTS-Async-35] - Requesting unknown Ec for conid 730443310
2024-10-18 21:12:54.374 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 730443310
2024-10-18 21:12:54.374 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 730443310
2024-10-18 21:12:54.375 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 728290422 no sec defs returned forSecDef reqId=PreferredReqByConid240
2024-10-18 21:12:54.375 [QY] INFO [JTS-Async-35] - CM IB PORT Uxxxxxxx./1/147565047: Getting unknown EC instance for conid 728290422...
2024-10-18 21:12:54.375 [QY] WARN [JTS-Async-35] - Requesting unknown Ec for conid 728290422
2024-10-18 21:12:54.375 [QY] ERROR [JTS-Async-35] - Creating unknown contract for conid 728290422
2024-10-18 21:12:54.375 [QY] ERROR [JTS-Async-35] - Requesting unknown DefContent for conid 728290422
2024-10-18 21:12:54.376 [QY] INFO [JTS-CCPDispatcherS2-41] - Error: no preferred EC for conid 730443341 no sec defs returned forSecDef reqId=PreferredReqByConid239
these happened in huge chunks, i only copy a snippet..
That does sound odd.
Generally, "no security definition found" is what IBKR says after a contract id has expired and you just can't look it up anymore.
If the logs are showing error messages of Error: Cannot find market rule for conid
then it looks more like an IBKR data problem somewhere. Maybe also log the full contract object too so we can see which ones are failing the lookup.
You can also try running an updated gateway version and also configure it with at least 4096 MB RAM under Settings: https://investors.interactivebrokers.com/en/index.php?f=16454 — it's technically just a headless TWS, but TWS has never worked great for me anyway.
Thanks for the quick response. I did some more testing. StartupFetchNONE connected while StartupFetchALL hits the same issue I saw this fetching was merged since June, can i understand what's the potential implication of not fetching?
abit more isolation.. i only got the issue when i fetch executions
ib.connect('127.0.0.1', 7496, clientId=777, fetchFields=StartupFetch.EXECUTIONS, raiseSyncErrors=True )
ConnectionError: ['executions request timed out']
i only got the issue when i fetch executions
oh, I see what you're saying.
If it works with NONE, then it must mean somehow your IBKR historical data can't be loaded (expired contracts again?) — but the original problem was also using NONE above too?
There are bugs in TWS/Gateway where sometimes if it gets bad connection attempts or data loading attempts, the entire gateway just stops responding until a full exit/restart (but, if you restart and the next connect attempt generates another bad session, it would continue breaking i guess).
Yes, the fetchFields
is an advanced feature and if you don't need it you can leave it undefined. The purpose is to just speed up startup time if you don't want the connect call to load all account data on startup (fetching executions is usually slow and can be delayed until later if run manually).
So one good usage is requesting "load ALL data but not EXECUTIONS":
fetchFields=ib_async.StartupFetchALL & ~ib_async.StartupFetch.EXECUTIONS,
If you wanted to figure out which fields are breaking for you, you could run through different combinations... StartupFetchALL
is just the union of all possible account data on startup:
StartupFetchALL =
StartupFetch.POSITIONS
| StartupFetch.ORDERS_OPEN
| StartupFetch.ORDERS_COMPLETE
| StartupFetch.ACCOUNT_UPDATES
| StartupFetch.SUB_ACCOUNT_UPDATES
| StartupFetch.EXECUTIONS
The logic for how all those fields are read is here: https://github.com/ib-api-reloaded/ib_async/blob/38cf54a66a4daefbd3fd1d7476381f0d178a8198/ib_async/ib.py#L2030-L2070 — it shows which APIs get called for each data request, but you can also run each of those API data fetches yourself for more debugging too (if only 1 of the 6 is failing or the order required isn't working for some reason).
Recently I'm encountering some weird connectivity errors that I've never seen before in past 2-3yrs running my bot. I highly suspect its TWS side issue but I can't really figure out.
Some background:
Some added tests I did to give more context:
At this point i already kinda figure out its some corrupted data somehow on my username when connecting. So I did some own investigating and try to narrow the code to replicate the issue in jupytor notebook:
Here's the errors:
The above error doesnt help much its just timeout error. I further dug into the ib_insync/ib_async code and see the issue happening here in client.py > connectAsync():
await asyncio.wait_for(ib.client.apiStart, timeout)
I even contacted the IBKR technical support but they're not in anyway helping, giving me random excuses like ib_insync not compatible and their TWS API had recent changelogs which are totally not true.
So i retrieved the TWS log in diagnostic detailed logging, this chunk always happen whenever i do a connect:
From what I have so far (above) it seems like something went missing in my account somehow and causing subsequent connect to timeout.
my current workaround if this ever happens is to keep switching the username every other day.. subscribing to marketdata on both username.. which is not the most ideal..
I'm just kinda documenting it here to see if anyone also encounter anything similar.. Or anyone have any idea what else can I try resolve this or even anyone who understand whats going on could help explain and advise anything.. or is there something i can do on ib_async side to prevent triggering the dummy error..
any help would be deeply appreciated. thanks.