summaryrefslogtreecommitdiff
path: root/trivionomicon/pkgs/ibkr-tws-api/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'trivionomicon/pkgs/ibkr-tws-api/default.nix')
-rw-r--r--trivionomicon/pkgs/ibkr-tws-api/default.nix150
1 files changed, 150 insertions, 0 deletions
diff --git a/trivionomicon/pkgs/ibkr-tws-api/default.nix b/trivionomicon/pkgs/ibkr-tws-api/default.nix
new file mode 100644
index 0000000..879c3d2
--- /dev/null
+++ b/trivionomicon/pkgs/ibkr-tws-api/default.nix
@@ -0,0 +1,150 @@
+{
+ cmake,
+ lib,
+ fetchzip,
+ intel-decimalfp,
+ pkg-config,
+ protobuf,
+ python3Packages,
+ stdenv,
+}: let
+ version = "1044.01";
+
+ src-with-protobuf = stdenv.mkDerivation {
+ pname = "ibkr-tws-api-src";
+ inherit version;
+
+ src = fetchzip {
+ url = "https://interactivebrokers.github.io/downloads/twsapi_macunix.${version}.zip";
+ hash = "sha256-9bi2Mgp3qDHz8R2lrXEOYIeBffRKOWqKxDYecybR8Eo=";
+ stripRoot = false;
+ };
+
+ nativeBuildInputs = [
+ protobuf
+ ];
+
+ configurePhase = ''
+ runHook preConfigure
+
+ rm IBJts/source/{cppclient/client/protobufUnix/*,pythonclient/ibapi/protobuf/*}
+ protoc \
+ -IIBJts/source/proto \
+ --cpp_out=IBJts/source/cppclient/client/protobufUnix \
+ --python_out=IBJts/source/pythonclient/ibapi/protobuf \
+ IBJts/source/proto/*.proto
+
+ sed -i '/^import / { s/\(\<[A-Za-z0-9_]*[A-Za-z0-9]_pb2\)/ibapi.protobuf.\1/g }' IBJts/source/pythonclient/ibapi/protobuf/*.py
+ touch IBJts/source/pythonclient/ibapi/protobuf/__init__.py
+
+ runHook postConfigure
+ '';
+
+ installPhase = ''
+ runHook preInstall
+
+ cp -r . $out
+
+ runHook postInstall
+ '';
+ };
+
+ native-lib = stdenv.mkDerivation {
+ pname = "ibkr-tws-api-native";
+ inherit version;
+
+ src = src-with-protobuf;
+ sourceRoot = "ibkr-tws-api-src-${version}/IBJts/source/cppclient/client";
+
+ buildInputs = [
+ intel-decimalfp
+ protobuf
+ ];
+
+ postPatch = ''
+ sed -i 's/-std=c++11/-std=c++17/' makefile
+ '';
+
+ makeFlags = [
+ "LIB_DIR=${intel-decimalfp}/lib"
+ "LIB_NAME=libbid.a"
+ ];
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out/lib
+ cp -v lib*.so $out/lib
+
+ runHook postInstall
+ '';
+ };
+
+ test-client = stdenv.mkDerivation {
+ pname = "ibkr-tws-api-test-client";
+ inherit version;
+
+ src = src-with-protobuf;
+ sourceRoot = "ibkr-tws-api-src-${version}/IBJts/samples/Cpp/TestCppClient";
+
+ nativeBuildInputs = [
+ pkg-config
+ ];
+
+ buildInputs = [
+ intel-decimalfp
+ native-lib
+ protobuf
+ ];
+
+ postPatch = ''
+ sed -i "s/-std=c++11/-std=c++17/; s@-lprotobuf@$(pkg-config --libs protobuf)@" makefile
+ '';
+
+ makeFlags = [
+ "TestCppClientDynamic"
+ "LIB_DIR=${intel-decimalfp}/lib"
+ "LIB_NAME_SO=libbid.a"
+ "SOURCE_DIR=${native-lib}/lib"
+ ];
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out/bin
+ install -m755 TestCppClientDynamic $out/bin/TestCppClient
+
+ runHook postInstall
+ '';
+
+ postFixup = ''
+ patchelf --add-rpath ${native-lib}/lib $out/bin/TestCppClient
+ '';
+
+ meta = {
+ mainProgram = "TestCppClient";
+ };
+ };
+
+ py-client = {
+ buildPythonPackage,
+ protobuf,
+ }:
+ buildPythonPackage {
+ pname = "ibapi-python";
+ inherit version;
+
+ src = src-with-protobuf;
+ sourceRoot = "ibkr-tws-api-src-${version}/IBJts/source/pythonclient";
+
+ format = "setuptools";
+
+ propagatedBuildInputs = [
+ protobuf
+ ];
+ };
+in {
+ inherit test-client;
+ native = native-lib;
+ ibapi-python = python3Packages.callPackage py-client {};
+}