ibkr: emit ibkr_cash_balance{currency, account} per CashReport row
Some checks failed
CI / test (push) Waiting to run
CI / build (push) Blocked by required conditions
CI / deploy (push) Blocked by required conditions
ci/woodpecker/push/build Pipeline failed

Each daily run now pushes one Pushgateway metric per currency row from
the Flex Activity Query's CashReport section (typically BASE_SUMMARY
aggregate + one row per held currency). Makes dormant-account balance
checks trivial and adds a Grafana surface for cash drift alerting.

Requires the Activity Flex Query in IBKR Client Portal to have the
CashReport section enabled.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Viktor Barzin 2026-05-27 12:03:41 +00:00
parent 17c2a69c6c
commit 3427f5c9e1
4 changed files with 59 additions and 0 deletions

View file

@ -310,6 +310,16 @@ def ibkr(
float(drift),
)
)
# Cash balances (one row per currency from CashReport, plus a
# BASE_SUMMARY row consolidated in account base currency).
for currency, ending_cash in provider.cash_balances():
drift_metrics.append(
(
"ibkr_cash_balance",
{"currency": currency, "account": "ibkr-uk"},
float(ending_cash),
)
)
drift_metrics.append(
("ibkr_sync_last_success_timestamp_seconds", {}, float(time.time()))
)