csv-parser: keep LLM-mapped tickers; don't pass them through T212 mapping

The route's resolve-slice loop is T212-specific — it looks tickers up
against the InstrumentMap, which only has T212's universe. For the LLM
path the ticker is already Yahoo-ready (e.g. VOD.L, ASML.AS), so
sending it through resolve_slice produced spurious "could not be
resolved" warnings and dropped the positions.

Fix: ParsedPie gains a ``tickers_resolved`` flag (default False for
T212 backward-compat); _apply_mapping in the LLM path sets it True
and also extracts currency from the LLM-mapped currency_col into a
new ``ParsedPosition.currency`` field. The route branches on the flag:
LLM-path positions are kept verbatim with a best-effort InstrumentMap
lookup for nicer name/currency overrides, never dropped.

Integration test tightened to assert all 5 IBKR fixture positions
round-trip with the right currencies (USD / GBP / EUR).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-05-27 12:48:27 +02:00
parent b8ebba9503
commit bc55ab7d26
4 changed files with 74 additions and 13 deletions

View file

@ -250,6 +250,7 @@ def _apply_mapping(
qty_col = mapping["qty_col"]
name_col = mapping.get("name_col")
cost_col = mapping.get("cost_col")
currency_col = mapping.get("currency_col")
positions: list[ParsedPosition] = []
invested_total = 0.0
@ -279,6 +280,9 @@ def _apply_mapping(
name = row[idx[name_col]].strip()
if not name:
name = ticker
currency: str | None = None
if currency_col is not None and idx[currency_col] < len(row):
currency = row[idx[currency_col]].strip() or None
positions.append(ParsedPosition(
slice=ticker,
name=name,
@ -286,6 +290,7 @@ def _apply_mapping(
current_value=None,
result=None,
quantity=qty,
currency=currency,
))
return ParsedPie(
@ -294,6 +299,7 @@ def _apply_mapping(
invested=(invested_total if invested_seen else None),
value=None,
result=None,
tickers_resolved=True,
)