This commit is contained in:
David Chen
2026-03-14 20:14:33 +08:00
committed by GitHub
parent ab91804be1
commit 05c17f6b5d
16 changed files with 3177 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
from typing import List
import pandas as pd
from internal_types.types import OHLC, Instrument
# todo: download parquet from clickhouse and store locally
def historical_data_tradingview_csv(csv: str, instr: Instrument, t0: str, t1: str) -> List[OHLC]:
# [t0, t1)
# t0 & t1: YYYY-mm-dd
df = pd.read_csv(csv)
df['date_dt'] = pd.to_datetime(df['time'], unit='s')
df = df.rename(columns={'time': 'timestamp', 'Volume': 'volume'})
df = df[(pd.Timestamp(t0) <= df['date_dt']) & (df['date_dt'] < pd.Timestamp(t1))]
return [
OHLC(
instr=instr,
timestamp=row.timestamp, # type: ignore
open=row.open, # type: ignore
high=row.high, # type: ignore
low=row.low, # type: ignore
close=row.close, # type: ignore
volume=row.volume) # type: ignore
for row in df.itertuples(index=False)
]