From 36a6d13e20de2cbb3f9b09a9c4ec38f3c4514279 Mon Sep 17 00:00:00 2001 From: ai-bot Date: Sat, 14 Nov 2026 16:10:58 +0000 Subject: [PATCH] Read the NOK paid for a buy from leg_out_ore, as the schema requires --- ledger.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ledger.py b/ledger.py index 3d983c9..f4e17ee 100644 --- a/ledger.py +++ b/ledger.py @@ -184,7 +184,13 @@ def create_lots_for(tx, conn=None): fee_ore = tx["fee_ore"] or 0 if tx_type == "trade" and tx["leg_in_sats"]: sats = tx["leg_in_sats"] - fee_sats - cost_ore = (tx["leg_in_ore"] or 0) + fee_ore + # The NOK that left the account. docs/spec.md section 5.1 says + # leg_in_ore, but a leg carries one currency only (the CHECK of + # section 4), so a buy keeps it on leg_out_ore. + nok_paid = tx["leg_out_ore"] + if nok_paid is None: + nok_paid = tx["leg_in_ore"] + cost_ore = (nok_paid or 0) + fee_ore elif tx_type == "income" and tx["leg_in_sats"]: sats = tx["leg_in_sats"] - fee_sats cost_ore = max((tx["value_ore"] or 0) - fee_ore, 0)