Add ledger.sats_on_hand for the current balance per account

This commit is contained in:
ai-bot committed 2026-11-14 12:21:52 +00:00
1 parent 165c600529
commit 8aa5798cb2
1 file changed
+15
+15
View File
@@ -284,6 +284,21 @@ def sats_in_market(market_id, date, conn=None):
conn.close() 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): def _split_capped(total, weights):
"""Hand out `total` over the weights, in order, never more than a weight.""" """Hand out `total` over the weights, in order, never more than a weight."""
cuts = [] cuts = []