Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(tools): skip blank/NaN symbol rows in futu and generic journal parsers

Robin1987China1af03bb312bc
diff --git a/agent/src/tools/trade_journal_parsers.py b/agent/src/tools/trade_journal_parsers.py
index 1b62c91af..335a060f3 100644
--- a/agent/src/tools/trade_journal_parsers.py
+++ b/agent/src/tools/trade_journal_parsers.py
@@ -284,10 +284,13 @@ def parse_futu(df: pd.DataFrame) -> list[TradeRecord]:
"""
records: list[TradeRecord] = []
for _, row in df.iterrows():
+ raw_symbol = row.get("Symbol", "")
+ if _is_empty_code(raw_symbol):
+ continue
date = str(row.get("Date", "")).strip()
time = str(row.get("Time", "")).strip()
dt = f"{date} {time}".strip()
- symbol = str(row.get("Symbol", "")).strip().upper()
+ symbol = str(raw_symbol).strip().upper()
qty = _to_float(row.get("Quantity"))
price = _to_float(row.get("Price"))
amount = _to_float(row.get("Amount")) or qty * price
@@ -341,6 +344,8 @@ def parse_generic(df: pd.DataFrame) -> list[TradeRecord]:
records: list[TradeRecord] = []
for _, row in df.iterrows():
+ if sym_col and _is_empty_code(row.get(sym_col)):
+ continue
if dt_col:
dt = str(row.get(dt_col, "")).strip()
elif date_col:
diff --git a/agent/tests/test_trade_journal.py b/agent/tests/test_trade_journal.py
index 8032de6d9..2b2133ed0 100644
--- a/agent/tests/test_trade_journal.py
+++ b/agent/tests/test_trade_journal.py
@@ -21,6 +21,8 @@ from src.tools.trade_journal_parsers import (
_qualify_a_share,
parse_tonghuashun,
parse_eastmoney,
+ parse_futu,
+ parse_generic,
detect_format,
parse_file,
records_to_dataframe,
@@ -565,3 +567,34 @@ def test_parse_eastmoney_skips_nan_code_rows() -> None:
rec = parse_eastmoney(df)
assert len(rec) == 1
assert rec[0].symbol == "000001.SZ"
+
+
+def test_parse_futu_skips_nan_symbol_rows() -> None:
+ """NaN Symbol cells must not become literal "NAN" US trades."""
+ df = pd.DataFrame([{
+ "Date": "2024-01-01", "Time": "10:00:00", "Symbol": float("nan"),
+ "Name": "", "Side": "Buy", "Quantity": 100, "Price": 10.0,
+ "Amount": 1000, "Commission": 0, "Platform Fee": 0,
+ }, {
+ "Date": "2024-01-01", "Time": "10:01:00", "Symbol": "AAPL",
+ "Name": "Apple", "Side": "Buy", "Quantity": 100, "Price": 10.0,
+ "Amount": 1000, "Commission": 0, "Platform Fee": 0,
+ }])
+ rec = parse_futu(df)
+ assert len(rec) == 1
+ assert rec[0].symbol == "AAPL"
+ assert rec[0].market == "us"
+
+
+def test_parse_generic_skips_nan_symbol_rows() -> None:
+ """Blank/NaN symbol cells are dropped instead of stringified to "nan"."""
+ df = pd.DataFrame([{
+ "datetime": "2024-01-01 10:00:00", "symbol": float("nan"),
+ "side": "buy", "quantity": 100, "price": 10.0,
+ }, {
+ "datetime": "2024-01-01 10:01:00", "symbol": "AAPL",
+ "side": "buy", "quantity": 100, "price": 10.0,
+ }])
+ rec = parse_generic(df)
+ assert len(rec) == 1
+ assert rec[0].symbol == "AAPL"