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
974 stars 174 forks source link

Fix suggestion for RECONNECTDATA and RECONNECTACCOUNT which never worked on macOS (probably) #242

Open ownrepo1s opened 7 months ago

ownrepo1s commented 7 months ago
#!/bin/bash

# Sends a command to the specified instance of IBC, for example to cause it
# to initiate a tidy closedown or restart of TWS or Gateway

# You must supply the command as the first argument when you call this
# script. It is case-insensitive.

# Please read the notes below and make any required changes, then save this
# file before running it.

# You may need to change this line. Set it to the name or IP address of the 
# computer that is running IBC. Note that you can use the local loopback 
# address (127.0.0.1) if IBC is running on the current machine.

server_address=127.0.0.1

# You may need to change this line. Make sure it's set to the value of the 
# CommandServerPort setting in config.ini:

command_server_port=7462

# You shouldn't need to change anything below this line.
# ==============================================================================

if [[ -z "$1" ]]; then
>&2 echo -e "Error: you must supply a valid IBC command as the first argument"
>&2 exit 1
fi

# send the required command to IBC 
(echo "$1"; sleep 1; echo "EXIT" ) | /usr/local/bin/telnet "$server_address" $command_server_port

I noticed on macOS the correct key combination for RECONNECTDATA is actually: Command + Option(Alt) + F instead of Ctrl + Alt + F

So that the above script doesn't work on macOS.

What i think needs to be done is to change the code from: https://github.com/IbcAlpha/IBC/blob/8b5f784d6c49af1fafc1df08e78462ad8b20fb34/src/ibcalpha/ibc/CommandDispatcher.java#L81 and https://github.com/IbcAlpha/IBC/blob/8b5f784d6c49af1fafc1df08e78462ad8b20fb34/src/ibcalpha/ibc/CommandDispatcher.java#L99

from int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK; to int modifiers = KeyEvent.VK_META | KeyEvent.ALT_DOWN_MASK;

As per https://github.com/GavriYashar/Matlab-Editor-Plugin/issues/150#issuecomment-498930862 for the key Command https://stackoverflow.com/a/7375073/1889814

Of course with the check of platform is macOS https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java

I'm not a Java developer, so the alternatives i'm considering until this is resolved are:

  1. Run TW in linux virtualized (docker or something else) and use the command to send a telnet command to the linux TW instance, maybe that one receives it correctly.
  2. Another option would be to implement a library in Objective-C or python to send that key combo to the TW window
  3. Another option would be to investigate the JAVA library and find the bug and fix it directly in the implementation and send a Pull Request to the library as well - this requires knowledge of ant
  4. Another option would be to RESTART the TW app each time, this is the simplest solution that i tested and works out of the box, just need to write handling code for waiting until fully reconnected. Got the RESTART from this undocumented API: https://github.com/IbcAlpha/IBC/blob/8b5f784d6c49af1fafc1df08e78462ad8b20fb34/src/ibcalpha/ibc/CommandDispatcher.java#L34-L57
  5. Might be an option to decompile the library and update it, but I'm not familiar on how to do this.

Cheers and thanks for this wonderful library!

ownrepo1s commented 6 months ago

Any comments here?

rlktradewright commented 6 months ago

Apologies for the delay in responding to this.

You seem to have a pretty good handle on what needs to be done, so it shouldn't be a big deal to fix it. But that doesn't make it any easier to find the time for it! I'll try to do so soon.

But I'm curious. What are the circumstances where you find it necessary to use it? Is this a frequent occurrence? Although I have used the manual equivalent of these commands on rare occasions, I've never found that they actually help solve any problems.