summary refs log tree commit diff
path: root/pkgs/applications/office/ib
diff options
context:
space:
mode:
authorRok Garbas <rok@garbas.si>2016-01-20 03:54:49 +0100
committerRok Garbas <rok@garbas.si>2016-01-20 04:42:30 +0100
commit95db340fd0b0d2710285846cc682156f9aa6c8ab (patch)
tree0ade7e804baa5367e0fec5d16707827a5fcd6b8d /pkgs/applications/office/ib
parent4f40a4542643d46f6e0d58fe6cd9f329ccee443d (diff)
downloadnixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar.gz
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar.bz2
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar.lz
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar.xz
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.tar.zst
nixlib-95db340fd0b0d2710285846cc682156f9aa6c8ab.zip
ib-tws, ib-controller: init at 9542 and 2.14.0, fixes #8142
Diffstat (limited to 'pkgs/applications/office/ib')
-rw-r--r--pkgs/applications/office/ib/controller/default.nix162
-rw-r--r--pkgs/applications/office/ib/tws/default.nix96
2 files changed, 258 insertions, 0 deletions
diff --git a/pkgs/applications/office/ib/controller/default.nix b/pkgs/applications/office/ib/controller/default.nix
new file mode 100644
index 000000000000..b39617e02db2
--- /dev/null
+++ b/pkgs/applications/office/ib/controller/default.nix
@@ -0,0 +1,162 @@
+{ stdenv, fetchurl, unzip, jdk, ib-tws, xpra }:
+
+stdenv.mkDerivation rec {
+  version = "2.14.0";
+  name = "ib-controller-${version}";
+
+  src = fetchurl {
+    url = "https://github.com/ib-controller/ib-controller/archive/${version}.tar.gz";
+    sha256 = "17a8bcgg9z3b4y38k035hm2lgvhmf8srlz59c7n2q3fdw2i95i68";
+  };
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  buildInputs = [ unzip jdk ib-tws ];
+
+  installPhase = ''
+    mkdir -p $out $out/bin $out/etc/ib/controller $out/share/IBController
+    cp resources/*.jar $out/share/IBController/.
+    cp resources/*.ini $out/etc/ib/controller/.
+    classpath=""
+    for jar in ${ib-tws}/share/IBJts/*.jar; do
+      classpath="$classpath:$jar"
+    done
+    for jar in $out/share/IBController/*.jar; do
+      classpath="$classpath:$jar"
+    done
+    # strings to use below; separated to avoid nix specific substitutions
+    javaOptions={JAVA_OPTIONS:--Xmx1024M}
+    ibProfileDir={IB_PROFILE_DIR:-~/IB/}
+    cat<<EOF > $out/bin/ib-tws-c
+    #!$SHELL
+    if [[ \$1 == /* ]] || [[ \$1 == ./* ]]; then
+      IB_USER_PROFILE=\`realpath \$1\`
+      IB_USER_PROFILE_TITLE=\`basename \$1\`
+    else
+      if [[ x\$1 != "x" ]] && [[ \$1 != -* ]]; then
+        IB_USER_PROFILE=\`realpath \$$ibProfileDir\$1\`
+        IB_USER_PROFILE_TITLE=\$1
+      else
+        echo "ERROR: \"\$1\" is not a valid name of a profile."
+        exit 1
+      fi
+    fi
+    shift
+    if [ ! -e \$IB_USER_PROFILE ]; then mkdir -p \$IB_USER_PROFILE; fi
+    if [ ! -d \$IB_USER_PROFILE ]; then echo "ERROR: \$IB_USER_PROFILE must be a directory!" && echo 1; fi
+    if [ ! -e \$IB_USER_PROFILE/jts.ini ]; then cp ${ib-tws}/etc/ib/tws/jts.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/jts.ini; fi
+    if [ ! -e \$IB_USER_PROFILE/IBController.ini ]; then cp $out/etc/ib/controller/IBController.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/IBController.ini; fi
+    if [[ \$1 == "-q" ]]; then
+      if [ -f \$IB_USER_PROFILE/xpra/run ]; then
+        ${xpra}/bin/xpra stop \`cat \$IB_USER_PROFILE/xpra/run\` --socket-dir=\$IB_USER_PROFILE/xpra/ &> /dev/null
+      fi
+      exit 0
+    fi
+    if [[ \$1 == "-d" ]] && [ ! -f \$IB_USER_PROFILE/xpra/run ]; then
+      ( sleep infinity ) &
+      WAIT_DUMMY_PID=\$!
+      ( trap "" INT;
+        DISPLAYNUM=100
+        while [ -f /tmp/.X\$DISPLAYNUM-lock ]; do DISPLAYNUM=\$((\$DISPLAYNUM + 1)); done
+        mkdir -p \$IB_USER_PROFILE/xpra
+        cd \$IB_USER_PROFILE
+        nohup ${xpra}/bin/xpra start :\$DISPLAYNUM \
+          --socket-dir=\$IB_USER_PROFILE/xpra/ \
+          --start-child="echo -n :\$DISPLAYNUM > \$IB_USER_PROFILE/xpra/run \
+                         && kill \$WAIT_DUMMY_PID &> /dev/null \
+                         && ${jdk}/bin/java -cp $classpath \$$javaOptions ibcontroller.IBController \$IB_USER_PROFILE/IBController.ini" \
+          --exit-with-children \
+          --no-pulseaudio \
+          --no-mdns \
+          --no-notification \
+          --no-daemon \
+          &> \$IB_USER_PROFILE/xpra/server.log
+        rm -f \$IB_USER_PROFILE/xpra/run
+        rm -f /tmp/.X\$DISPLAYNUM-lock
+      ) &
+      wait \$WAIT_DUMMY_PID
+      exit 0
+    fi
+    if [ -f \$IB_USER_PROFILE/xpra/run ]; then
+      ${xpra}/bin/xpra attach \`cat \$IB_USER_PROFILE/xpra/run\` --socket-dir=\$IB_USER_PROFILE/xpra/ \
+      --windows \
+      --no-speaker \
+      --no-microphone \
+      --no-tray \
+      --title="\$IB_USER_PROFILE_TITLE: @title@" \
+      &> \$IB_USER_PROFILE/xpra/client.log
+    fi
+    EOF
+    chmod u+x $out/bin/ib-tws-c
+    cat<<EOF > $out/bin/ib-gw-c
+    #!$SHELL
+    if [[ \$1 == /* ]] || [[ \$1 == ./* ]]; then
+      IB_USER_PROFILE=\`realpath \$1\`
+      IB_USER_PROFILE_TITLE=\`basename \$1\`
+    else
+      if [[ x\$1 != "x" ]] && [[ \$1 != -* ]]; then
+        IB_USER_PROFILE=\`realpath \$$ibProfileDir\$1\`
+        IB_USER_PROFILE_TITLE=\$1
+      else
+        echo "ERROR: \"\$1\" is not a valid name of a profile."
+        exit 1
+      fi
+    fi
+    shift
+    if [ ! -e \$IB_USER_PROFILE ]; then mkdir -p \$IB_USER_PROFILE; fi
+    if [ ! -d \$IB_USER_PROFILE ]; then echo "ERROR: \$IB_USER_PROFILE must be a directory!" && echo 1; fi
+    if [ ! -e \$IB_USER_PROFILE/jts.ini ]; then cp ${ib-tws}/etc/ib/tws/jts.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/jts.ini; fi
+    if [ ! -e \$IB_USER_PROFILE/IBController.ini ]; then cp $out/etc/ib/controller/IBController.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/IBController.ini; fi
+    if [[ \$1 == "-q" ]]; then
+      if [ -f \$IB_USER_PROFILE/xpra/run ]; then
+        ${xpra}/bin/xpra stop \`cat \$IB_USER_PROFILE/xpra/run\` --socket-dir=\$IB_USER_PROFILE/xpra/ &> /dev/null
+      fi
+      exit 0
+    fi
+    if [[ \$1 == "-d" ]] && [ ! -f \$IB_USER_PROFILE/xpra/run ]; then
+      ( sleep infinity ) &
+      WAIT_DUMMY_PID=\$!
+      ( trap "" INT;
+        DISPLAYNUM=100
+        while [ -f /tmp/.X\$DISPLAYNUM-lock ]; do DISPLAYNUM=\$((\$DISPLAYNUM + 1)); done
+        mkdir -p \$IB_USER_PROFILE/xpra
+        cd \$IB_USER_PROFILE
+        nohup ${xpra}/bin/xpra start :\$DISPLAYNUM \
+          --socket-dir=\$IB_USER_PROFILE/xpra/ \
+          --start-child="echo -n :\$DISPLAYNUM > \$IB_USER_PROFILE/xpra/run \
+                         && kill \$WAIT_DUMMY_PID &> /dev/null \
+                         && ${jdk}/bin/java -cp $classpath \$$javaOptions ibcontroller.IBGatewayController \$IB_USER_PROFILE/IBController.ini" \
+          --exit-with-children \
+          --no-pulseaudio \
+          --no-mdns \
+          --no-notification \
+          --no-daemon \
+          &> \$IB_USER_PROFILE/xpra/server.log
+        rm -f \$IB_USER_PROFILE/xpra/run
+        rm -f /tmp/.X\$DISPLAYNUM-lock
+      ) &
+      wait \$WAIT_DUMMY_PID
+      exit 0
+    fi
+    if [ -f \$IB_USER_PROFILE/xpra/run ]; then
+      ${xpra}/bin/xpra attach \`cat \$IB_USER_PROFILE/xpra/run\` --socket-dir=\$IB_USER_PROFILE/xpra/ \
+      --windows \
+      --no-speaker \
+      --no-microphone \
+      --no-tray \
+      --title="\$IB_USER_PROFILE_TITLE: @title@" \
+      &> \$IB_USER_PROFILE/xpra/client.log
+    fi
+    EOF
+    chmod u+x $out/bin/ib-gw-c
+    '';
+
+
+  meta = with stdenv.lib; {
+    description = "Automation Controller for the Trader Work Station of Interactive Brokers";
+    homepage = https://github.com/ib-controller/ib-controller;
+    license = licenses.gpl3;
+    maintainers = [ maintainers.tstrobel ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/pkgs/applications/office/ib/tws/default.nix b/pkgs/applications/office/ib/tws/default.nix
new file mode 100644
index 000000000000..b8844391c7d9
--- /dev/null
+++ b/pkgs/applications/office/ib/tws/default.nix
@@ -0,0 +1,96 @@
+{ stdenv, requireFile, jdk }:
+
+stdenv.mkDerivation rec {
+  version = "9542";
+  name = "ib-tws-${version}";
+
+  src = requireFile rec {
+    name = "ibtws_${version}.jar";
+    message = ''
+      This nix expression requires that ${name} is already part of the store.
+      Download the TWS from
+      https://download2.interactivebrokers.com/download/unixmacosx_latest.jar,
+      rename the file to ${name}, and add it to the nix store with
+      "nix-prefetch-url file://${name}".
+    '';
+    sha256 = "1a2jiwwnr5g3xfba1a89c257bdbnq4zglri8hz021vk7f6s4rlrf";
+  };
+
+  phases = [ "unpackPhase" "buildPhase" "installPhase" ];
+
+  buildInputs = [ jdk ];
+
+  buildPhase = ''
+    jar -xf IBJts/jts.jar
+    cp trader/common/images/ibapp_icon.gif ibtws_icon.gif
+    '';
+
+  unpackPhase = ''
+    jar xf ${src}
+    '';
+
+  installPhase = ''
+    mkdir -p $out $out/bin $out/etc/ib/tws $out/share/IBJts $out/share/icons
+    cp IBJts/*.jar $out/share/IBJts/.
+    cp IBJts/*.ini $out/etc/ib/tws/.
+    cp ibtws_icon.gif $out/share/icons/.
+    classpath=""
+    for jar in $out/share/IBJts/*.jar; do
+      classpath="$classpath:$jar"
+    done
+    # strings to use below; separated to avoid nix specific substitutions
+    javaOptions={JAVA_OPTIONS:-'-Xmx1024M -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.xrender=True -Dsun.java2d.opengl=False'}
+    # OTHER JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java
+    ibProfileDir={IB_PROFILE_DIR:-~/IB/}
+    cat<<EOF > $out/bin/ib-tws
+    #!$SHELL
+    if [[ \$1 == /* ]] || [[ \$1 == ./* ]]; then
+      IB_USER_PROFILE=\`realpath \$1\`
+      IB_USER_PROFILE_TITLE=\`basename \$1\`
+    else
+      if [[ x\$1 != "x" ]] && [[ \$1 != -* ]]; then
+        IB_USER_PROFILE=\`realpath \$$ibProfileDir\$1\`
+        IB_USER_PROFILE_TITLE=\$1
+      else
+        echo "ERROR: \"\$1\" is not a valid name of a profile."
+        exit 1
+      fi
+    fi
+    shift
+    if [ ! -e \$IB_USER_PROFILE ]; then mkdir -p \$IB_USER_PROFILE; fi
+    if [ ! -d \$IB_USER_PROFILE ]; then echo "ERROR: \$IB_USER_PROFILE must be a directory!" && echo 1; fi
+    if [ ! -e \$IB_USER_PROFILE/jts.ini ]; then cp $out/etc/ib/tws/jts.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/jts.ini; fi
+    ${jdk}/bin/java -cp $classpath \$$javaOptions jclient.LoginFrame \$IB_USER_PROFILE
+    EOF
+    chmod u+x $out/bin/ib-tws
+    cat<<EOF > $out/bin/ib-gw
+    #!$SHELL
+    if [[ \$1 == /* ]] || [[ \$1 == ./* ]]; then
+      IB_USER_PROFILE=\`realpath \$1\`
+      IB_USER_PROFILE_TITLE=\`basename \$1\`
+    else
+      if [[ x\$1 != "x" ]] && [[ \$1 != -* ]]; then
+        IB_USER_PROFILE=\`realpath \$$ibProfileDir\$1\`
+        IB_USER_PROFILE_TITLE=\$1
+      else
+        echo "ERROR: \"\$1\" is not a valid name of a profile."
+        exit 1
+      fi
+    fi
+    shift
+    if [ ! -e \$IB_USER_PROFILE ]; then mkdir -p \$IB_USER_PROFILE; fi
+    if [ ! -d \$IB_USER_PROFILE ]; then echo "ERROR: \$IB_USER_PROFILE must be a directory!" && echo 1; fi
+    if [ ! -e \$IB_USER_PROFILE/jts.ini ]; then cp $out/etc/ib/tws/jts.ini \$IB_USER_PROFILE/. && chmod +w \$IB_USER_PROFILE/jts.ini; fi
+    ${jdk}/bin/java -cp $classpath -Dsun.java2d.noddraw=true \$$javaOptions ibgateway.GWClient \$IB_USER_PROFILE
+    EOF
+    chmod u+x $out/bin/ib-gw
+    '';
+
+  meta = with stdenv.lib; {
+    description = "Trader Work Station of Interactive Brokers";
+    homepage = https://www.interactivebrokers.com;
+    license = licenses.unfree;
+    maintainers = [ maintainers.tstrobel ];
+    platforms = platforms.linux;
+  };
+}