|
|
|
@ -52,10 +52,18 @@ def batch_fetch(req: BatchFetchRequest, db: Session = Depends(get_db)):
|
|
|
|
cached = get_cached_data(db, sym, data_type, periods)
|
|
|
|
cached = get_cached_data(db, sym, data_type, periods)
|
|
|
|
timeframes = []
|
|
|
|
timeframes = []
|
|
|
|
for p, candles in cached["timeframes"].items():
|
|
|
|
for p, candles in cached["timeframes"].items():
|
|
|
|
|
|
|
|
# 转换数据格式: time -> datetime
|
|
|
|
|
|
|
|
normalized_candles = []
|
|
|
|
|
|
|
|
for c in candles:
|
|
|
|
|
|
|
|
candle_dict = dict(c)
|
|
|
|
|
|
|
|
if 'time' in candle_dict and 'datetime' not in candle_dict:
|
|
|
|
|
|
|
|
candle_dict['datetime'] = candle_dict.pop('time')
|
|
|
|
|
|
|
|
normalized_candles.append(candle_dict)
|
|
|
|
|
|
|
|
|
|
|
|
timeframes.append(TimeframeData(
|
|
|
|
timeframes.append(TimeframeData(
|
|
|
|
period=p,
|
|
|
|
period=p,
|
|
|
|
candles=[CandleItem(**c) for c in candles],
|
|
|
|
candles=[CandleItem(**c) for c in normalized_candles],
|
|
|
|
candle_count=len(candles),
|
|
|
|
candle_count=len(normalized_candles),
|
|
|
|
fetched_at=cached.get("timestamp", ""),
|
|
|
|
fetched_at=cached.get("timestamp", ""),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
details[sym] = SymbolDataResponse(
|
|
|
|
details[sym] = SymbolDataResponse(
|
|
|
|
@ -88,10 +96,18 @@ def batch_fetch(req: BatchFetchRequest, db: Session = Depends(get_db)):
|
|
|
|
for p in periods:
|
|
|
|
for p in periods:
|
|
|
|
candles = all_timeframes.get(p, [])
|
|
|
|
candles = all_timeframes.get(p, [])
|
|
|
|
if candles:
|
|
|
|
if candles:
|
|
|
|
|
|
|
|
# 转换数据格式: time -> datetime
|
|
|
|
|
|
|
|
normalized_candles = []
|
|
|
|
|
|
|
|
for c in candles:
|
|
|
|
|
|
|
|
candle_dict = dict(c)
|
|
|
|
|
|
|
|
if 'time' in candle_dict and 'datetime' not in candle_dict:
|
|
|
|
|
|
|
|
candle_dict['datetime'] = candle_dict.pop('time')
|
|
|
|
|
|
|
|
normalized_candles.append(candle_dict)
|
|
|
|
|
|
|
|
|
|
|
|
timeframes.append(TimeframeData(
|
|
|
|
timeframes.append(TimeframeData(
|
|
|
|
period=p,
|
|
|
|
period=p,
|
|
|
|
candles=[CandleItem(**c) for c in candles],
|
|
|
|
candles=[CandleItem(**c) for c in normalized_candles],
|
|
|
|
candle_count=len(candles),
|
|
|
|
candle_count=len(normalized_candles),
|
|
|
|
fetched_at=result.get("timestamp", ""),
|
|
|
|
fetched_at=result.get("timestamp", ""),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|