|
|
|
@ -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}")
|
|
|
|
|