Update OHLC backfill script following changes to OHLC data client

This commit is contained in:
moshferatu 2024-11-22 12:47:48 -08:00
parent 8f4c03e59b
commit 0400589418

View File

@ -1,31 +1,30 @@
import pandas as pd
from datetime import date, datetime, timedelta
from database.ohlc import insert
from datetime import datetime#, date, timedelta
from iqfeed import get_daily_data, get_historical_data, minutes
symbols_and_timeframes = []
from symbols_and_timeframes import symbols_and_timeframes
start_date = datetime(2023, 12, 1)
# yesterday = date.today() - timedelta(days=1)
start_date = datetime(2024, 11, 20)
end_date = date.today() - timedelta(days = 1)
for symbol, timeframe in symbols_and_timeframes:
if timeframe == '1d':
data = get_daily_data(symbol,
start_date = datetime.combine(start_date, datetime.min.time()),
end_date = datetime.combine(start_date, datetime.max.time()))
end_date = datetime.combine(end_date, datetime.max.time()))
else: # Assuming minutes for now.
data = get_historical_data(symbol, minutes(int(timeframe[:-1])),
start_date = datetime.combine(start_date, datetime.min.time()),
end_date = datetime.combine(start_date, datetime.max.time()))
end_date = datetime.combine(end_date, datetime.max.time()))
data['Symbol'] = symbol
data['Timeframe'] = timeframe
data['Timestamp'] = pd.to_datetime(data['Date'])
data['Date'] = data['Timestamp'].dt.date
data = data.rename(columns={
'Period Volume': 'Volume'
})
data = data[['Symbol', 'Date', 'Timeframe', 'Timestamp', 'Open', 'High', 'Low', 'Close', 'Volume']]
if 'Time' in data.columns:
data['Timestamp'] = data.apply(lambda row: datetime.combine(row['Date'], row['Time']), axis = 1)
else:
data['Timestamp'] = data['Date'].apply(lambda date: datetime.combine(date, datetime.min.time()))
data = data[['Symbol', 'Date', 'Timeframe', 'Timestamp', 'Open', 'High', 'Low', 'Close', 'Volume']]
insert(data)