From ae2e21f21d2ed81d5355136eb315055f9fe79a6d Mon Sep 17 00:00:00 2001 From: hhaishen <122429037+hhaishen@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:38:13 +0800 Subject: [PATCH 1/2] Update market_analyzer.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复6个指数2个获取失败问题,更改为新浪财经接口 --- market_analyzer.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/market_analyzer.py b/market_analyzer.py index 4931d2da4..30033060c 100644 --- a/market_analyzer.py +++ b/market_analyzer.py @@ -88,12 +88,12 @@ class MarketAnalyzer: # 主要指数代码 MAIN_INDICES = { - '000001': '上证指数', - '399001': '深证成指', - '399006': '创业板指', - '000688': '科创50', - '000016': '上证50', - '000300': '沪深300', + 'sh000001': '上证指数', + 'sz399001': '深证成指', + 'sz399006': '创业板指', + 'sh000688': '科创50', + 'sh000016': '上证50', + 'sh000300': '沪深300', } def __init__(self, search_service: Optional[SearchService] = None, analyzer=None): @@ -139,8 +139,8 @@ class MarketAnalyzer: try: logger.info("[大盘] 获取主要指数实时行情...") - # 使用 akshare 获取指数行情 - df = ak.stock_zh_index_spot_em() + # 使用 akshare 获取指数行情(新浪财经接口,包含深市指数) + df = ak.stock_zh_index_spot_sina() if df is not None and not df.empty: for code, name in self.MAIN_INDICES.items(): From 6f510e377f098e8c96d2f715bca4f6f2e6b5a8fb Mon Sep 17 00:00:00 2001 From: hhaishen <122429037+hhaishen@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:43:54 +0800 Subject: [PATCH 2/2] Update market_analyzer.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 北向资金已于2024年8月19日之后不再提供数据,注释掉相关代码 --- market_analyzer.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/market_analyzer.py b/market_analyzer.py index 30033060c..e6c123d94 100644 --- a/market_analyzer.py +++ b/market_analyzer.py @@ -128,7 +128,7 @@ class MarketAnalyzer: self._get_sector_rankings(overview) # 4. 获取北向资金(可选) - self._get_north_flow(overview) + # self._get_north_flow(overview) return overview @@ -245,26 +245,26 @@ class MarketAnalyzer: except Exception as e: logger.error(f"[大盘] 获取板块涨跌榜失败: {e}") - def _get_north_flow(self, overview: MarketOverview): - """获取北向资金流入""" - try: - logger.info("[大盘] 获取北向资金...") + # def _get_north_flow(self, overview: MarketOverview): + # """获取北向资金流入""" + # try: + # logger.info("[大盘] 获取北向资金...") - # 获取北向资金数据 - df = ak.stock_hsgt_north_net_flow_in_em(symbol="北上") + # # 获取北向资金数据 + # df = ak.stock_hsgt_north_net_flow_in_em(symbol="北上") - if df is not None and not df.empty: - # 取最新一条数据 - latest = df.iloc[-1] - if '当日净流入' in df.columns: - overview.north_flow = float(latest['当日净流入']) / 1e8 # 转为亿元 - elif '净流入' in df.columns: - overview.north_flow = float(latest['净流入']) / 1e8 + # if df is not None and not df.empty: + # # 取最新一条数据 + # latest = df.iloc[-1] + # if '当日净流入' in df.columns: + # overview.north_flow = float(latest['当日净流入']) / 1e8 # 转为亿元 + # elif '净流入' in df.columns: + # overview.north_flow = float(latest['净流入']) / 1e8 - logger.info(f"[大盘] 北向资金净流入: {overview.north_flow:.2f}亿") + # logger.info(f"[大盘] 北向资金净流入: {overview.north_flow:.2f}亿") - except Exception as e: - logger.warning(f"[大盘] 获取北向资金失败: {e}") + # except Exception as e: + # logger.warning(f"[大盘] 获取北向资金失败: {e}") def search_market_news(self) -> List[Dict]: """