diff --git a/sanguo_portfolio/strategies/all_weather.py b/sanguo_portfolio/strategies/all_weather.py index dcca854..0cadc85 100644 --- a/sanguo_portfolio/strategies/all_weather.py +++ b/sanguo_portfolio/strategies/all_weather.py @@ -173,19 +173,15 @@ class AllWeatherStrategy: for stock in self.yesterday_hl_list: if stock not in positions: continue - row = self._intraday_high_low(stock, now_time) - if row is None: + status = self._limit_status(stock, now_time) + if status is None: continue - close = row.get("close") - high_limit = row.get("high_limit") - if close is None or high_limit is None: - continue - if close < high_limit: + if status.get("is_limit_up"): + logger.info("[%s]涨停,继续持有", stock) + else: logger.info("[%s]涨停打开,卖出", stock) self._close_position(stock) num_sold += 1 - else: - logger.info("[%s]涨停,继续持有", stock) # 2) 止损 -8% remaining: List[str] = [] @@ -456,27 +452,23 @@ class AllWeatherStrategy: arr = np.nan_to_num(change.to_numpy()) return float(np.mean(arr)) - def _intraday_high_low(self, stock: str, now_time: Any) -> Optional[Dict[str, Any]]: - """取当日 1m close + high_limit(聚宽 stop_loss 用)。""" + def _limit_status(self, stock: str, now_time: Any) -> Optional[Dict[str, Any]]: + """查当日涨跌停/停牌状态(P1.2 去 1m 依赖)。 + + 原实现取 1m close+high_limit,但数据层无 1m 表(仅 d/15m)→ 该分支在 + 日线路径静默失效。改用 get_limit_status_batch(日线 prev_close×板块 + 幅度精确算涨跌停价,与 filters/其他策略同源)。provider 未实现/异常 + → None(跳过该股,等价原失效行为)。 + """ + fn = getattr(self.provider, "get_limit_status_batch", None) + if fn is None: + return None try: - df = self.provider.get_price( - stock, - end_date=now_time, - frequency="1m", - fields=["close", "high_limit"], - skip_paused=False, - fq="pre", - count=1, - panel=False, - fill_paused=True, - ) + result = fn([stock], now_time) or {} except Exception as exc: - logger.debug("intraday_high_low 失败 %s: %s", stock, exc) + logger.warning("get_limit_status_batch 失败 %s: %s", stock, exc) return None - if df is None or len(df) == 0: - return None - row = df.iloc[0] - return {"close": row.get("close"), "high_limit": row.get("high_limit")} + return result.get(stock) # ======================== context 适配 ========================