From f54ef39c591b8b3434160c12f10dfdeb7acc49b9 Mon Sep 17 00:00:00 2001 From: czichy Date: Sat, 30 Nov 2024 18:23:37 +0100 Subject: [PATCH] ibkr-flex --- flake.nix | 6 +- hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix | 66 ++++++++++++++++----- hosts/HL-1-MRZ-HOST-01/guests/samba.nix | 4 +- parts/pkgs/default.nix | 2 +- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index a4c79c2..3481024 100755 --- a/flake.nix +++ b/flake.nix @@ -166,9 +166,9 @@ url = "github:edolstra/flake-compat"; flake = false; }; - ibkr-rust = { - url = "github:czichy/ibkr-rust"; - }; + # ibkr-rust = { + # url = "github:czichy/ibkr-rust"; + # }; }; # NOTE Here you can add additional binary cache substituers that you trust. diff --git a/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix b/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix index c4e6d95..dd23be3 100755 --- a/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix +++ b/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix @@ -2,8 +2,6 @@ pkgs, secretsPath, hostName, - lib, - inputs, ... }: # let @@ -35,17 +33,10 @@ owner = "root"; }; }; - # |----------------------------------------------------------------------| # - # networking.firewall = { - # allowedTCPPorts = [ - # 8384 # Port for Syncthing Web UI. - # 22000 # TCP based sync protocol traffic - # ]; - # allowedUDPPorts = [ - # 22000 # QUIC based sync protocol traffic - # 21027 # for discovery broadcasts on IPv4 and multicasts on IPv6 - # ]; - # }; + age.secrets.ibkr-flex-hc-ping = { + file = secretsPath + "/hosts/HL-4-PAZ-PROXY-01/healthchecks-ping.age"; + mode = "440"; + }; # ------------------------------ # | SYSTEM PACKAGES | # ------------------------------ @@ -53,8 +44,55 @@ pkg-config openssh # inputs.self.packages.${system}.ibkr-rust - inputs.ibkr-rust.packages.${pkgs.system}.flex + ( + let + token = "$(cat ${config.age.secrets.ibkrFlexToken.path})"; + query = "639991"; + + pingKey = "$(cat ${config.age.secrets.ibkr-flex-hc-ping.path})"; + slug = "https://health.czichy.com/ping/${pingKey}"; + in + writeShellScriptBin "ibkr-flex-download" + '' + #!/usr/bin/env bash + set -euo pipefail + + echo "Downloading Flex Report" + nix run github:czichy/ibkr-rust/flex -q ${query} -t "echo '${token}'" --dump-path /TWS_Flex_Reports \ + --extra-experimental-features "nix-command flakes" + + for file in /TWS_Flex_Reports/*.xml ; do + fileDate=$(awk -F[_.] '{print $3 }' <<<"$(basename "$file")"); + destination="$(awk -F[-] '{print $1 }' <<<"$fileDate")/$(awk -F[-] '{print $1"-"$2 }' <<<"$fileDate")/" + echo "$destination" + echo mv "$file" "/TWS_Flex_Reports/$destination"; + done + ${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused ${slug}/ibkr-flex-download + + '' + ) + # inputs.ibkr-rust.packages.${pkgs.system}.flex ]; + # |----------------------------------------------------------------------| # + systemd.timers."ibkr-flex-download" = { + wantedBy = ["timers.target"]; + timerConfig = { + Perisistent = true; + OnCalendar = "Mon..Fri 23:30"; + Unit = "ibkr-flex-download.service"; + }; + }; + + systemd.services."ibkr-flex-download" = { + script = '' + set -eu + ${pkgs}/ibkr.flex-download + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; # |----------------------------------------------------------------------| # environment.persistence."/persist".files = [ diff --git a/hosts/HL-1-MRZ-HOST-01/guests/samba.nix b/hosts/HL-1-MRZ-HOST-01/guests/samba.nix index 297aa2d..52228b4 100755 --- a/hosts/HL-1-MRZ-HOST-01/guests/samba.nix +++ b/hosts/HL-1-MRZ-HOST-01/guests/samba.nix @@ -451,13 +451,13 @@ in { -H 'Title: Backup (${site}) on ${host} failed!' \ -H 'Tags: backup,restic,${host},${site}' \ -d "Restic (${site}) backup error on ${host}!" '${ntfy_url}' - ${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused "${slug}/backup-${site}/fail" + ${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused ${slug}/backup-${site}/fail else ${pkgs.curl}/bin/curl -u alert:${ntfy_pass} \ -H 'Title: Backup (${site}) on ${host} successful!' \ -H 'Tags: backup,restic,${host},${site}' \ -d "Restic (${site}) backup success on ${host}!" '${ntfy_url}' - ${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused "${slug}/backup-${site}" + ${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused ${slug}/backup-${site} fi ''; in { diff --git a/parts/pkgs/default.nix b/parts/pkgs/default.nix index 4b9cf23..9a0b14c 100755 --- a/parts/pkgs/default.nix +++ b/parts/pkgs/default.nix @@ -22,7 +22,7 @@ my_cookies = pkgs.callPackage ./my_cookies.nix {}; ib-tws-native = pkgs.callPackage ./ibtws {}; ib-tws-native-latest = pkgs.callPackage ./ibtws_latest {}; - ibkr-rust = pkgs.callPackage ./ibkr-rust.nix {}; + # ibkr-rust = pkgs.callPackage ./ibkr-rust.nix {}; polonium-nightly = pkgs.libsForQt5.callPackage ./polonium-nightly.nix {inherit lib;}; }; };