Skip to content

Commit

Permalink
ibkr-flex
Browse files Browse the repository at this point in the history
  • Loading branch information
Czichy committed Nov 30, 2024
1 parent 68f5c5a commit f54ef39
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
66 changes: 52 additions & 14 deletions hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
pkgs,
secretsPath,
hostName,
lib,
inputs,
...
}:
# let
Expand Down Expand Up @@ -35,26 +33,66 @@
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 |
# ------------------------------
environment.systemPackages = with pkgs; [
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 = [
Expand Down
4 changes: 2 additions & 2 deletions hosts/HL-1-MRZ-HOST-01/guests/samba.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion parts/pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;};
};
};
Expand Down

0 comments on commit f54ef39

Please sign in to comment.