Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(journal): normalize Excel float YYYYMMDD dates in eastmoney parser

santhreal4c6f23cb25d2
diff --git a/agent/src/tools/trade_journal_parsers.py b/agent/src/tools/trade_journal_parsers.py
index 335a060f3..020111089 100644
--- a/agent/src/tools/trade_journal_parsers.py
+++ b/agent/src/tools/trade_journal_parsers.py
@@ -240,6 +240,13 @@ def parse_eastmoney(df: pd.DataFrame) -> list[TradeRecord]:
if _is_empty_code(raw_code):
continue
raw_date = str(row.get("成交日期", "")).strip()
+ # Excel numeric YYYYMMDD cells stringify as "20260115.0".
+ try:
+ as_float = float(raw_date)
+ if as_float.is_integer() and 19_000_001 <= int(as_float) <= 21_001_231:
+ raw_date = f"{int(as_float):08d}"
+ except (ValueError, OverflowError):
+ pass
raw_time = str(row.get("成交时间", "")).strip()
if len(raw_date) == 8 and raw_date.isdigit():
iso_date = f"{raw_date[:4]}-{raw_date[4:6]}-{raw_date[6:8]}"
diff --git a/agent/tests/test_eastmoney_float_dates.py b/agent/tests/test_eastmoney_float_dates.py
new file mode 100644
index 000000000..07f24fe6a
--- /dev/null
+++ b/agent/tests/test_eastmoney_float_dates.py
@@ -0,0 +1,43 @@
+"""Eastmoney YYYYMMDD dates from Excel floats must normalize to ISO."""
+
+from __future__ import annotations
+
+import pandas as pd
+
+from src.tools.trade_journal_parsers import parse_eastmoney
+
+
+def test_parse_eastmoney_float_yyyymmdd_date() -> None:
+ df = pd.DataFrame([{
+ "成交日期": 20260115.0,
+ "成交时间": "09:30:00",
+ "股票代码": "600519",
+ "股票名称": "茅台",
+ "买卖标志": "B",
+ "成交数量": "100",
+ "成交均价": "100",
+ "成交金额": "",
+ "佣金": "1",
+ "印花税": "0",
+ }])
+ rec = parse_eastmoney(df)
+ assert len(rec) == 1
+ assert rec[0].datetime == "2026-01-15 09:30:00"
+
+
+def test_parse_eastmoney_string_yyyymmdd_still_ok() -> None:
+ df = pd.DataFrame([{
+ "成交日期": "20260115",
+ "成交时间": "09:30:00",
+ "股票代码": "600519",
+ "股票名称": "茅台",
+ "买卖标志": "B",
+ "成交数量": "100",
+ "成交均价": "100",
+ "成交金额": "",
+ "佣金": "1",
+ "印花税": "0",
+ }])
+ rec = parse_eastmoney(df)
+ assert len(rec) == 1
+ assert rec[0].datetime == "2026-01-15 09:30:00"