From 57959d2278486eddf92842ab7b253232a8b755c4 Mon Sep 17 00:00:00 2001 From: mankind806 <251444827+mankind806@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:16:40 +0100 Subject: [PATCH] MT535: reset total_value for each holding A holding without a :19A::HOLD// clause got the total value of the previous holding; if the first holding had none, parse() raised UnboundLocalError. Reset total_value with the other per-holding values and add two tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NWM3zdiEV9ZBtiNXUKHuqw --- fints/utils.py | 2 +- tests/test_mt535.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/test_mt535.py diff --git a/fints/utils.py b/fints/utils.py index f02edb6..a656131 100644 --- a/fints/utils.py +++ b/fints/utils.py @@ -162,7 +162,7 @@ def parse(self, lines): finsegs = self.grab_financial_instrument_segments(clauses) # Third: Extract financial instrument data for finseg in finsegs: - isin, name, market_price, price_symbol, price_date, pieces, acquisitionprice = (None,)*7 + isin, name, market_price, price_symbol, price_date, pieces, total_value, acquisitionprice = (None,)*8 for clause in finseg: # identification of instrument # e.g. ':35B:ISIN LU0635178014|/DE/ETF127|COMS.-MSCI EM.M.T.U.ETF I' diff --git a/tests/test_mt535.py b/tests/test_mt535.py new file mode 100644 index 0000000..69b3b49 --- /dev/null +++ b/tests/test_mt535.py @@ -0,0 +1,34 @@ +from fints.utils import MT535_Miniparser + + +def _mt535_holding(isin, name, pieces, total_value=None): + lines = [ + ":16R:FIN", + ":35B:ISIN {}|/DE/X1|{}".format(isin, name), + ":90B::MRKT//ACTU/EUR10,00", + ":98A::PRIC//20260101", + ":93B::AGGR//UNIT/{},".format(pieces), + ] + if total_value is not None: + lines.append(":19A::HOLD//EUR{}".format(total_value)) + lines.append(":16S:FIN") + return lines + + +def test_mt535_holding_without_total_value_does_not_inherit_previous(): + lines = _mt535_holding("AA0000000001", "ONE", "5", "50,00") + lines += _mt535_holding("AA0000000002", "TWO", "7") + lines.append("-") + + first, second = MT535_Miniparser().parse(lines) + + assert first.total_value == 50.0 + assert second.total_value is None + + +def test_mt535_first_holding_without_total_value(): + lines = _mt535_holding("AA0000000003", "THREE", "1") + ["-"] + + (holding,) = MT535_Miniparser().parse(lines) + + assert holding.total_value is None