diff --git a/tax.py b/tax.py index 3a45f47..cf81de2 100644 --- a/tax.py +++ b/tax.py @@ -55,9 +55,22 @@ def btc_price_ore(tx): """The bitcoin price of docs/spec.md section 7.3, in ore per whole BTC. The kroner amount is the leg that carries it, or `value_ore` where no leg - does; the fee is left out. Returns None when the type has no price. + does; the fee is left out. A transfer has no kroner leg to read, so it uses + the lots it moved: the consumed lots for the outgoing side, the mirrored + lots for the incoming side, which gives both sides the same price. Returns + None when the type has no price. """ tx_type = tx["type"] + if tx_type in ("transfer_out", "transfer_in"): + if tx_type == "transfer_out": + nok_ore = tx["cost_ore"] + sats = tx["consumed_sats"] + else: + nok_ore = tx["lot_cost_ore"] + sats = tx["lot_sats"] + if not nok_ore or not sats: + return None + return _round_div(nok_ore * SATS_PER_BTC, sats) if tx_type not in PRICE_TYPES: return None if tx_type in ("income", "gift_received"):