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 = []