database/insert_ohlc_example.py

23 lines
746 B
Python
Raw Normal View History

2023-09-28 21:23:40 +00:00
import pandas as pd
from database.ohlc import insert
2023-10-02 20:07:32 +00:00
from datetime import datetime, date, timedelta
2023-09-28 21:23:40 +00:00
from iqfeed.iqfeed import get_historical_data, minutes
today = date.today()
2023-10-02 20:07:32 +00:00
symbol = 'VIX1D.XO'
yesterday = date.today() - timedelta(days=1)
2023-09-28 21:23:40 +00:00
data = get_historical_data(symbol, minutes(5),
2023-10-02 20:07:32 +00:00
start_date = datetime.combine(date(2016, 1, 1), datetime.min.time()),
end_date = datetime.combine(yesterday, datetime.max.time()))
2023-09-28 21:23:40 +00:00
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)