fix: /v1/stock/klines接口已通

master
Lxy 3 months ago
parent 7966856011
commit 9fe481f7a7

@ -223,30 +223,45 @@ class AmazingDataAdapter(DataSourceAdapter):
results = [] results = []
if symbol in kline_dict: if symbol in kline_dict:
df = kline_dict[symbol] 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(): for _, row in df.iterrows():
print(f"[amazingdata_adapter _fetch_klines_sync]正在处理行: {row}") # 从 kline_time 列获取日期AmazingData 返回的日期字段)
# 解析日期时间 kline_time = row.get('kline_time')
# if isinstance(row.name, pd.Timestamp): if pd.isna(kline_time) or kline_time is None:
# ts = int(row.name.timestamp()) print(f"[amazingdata_adapter _fetch_klines_sync]跳过无效日期: kline_time 为空")
# trade_date = row.name.strftime('%Y-%m-%d') continue
# else:
# 假设是整数日期格式 YYYYMMDD try:
# date_str = str(row.name) # kline_time 可能是 Timestamp 或整数 YYYYMMDD
# dt = datetime.strptime(date_str, "%Y-%m-%d") if isinstance(kline_time, pd.Timestamp):
# ts = int(dt.timestamp()) ts = int(kline_time.timestamp())
# trade_date = dt.strftime('%Y-%m-%d') 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( results.append(KLineData(
symbol=symbol, symbol=symbol,
# time=ts, time=ts,
time=datetime.fromtimestamp("2026-03-02").strftime('%Y-%m-%d'),
open=float(row.get('open', 0)), open=float(row.get('open', 0)),
high=float(row.get('high', 0)), high=float(row.get('high', 0)),
low=float(row.get('low', 0)), low=float(row.get('low', 0)),
close=float(row.get('close', 0)), close=float(row.get('close', 0)),
volume=int(row.get('volume', 0)), volume=int(row.get('volume', 0)),
amount=float(row.get('amount', 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}") info(f"Fetched {len(results)} klines from AmazingData for {symbol}")

@ -74,6 +74,7 @@ class DataSourceStatus(str, Enum):
class KLineItem(BaseModel): class KLineItem(BaseModel):
"""单条K线数据""" """单条K线数据"""
symbol: Optional[str] = Field(None, description="标的代码")
time: datetime = Field(..., description="时间戳") time: datetime = Field(..., description="时间戳")
open: float = Field(..., description="开盘价") open: float = Field(..., description="开盘价")
high: float = Field(..., description="最高价") high: float = Field(..., description="最高价")

Loading…
Cancel
Save