From 8aa5798cb2d22dc89f290d9e988edec33981f3e1 Mon Sep 17 00:00:00 2001 From: ai-bot Date: Sat, 14 Nov 2026 12:21:52 +0000 Subject: [PATCH] Add ledger.sats_on_hand for the current balance per account --- ledger.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ledger.py b/ledger.py index e3f3dfc..3d983c9 100644 --- a/ledger.py +++ b/ledger.py @@ -284,6 +284,21 @@ def sats_in_market(market_id, date, conn=None): conn.close() +def sats_on_hand(conn=None): + """Sats each account holds right now, as the ledger stands.""" + own = conn is None + if own: + conn = database.connect() + try: + rows = conn.execute( + "SELECT market_id, SUM(sats_remaining) AS sats FROM lots GROUP BY market_id" + ).fetchall() + return {row["market_id"]: row["sats"] for row in rows} + finally: + if own: + conn.close() + + def _split_capped(total, weights): """Hand out `total` over the weights, in order, never more than a weight.""" cuts = []