Skip to content

Commit 54734ff

Browse files
committed
Trim redundant IBKR mapper metadata
1 parent 14b5f5c commit 54734ff

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

application/reconciliation_service.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def build_reconciliation_record(
4242
signal_metadata = dict(signal_metadata or {})
4343
execution_summary = dict(execution_summary or {})
4444
target_weights = dict(target_weights or {})
45+
allocation = dict(signal_metadata.get("allocation") or {})
46+
allocation_safe_haven_symbols = tuple(allocation.get("safe_haven_symbols") or ())
47+
allocation_safe_haven_symbol = allocation_safe_haven_symbols[0] if allocation_safe_haven_symbols else None
4548
record = {
4649
"strategy_profile": strategy_profile,
4750
"mode": mode,
@@ -55,7 +58,11 @@ def build_reconciliation_record(
5558
"realized_stock_weight": signal_metadata.get("realized_stock_weight"),
5659
"target_safe_haven_weight": signal_metadata.get("safe_haven_weight"),
5760
"realized_safe_haven_weight": execution_summary.get("realized_safe_haven_weight"),
58-
"safe_haven_symbol": execution_summary.get("safe_haven_symbol") or signal_metadata.get("safe_haven_symbol"),
61+
"safe_haven_symbol": (
62+
execution_summary.get("safe_haven_symbol")
63+
or signal_metadata.get("safe_haven_symbol")
64+
or allocation_safe_haven_symbol
65+
),
5966
"target_holdings": [
6067
{"symbol": symbol, "target_weight": float(weight)}
6168
for symbol, weight in sorted(target_weights.items(), key=lambda item: (-item[1], item[0]))
@@ -85,6 +92,9 @@ def build_reconciliation_record(
8592

8693
def write_reconciliation_record(record: dict[str, Any], *, output_path: str | Path | None = None) -> Path:
8794
path = Path(output_path) if output_path else default_reconciliation_output_path(record.get("strategy_profile"))
95+
if output_path and path.suffix.lower() != ".json":
96+
trade_date = str(record.get("trade_date") or "latest").strip() or "latest"
97+
path = path / trade_date / "reconciliation.json"
8898
path.parent.mkdir(parents=True, exist_ok=True)
8999
path.write_text(json.dumps(_json_safe(record), ensure_ascii=False, indent=2, sort_keys=True), encoding="utf-8")
90100
return path

decision_mapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def map_strategy_decision(
128128
metadata.setdefault("risk_flags", risk_flags)
129129
metadata.setdefault("actionable", not no_execute)
130130
if allocation_payload:
131-
metadata.setdefault("target_mode", allocation_payload["target_mode"])
132131
metadata.setdefault("allocation", allocation_payload)
133132

134133
return target_weights, signal_desc, is_emergency, status_desc, metadata

tests/test_decision_mapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def test_map_strategy_decision_maps_weight_positions_and_safe_haven():
2828
assert metadata["safe_haven_symbol"] == "BOXX"
2929
assert metadata["managed_symbols"] == ("AAA", "BOXX")
3030
assert metadata["status_icon"] == "🧲"
31-
assert metadata["target_mode"] == "weight"
3231
assert metadata["allocation"]["target_mode"] == "weight"
3332
assert metadata["allocation"]["strategy_symbols"] == ("AAA", "BOXX")
3433
assert metadata["allocation"]["targets"] == {"AAA": 0.6, "BOXX": 0.4}
3534
assert metadata["allocation"]["positions"][1]["role"] == "safe_haven"
35+
assert "target_mode" not in metadata
3636

3737

3838
def test_map_strategy_decision_returns_noop_when_flagged_no_execute():

0 commit comments

Comments
 (0)