-
This commit is contained in:
28
historical_data/historical_data.py
Normal file
28
historical_data/historical_data.py
Normal 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)
|
||||
]
|
||||
Reference in New Issue
Block a user