Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(paper-trade): keep the board limit for ST stocks outside the main board

Rudy Mizrahi Celekli3cbb167e9d7a
diff --git a/agent/src/tools/paper_trade/limits_cn_a.py b/agent/src/tools/paper_trade/limits_cn_a.py
index a2111b1af..223628ae9 100644
--- a/agent/src/tools/paper_trade/limits_cn_a.py
+++ b/agent/src/tools/paper_trade/limits_cn_a.py
@@ -64,6 +64,7 @@ PROV_LIMIT_LIST_ROW = "limit_list:stk_limit_list_d"
#: ST price-limit ratio (REQUIREMENTS §4: ST ±5%). The board heuristic in
#: china_a.py cannot detect ST from the code alone; the table can.
_ST_LIMIT_RATIO = Decimal("0.05")
+_MAIN_BOARD_RATIO = Decimal("0.1")
_TICK = Decimal("0.01")
@@ -111,14 +112,18 @@ def heuristic_limit_prices(ts_code: str, prev_close: float, is_st: bool) -> tupl
"""Derive (up_limit, down_limit) from the board ratio and previous close.
Ratio source: ``china_a._price_limit`` (main board 10%, ChiNext/STAR
- 20%, BSE 30%), overridden to 5% when the ST table says the symbol is
- ST that day. Quantized to the 0.01 tick with ROUND_HALF_UP (VD-9).
+ 20%, BSE 30%), overridden to 5% on the main board when the ST table
+ says the symbol is ST that day. Quantized to the 0.01 tick with ROUND_HALF_UP (VD-9).
``prev_close`` must be positive — non-positive prices are a data-layer
sanity gate (plan R-V3), not something to derive bands from.
"""
if prev_close <= 0:
raise ValueError(f"prev_close must be positive to derive a heuristic band, got {prev_close!r}")
- ratio = _ST_LIMIT_RATIO if is_st else Decimal(str(_price_limit(ts_code)))
+ ratio = Decimal(str(_price_limit(ts_code)))
+ # ST status narrows only the main-board band; ChiNext, STAR and BSE
+ # risk-warning stocks keep their board's ratio.
+ if is_st and ratio == _MAIN_BOARD_RATIO:
+ ratio = _ST_LIMIT_RATIO
base = Decimal(str(prev_close))
up = (base * (Decimal(1) + ratio)).quantize(_TICK, rounding=ROUND_HALF_UP)
down = (base * (Decimal(1) - ratio)).quantize(_TICK, rounding=ROUND_HALF_UP)
diff --git a/agent/tests/test_paper_trade_limits_cn_a.py b/agent/tests/test_paper_trade_limits_cn_a.py
index dae9e09b1..024fada5f 100644
--- a/agent/tests/test_paper_trade_limits_cn_a.py
+++ b/agent/tests/test_paper_trade_limits_cn_a.py
@@ -105,6 +105,23 @@ def test_st_from_table_overrides_heuristic_ratio_to_five_percent() -> None:
assert PROV_ST_ROW in status.provenance
+ ("ts_code", "expected"),
+ [
+ ("300001.SZ", (12.0, 8.0)), # ChiNext ST keeps ±20%
+ ("688001.SH", (12.0, 8.0)), # STAR ST keeps ±20%
+ ("830799.BJ", (13.0, 7.0)), # BSE ST keeps ±30%
+ ],
+)
+def test_st_keeps_the_board_ratio_outside_the_main_board(
+ ts_code: str, expected: tuple[float, float]
+) -> None:
+ client = FakeLimitsClient(st=[{"type": "ST", "type_name": "ST"}])
+ status = get_limit_status(client, ts_code, _TRADE_DATE, prev_close=10.0)
+ assert status.is_st is True
+ assert (status.up_limit, status.down_limit) == expected
+
+
def test_heuristic_quantizes_half_up_not_banker() -> None:
# VD-9 trap pin: 10.05 × 1.1 = 11.055 → HALF_UP → 11.06.
# Builtin round(11.055, 2) gives 11.05 (float 11.0549999… + banker's).