diff --git a/ledger.py b/ledger.py index f4e17ee..0b8315c 100644 --- a/ledger.py +++ b/ledger.py @@ -98,10 +98,17 @@ def _lot_by_origin(conn, market_id, origin_tx_id, origin_seq): def _sats_to_consume(tx): - """How many sats a transaction takes out of its account.""" + """How many sats a transaction takes out of its account. + + A trade consumes only when BTC leaves the account (a sale). A buy carries + its sats fee on the incoming leg, where it lowers the sats received, so it + must not consume anything. + """ if tx["type"] not in CONSUMING_TYPES: return 0 sats = tx["leg_out_sats"] or 0 + if sats <= 0: + return 0 if tx["type"] in FEE_ADDS_TO_CONSUMPTION: sats += tx["fee_sats"] or 0 return sats