diff --git a/app/adapters/__pycache__/amazingdata_adapter.cpython-311.pyc b/app/adapters/__pycache__/amazingdata_adapter.cpython-311.pyc index faee356..e44baea 100644 Binary files a/app/adapters/__pycache__/amazingdata_adapter.cpython-311.pyc and b/app/adapters/__pycache__/amazingdata_adapter.cpython-311.pyc differ diff --git a/app/adapters/amazingdata_adapter.py b/app/adapters/amazingdata_adapter.py index b62d363..8823e22 100644 --- a/app/adapters/amazingdata_adapter.py +++ b/app/adapters/amazingdata_adapter.py @@ -223,30 +223,45 @@ class AmazingDataAdapter(DataSourceAdapter): results = [] if symbol in kline_dict: df = kline_dict[symbol] + print(f"[amazingdata_adapter _fetch_klines_sync]DataFrame columns: {df.columns.tolist()}") + print(f"[amazingdata_adapter _fetch_klines_sync]DataFrame head:\n{df.head()}") + for _, row in df.iterrows(): - print(f"[amazingdata_adapter _fetch_klines_sync]正在处理行: {row}") - # 解析日期时间 - # if isinstance(row.name, pd.Timestamp): - # ts = int(row.name.timestamp()) - # trade_date = row.name.strftime('%Y-%m-%d') - # else: - # 假设是整数日期格式 YYYYMMDD - # date_str = str(row.name) - # dt = datetime.strptime(date_str, "%Y-%m-%d") - # ts = int(dt.timestamp()) - # trade_date = dt.strftime('%Y-%m-%d') - + # 从 kline_time 列获取日期(AmazingData 返回的日期字段) + kline_time = row.get('kline_time') + if pd.isna(kline_time) or kline_time is None: + print(f"[amazingdata_adapter _fetch_klines_sync]跳过无效日期: kline_time 为空") + continue + + try: + # kline_time 可能是 Timestamp 或整数 YYYYMMDD + if isinstance(kline_time, pd.Timestamp): + ts = int(kline_time.timestamp()) + trade_date = kline_time.strftime('%Y-%m-%d') + else: + # 整数格式 YYYYMMDD + date_str = str(int(kline_time)) + if len(date_str) != 8: + print(f"[amazingdata_adapter _fetch_klines_sync]跳过无效日期: {date_str}") + continue + + dt = datetime.strptime(date_str, "%Y%m%d") + ts = int(dt.timestamp()) + trade_date = dt.strftime('%Y-%m-%d') + except (ValueError, TypeError) as e: + print(f"[amazingdata_adapter _fetch_klines_sync]日期解析错误 '{kline_time}' (type: {type(kline_time)}): {e}") + continue + results.append(KLineData( symbol=symbol, - # time=ts, - time=datetime.fromtimestamp("2026-03-02").strftime('%Y-%m-%d'), + time=ts, open=float(row.get('open', 0)), high=float(row.get('high', 0)), low=float(row.get('low', 0)), close=float(row.get('close', 0)), volume=int(row.get('volume', 0)), amount=float(row.get('amount', 0)), - trade_date=row.get('kline_time').strftime('%Y-%m-%d') + trade_date=trade_date )) info(f"Fetched {len(results)} klines from AmazingData for {symbol}") diff --git a/app/models/__pycache__/types.cpython-311.pyc b/app/models/__pycache__/types.cpython-311.pyc index 2e299e9..3a22eac 100644 Binary files a/app/models/__pycache__/types.cpython-311.pyc and b/app/models/__pycache__/types.cpython-311.pyc differ diff --git a/app/models/types.py b/app/models/types.py index f2fb8f7..8ec4183 100644 --- a/app/models/types.py +++ b/app/models/types.py @@ -74,6 +74,7 @@ class DataSourceStatus(str, Enum): class KLineItem(BaseModel): """单条K线数据""" + symbol: Optional[str] = Field(None, description="标的代码") time: datetime = Field(..., description="时间戳") open: float = Field(..., description="开盘价") high: float = Field(..., description="最高价")