Skip to content

Commit 0096bf9

Browse files
Pigbibiclaude
andauthored
fix: add buying-power guard to small-account bootstrap (#242)
Skip bootstrap when estimated buying power (liquid_cash - reserved_cash) is below 1-share limit price. Prevents misleading "允许按 1 股下单" messages when the account cannot actually afford the share. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9a62f1a commit 0096bf9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

application/execution_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ def _apply_small_account_whole_share_compatibility(
699699
retained_symbols = []
700700
bootstrap_symbols = []
701701
portfolio = dict((plan or {}).get("portfolio") or {})
702+
execution = dict((plan or {}).get("execution") or {})
703+
_liquid_cash = float(portfolio.get("liquid_cash", 0.0) or 0.0)
704+
_reserved_cash = float(execution.get("reserved_cash", 0.0) or 0.0)
705+
_estimated_buying_power = max(0.0, _liquid_cash - _reserved_cash)
702706
quantities = {
703707
str(symbol or "").strip().upper(): float(quantity or 0.0)
704708
for symbol, quantity in dict(portfolio.get("quantities") or {}).items()
@@ -715,10 +719,13 @@ def _apply_small_account_whole_share_compatibility(
715719
if price > 0.0
716720
else 0.0
717721
)
722+
# Skip bootstrap if the account cannot afford even 1 share at limit price.
723+
_can_afford_one_share = limit_price > 0.0 and _estimated_buying_power >= limit_price
718724
if not _should_retain_existing_whole_share(symbol, target_value=target_value, price=price):
719725
if (
720726
quantities.get(symbol, 0.0) <= 0.0
721727
and 0.0 < target_value < limit_price
728+
and _can_afford_one_share
722729
and _should_bootstrap_whole_share_buy(symbol, target_value=target_value, limit_price=limit_price)
723730
):
724731
compatibility_targets[symbol] = limit_price
@@ -731,6 +738,7 @@ def _apply_small_account_whole_share_compatibility(
731738
if (
732739
quantities.get(symbol, 0.0) <= 0.0
733740
and 0.0 < target_value < limit_price
741+
and _can_afford_one_share
734742
and _should_bootstrap_whole_share_buy(symbol, target_value=target_value, limit_price=limit_price)
735743
):
736744
compatibility_targets[symbol] = limit_price

0 commit comments

Comments
 (0)