现在可以正常工作了

This commit is contained in:
jackyu66git
2025-11-14 17:32:32 +08:00
parent 3401cb56bf
commit b072334adf
6 changed files with 464 additions and 299 deletions
+25
View File
@@ -85,6 +85,31 @@ def upsert_candles(base_dir: str, symbol: str, timeframe: str, candles: List[Lis
pass
def write_candles_snapshot(base_dir: str, symbol: str, timeframe: str, df: pd.DataFrame):
columns = ["timestamp", "open", "high", "low", "close", "volume"]
if df.empty:
safe_df = pd.DataFrame(columns=columns)
else:
safe_df = df[columns].copy()
safe_df = safe_df.drop_duplicates(subset=["timestamp"], keep="last").sort_values("timestamp").reset_index(drop=True)
p = _path(base_dir, symbol, timeframe)
with _lock:
temp_path = f"{p}.tmp"
try:
safe_df.to_parquet(temp_path, index=False)
os.replace(temp_path, p)
finally:
if os.path.exists(temp_path):
try:
os.remove(temp_path)
except OSError:
pass
def candle_path(base_dir: str, symbol: str, timeframe: str) -> str:
return _path(base_dir, symbol, timeframe)
def get_last_timestamp(base_dir: str, symbol: str, timeframe: str) -> Optional[int]:
p = _path(base_dir, symbol, timeframe)
if not os.path.exists(p):