2024-11-22 20:47:48 +00:00
|
|
|
from datetime import date, datetime, timedelta
|
2023-12-05 14:16:22 +00:00
|
|
|
|
|
|
|
from database.ohlc import insert
|
|
|
|
from iqfeed import get_daily_data, get_historical_data, minutes
|
|
|
|
|
2024-11-22 20:47:48 +00:00
|
|
|
from symbols_and_timeframes import symbols_and_timeframes
|
2023-12-05 14:16:22 +00:00
|
|
|
|
2024-11-22 20:47:48 +00:00
|
|
|
start_date = datetime(2024, 11, 20)
|
|
|
|
end_date = date.today() - timedelta(days = 1)
|
2023-12-05 14:16:22 +00:00
|
|
|
|
|
|
|
for symbol, timeframe in symbols_and_timeframes:
|
|
|
|
if timeframe == '1d':
|
|
|
|
data = get_daily_data(symbol,
|
|
|
|
start_date = datetime.combine(start_date, datetime.min.time()),
|
2024-11-22 20:47:48 +00:00
|
|
|
end_date = datetime.combine(end_date, datetime.max.time()))
|
2023-12-05 14:16:22 +00:00
|
|
|
else: # Assuming minutes for now.
|
|
|
|
data = get_historical_data(symbol, minutes(int(timeframe[:-1])),
|
|
|
|
start_date = datetime.combine(start_date, datetime.min.time()),
|
2024-11-22 20:47:48 +00:00
|
|
|
end_date = datetime.combine(end_date, datetime.max.time()))
|
2023-12-05 14:16:22 +00:00
|
|
|
|
|
|
|
data['Symbol'] = symbol
|
|
|
|
data['Timeframe'] = timeframe
|
|
|
|
|
2024-11-22 20:47:48 +00:00
|
|
|
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']]
|
2023-12-05 14:16:22 +00:00
|
|
|
insert(data)
|