IbcAlpha / IBC

Automation of Interactive Brokers TWS. You can download the latest release here: https://github.com/ibcalpha/ibc/releases/latest
GNU General Public License v3.0
1.02k stars 178 forks source link

java.lang.ArrayIndexOutOfBoundsException when running ibc #262

Closed lvxhnat closed 2 weeks ago

lvxhnat commented 1 month ago

I am trying to run IBC using ib-insync, this is the code:

    ibc = IBC(10.19, gateway=True, tradingMode='live', userid="user", password="pass")
    ibc.start()
    IB.run()

ibc is installed in /opt/ibc and gateway in ~/Applications. I am unfamiliar to Java, where can I start to debug this issue, or what is the cause of this in the first place?

mktemp: mkstemp failed on Q17CZH0E: Permission denied
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by feature.search.recorder.JtsMultiLookAndFeel (file:/Users/jidm/Applications/IB%20Gateway%2010.19/jars/twslaunch-1019.jar) to method javax.swing.UIManager.getLAFState()
WARNING: Please consider reporting this to the maintainers of feature.search.recorder.JtsMultiLookAndFeel
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Jul 24, 2024 4:14:45 PM com.sun.glass.ui.mac.MacApplication lambda$waitForReactivation$6
WARNING: Timeout while waiting for app reactivation
RenderJob.run: internal exception
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
        at java.base/java.util.Arrays$ArrayList.get(Arrays.java:4351)
        at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1310)
        at javafx.graphics/com.sun.glass.ui.Screen.getMainScreen(Screen.java:61)
        at javafx.graphics/com.sun.prism.es2.ES2Pipeline.getScreenForAdapter(ES2Pipeline.java:147)
        at javafx.graphics/com.sun.prism.es2.ES2Pipeline.findDefaultResourceFactory(ES2Pipeline.java:158)
        at javafx.graphics/com.sun.prism.es2.ES2Pipeline.getDefaultResourceFactory(ES2Pipeline.java:179)
        at javafx.graphics/com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipeline.java:151)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.lambda$createResourceFactory$2(QuantumRenderer.java:161)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
        at javafx.graphics/com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
        at java.base/java.lang.Thread.run(Thread.java:829)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2024-07-24 16:15:38:925 IBC: IBC closing after TWS/Gateway failed to display login dialog
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rlktradewright commented 1 month ago

You are invoking something called IBC, presumably from your Python code.

But there is nothing in the IBC code base called IBC. What actually starts IBC is a Bash script called ibcstart.sh.

Clearly this thing called IBC is actually managing to start IBC, because the message at the end is output by IBC when Gateway doesn't behave properly. So presumably the thing called IBC is itself invoking ibcstart.sh. but I have no idea what that thing is or where it is or what else it does.

In other words, your problem is not an IBC issue: you need to discuss this with whoever now maintains ib-insync.

lvxhnat commented 1 month ago

@rlktradewright Thank you for your quick reply. I am trying to use the script twsstartmacos.sh instead now to start, instead of depending on ibcstart.sh. I am running

# After sudo chmod o+x *.sh */*.sh the contents of the /opt/ibc folder
# In /opt/ibc
sh twsstartmacos.sh

however, when i do so, it simply returns me

tab 1 of window id 169

and nothing happens (tws is not logged in). i have configured my username and password in ~/ibc/config.ini and the one in /opt/ibc but neither works. any idea what is causing this issue?

rlktradewright commented 1 month ago

twsstartmacos.sh is a Bash script, so you need to make sure you're running it with Bash. I beleieve the default shell on macOS is NOT Bash.

So try:

bash twsstartmacos

lvxhnat commented 1 month ago

@rlktradewright Thanks for the quick reply. I did try bash twsstartmacos.sh but i am getting the same output tab 1 of window id 200. Where can i start debugging this?

rlktradewright commented 1 month ago

Ok, let's try and suggest some things. But let me say right from the start that I don't have access to a mac, so there's nothing I can do directly.

Note that IBC does work fine on macs, There's no doubt about this. So what is causing the problem mut be something about the context or environment you're trying to run it in.

And the error mesage in your first post shows that IBC does indeed run when started from your Python code. IBC produces that message exactly when it says, ie Gateway has been started but has failed to display the login dialog within the relevant timeout (as specified in the LoginDialogDisplayTimeout=60 setting in config.ini). Presumably the reason it failed to do so is something to do with the Java exception report: I have absolutely no idea what that means or what is the cause., butiti's nothing to do with IBC.

So when you run from your original code using ib-insync, clearly something about the Java environment is incorrect: that's nothing to do with me, which is why I suggested you get help from the ib-insync community.

Next, you try running twsstartmacos.sh directly, and you get the message tab 1 of window id nnn. My understanding is that the terminal issues this message when something is started in a tab, But you say 'nothing happens (tws is not logged in)', but something must be happening in that tab. What should happen is that the subscript displaybannerandlaunch.sh runs within the terminal, and this displays some information and then invokes ibcstart.sh, which in turn runs IBC which then runs TWS

So if nothing seems to be happening, you'll need to do something like add echo statements to the scripts to see what they're doing.

I don't really know what more I can say.

Except to make the suggestion that you start again from scratch and follow the instructions in the User Guide for installing IBC, and try running that (so no use of ib-insync) just to convince yourself that it does work.