database/insert_ohlc_example.py

22 lines
681 B
Python
Raw Normal View History

2023-09-28 21:23:40 +00:00
import pandas as pd
from database.ohlc import insert
from datetime import datetime, date
from iqfeed.iqfeed import get_historical_data, minutes
today = date.today()
symbol = 'SPY'
data = get_historical_data(symbol, minutes(5),
start_date = datetime.combine(date(2023, 1, 1), datetime.min.time()),
end_date = datetime.combine(today, datetime.max.time()))
data['Symbol'] = symbol
data['Timeframe'] = '5m'
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']]
insert(data)