Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def apply_small_account_cash_compatibility(
safe_haven_substituted.append(symbol)

notes: list[dict[str, object]] = []
if safe_haven_substituted:
if substituted:
normalized_targets = {
_normalize_symbol(symbol): float(value or 0.0)
for symbol, value in dict(target_values or {}).items()
Expand Down
16 changes: 13 additions & 3 deletions tests/test_small_account_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ def test_keeps_safe_haven_when_cash_projection_exceeds_small_account_limit(self)
self.assertEqual(result.targets["BOXX"], 5000.0)
self.assertEqual(result.whole_share_substituted_symbols, ("SOXX",))
self.assertEqual(result.safe_haven_cash_substituted_symbols, ())
self.assertEqual(result.cash_substitution_notes, ())
self.assertEqual(
result.cash_substitution_notes,
(
{
"symbol": "SOXX",
"target_value": 163.14,
"price": 504.60,
"cash_symbols": (),
},
),
)

def test_formats_cash_substitution_notes_through_i18n(self):
messages = format_small_account_cash_substitution_notes(
Expand All @@ -85,7 +95,7 @@ def test_formats_cash_substitution_notes_through_i18n(self):
"buy_deferred": "ℹ️ [买入说明] {detail}",
"buy_deferred_small_account_cash_substitution": (
"{symbol} 目标金额 ${diff} 低于 1 股价格 ${price};"
"为避免超过目标仓位,小账户本轮保留现金,不回补 {cash_symbols}"
"为避免超过目标仓位,本轮保留现金(现金替代:{cash_symbols}"
),
}.get(key, key).format(**kwargs),
)
Expand All @@ -94,7 +104,7 @@ def test_formats_cash_substitution_notes_through_i18n(self):
messages,
(
"ℹ️ [买入说明] SOXX.US 目标金额 $163.14 低于 1 股价格 $504.60;"
"为避免超过目标仓位,小账户本轮保留现金,不回补 BOXX.US",
"为避免超过目标仓位,本轮保留现金(现金替代:BOXX.US",
),
)

Expand Down