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.07k stars 185 forks source link

crontab not working in Mac OS #87

Closed saikee closed 3 years ago

saikee commented 4 years ago

First of all, thank you for providing such good software.

I'm new. Installed for Mac OS, 10.15.

(1) Found out the start up script doesn't work for Mac, and found the fix from https://github.com/IbcAlpha/IBC/blob/master/resources/scripts/ibcstart.sh Wish the maintainer can embed the bug fix into next release.

(2) Found out the ./twsstartmacos.sh doesn't work, must be ./twsstartmacos.sh -inline

(3) After tested manual startup with the script, OK; stop also OK. Using absolute path, setup the "twsstartmacos.sh -inline" in crontab, it failed, following is the log file:

================================================================================

Starting IBC version 3.8.2 on 2020-04-22 at 10:13:00

Operating system: Darwin iMac2.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

Arguments:

TWS version = 978 Entry point = ibcalpha.ibc.IbcTws --tws-path = /Volumes/HDA/Users/skwong/Applications --tws-settings-path = /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/tws_settings --ibc-path = /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d --ibc-ini = /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/config.ini --mode = --java-path = --user = --pw =

================================= Generating the classpath Classpath=/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/jts4launch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/locales.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-api-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-core-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/total-2018.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-install4j-1.9.jar:/Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/IBC.jar

Generating the JAVA VM options Java VM Options=-Xmx768m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=20 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70

Determining the location of java executable Location of java executable=/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/bin

Starting TWS with this command: "/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/bin/java" -cp "/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/jts4launch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/locales.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-api-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-core-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/total-2018.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-install4j-1.9.jar:/Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/IBC.jar" -Xmx768m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=20 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70 ibcalpha.ibc.IbcTws "/Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/config.ini"

2020-04-22 10:13:00:969 IBC: Properties file /Volumes/HDA/Users/skwong/IBC/config.ini not found 2020-04-22 10:13:00:987 IBC: Version: 3.8.2 System Properties

java.runtime.name = Java(TM) SE Runtime Environment sun.boot.library.path = /Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib java.vm.version = 25.152-b16 gopherProxySet = false java.vm.vendor = Oracle Corporation java.vendor.url = http://java.oracle.com/ path.separator = : java.vm.name = Java HotSpot(TM) 64-Bit Server VM file.encoding.pkg = sun.io user.country = HK sun.java.launcher = SUN_STANDARD sun.os.patch.level = unknown java.vm.specification.name = Java Virtual Machine Specification user.dir = /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/tws_settings java.runtime.version = 1.8.0_152-b16 java.awt.graphicsenv = sun.awt.CGraphicsEnvironment java.endorsed.dirs = /Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/endorsed os.arch = x86_64 java.io.tmpdir = /var/folders/ll/rh68dbvj4yjf6nqxz9v22wdr0000gn/T/ line.separator =

java.vm.specification.vendor = Oracle Corporation os.name = Mac OS X sun.jnu.encoding = UTF-8 java.library.path = /Volumes/HDA/Users/skwong/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. java.specification.name = Java Platform API Specification java.class.version = 52.0 sun.management.compiler = HotSpot 64-Bit Tiered Compilers os.version = 10.15.3 http.nonProxyHosts = local|.local|169.254/16|.169.254/16 user.home = /Volumes/HDA/Users/skwong user.timezone = Pacific/Auckland java.awt.printerjob = sun.lwawt.macosx.CPrinterJob file.encoding = UTF-8 java.specification.version = 1.8 java.class.path = /Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/jts4launch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/locales.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-api-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/log4j-core-2.5.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/total-2018.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-978.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/jars/twslaunch-install4j-1.9.jar:/Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/IBC.jar user.name = skwong java.vm.specification.version = 1.8 sun.java.command = ibcalpha.ibc.IbcTws /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/config.ini java.home = /Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre sun.arch.data.model = 64 user.language = en java.specification.vendor = Oracle Corporation awt.toolkit = sun.lwawt.macosx.LWCToolkit java.vm.info = mixed mode java.version = 1.8.0_152 java.ext.dirs = /Volumes/HDA/Users/skwong/Library/Java/Extensions:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java sun.boot.class.path = /Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/resources.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/rt.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/sunrsasign.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/jsse.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/jce.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/charsets.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/lib/jfr.jar:/Volumes/HDA/Users/skwong/Applications/Trader Workstation 978/.install4j/jre.bundle/Contents/Home/jre/classes java.awt.headless = true java.vendor = Oracle Corporation file.separator = / java.vendor.url.bug = http://bugreport.sun.com/bugreport/ sun.io.unicode.encoding = UnicodeBig sun.cpu.endian = little socksNonProxyHosts = local|.local|169.254/16|.169.254/16 ftp.nonProxyHosts = local|.local|169.254/16|.169.254/16 sun.cpu.isalist =

2020-04-22 10:13:00:989 IBC: Using default settings provider: ini file is /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/config.ini 2020-04-22 10:13:00:989 IBC: Using default login manager: getting username and password from args but not found. Will get from settings 2020-04-22 10:13:00:989 IBC: Using default main window manager: constructor parameter isGateway=false 2020-04-22 10:13:00:989 IBC: Using default trading mode manager: constructor parameter args but trading mode not present - will be taken from settings 2020-04-22 10:13:00:991 IBC: Using default config dialog manager 2020-04-22 10:13:00:996 IBC: CommandServer is starting with port 7464 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2020-04-22 10:13:01:197 IBC: CommandServer failed to create socket: Address already in use (Bind failed) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2020-04-22 10:13:01:197 IBC: CommandServer cannot process commands 2020-04-22 10:13:01:197 IBC: CommandServer is shutdown 2020-04-22 10:13:01:228 IBC: TWS Settings directory is: /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/tws_settings 2020-04-22 10:13:01:256 IBC: Ensuring /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/tws_settings/jts.ini contains required minimal lines 2020-04-22 10:13:01:256 IBC: Found setting: [Logon]/s3store=true 2020-04-22 10:13:01:256 IBC: Found setting: [Logon]/Locale=en 2020-04-22 10:13:01:256 IBC: Found setting: [Logon]/displayedproxymsg=1 2020-04-22 10:13:01:256 IBC: Found setting: [IBGateway]/ApiOnly=true 2020-04-22 10:13:01:256 IBC: Confirmed /Volumes/HDA/Users/skwong/Applications/IBCMacos-3.8.2d/tws_settings/jts.ini contains required minimal lines RenderJob.run: internal exception java.lang.ArrayIndexOutOfBoundsException: 0 at java.util.Arrays$ArrayList.get(Arrays.java:3841) at java.util.Collections$UnmodifiableList.get(Collections.java:1309) at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61) at com.sun.prism.sw.SWPipeline.getDefaultResourceFactory(SWPipeline.java:82) at com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipeline.java:120) at com.sun.javafx.tk.quantum.QuantumRenderer.lambda$createResourceFactory$413(QuantumRenderer.java:161) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125) at java.lang.Thread.run(Thread.java:748)

Where, the CommandServer fault is not an issue. The issue seems come from the RenderJob.run: internal exception java.lang.ArrayIndexOutOfBoundsException: 0

at the end.

Anyone had similar experience and know the tricks ?

rlktradewright commented 4 years ago

[In future, it's preferable to attach logfiles rather than quote them inline.]

(1) I apologise that I haven't got round to doing a release with the macOS script fix in it yet. I'll try to do it soon.

(2) More information please. I don't have access to a Mac, so I need hard evidence of what's happening.

(3) There was a thread in the IBC User Group a few years back, where one of the members did a pretty thorough job of getting IBC working automatically. It seems that crontab is not the way to go on macOS, rather use Launch Agents and launchd. Below is a link to the first message in that thread that discusses use of launchd, and there's a whole lot more after that. I hope they will help you. Note that this thread is from before IBC was forked from IBController, but the issues are presumably the same.

https://groups.io/g/ibcalpha/message/271

saikee commented 4 years ago

Apologize for asking question with lengthy text instead of upload log file.

(1) Thank you !

(2) I made the file as ~/Applications/IBCMacos-3.8.2a/twsstartmacos.sh If I execute it from command line as ~/Applications/IBCMacos-3.8.2a/twsstartmacos.sh

 It will fire up another terminal window to run "/opt/ibc/twsstartmacos.sh -inline"

 ended up with below output
 zsh: no such file or directory: /opt/ibc/twsstartmacos.sh

 That is true because I did not install it under /opt/ibc

 Actually, I want to run 4 instances of TWS, therefore, I made
 ~/Applications/IBCMacos-3.8.2a/twsstartmacos.sh
 ~/Applications/IBCMacos-3.8.2b/twsstartmacos.sh
 ~/Applications/IBCMacos-3.8.2c/twsstartmacos.sh
 ~/Applications/IBCMacos-3.8.2d/twsstartmacos.sh

 If I execute it from command line as
 ~/Applications/IBCMacos-3.8.2a/twsstartmacos.sh -inline

 everything just fine.

(3) Will take a look and configure it. Many thanks !