database/insert_ohlc_example.py

23 lines
746 B
Python

import pandas as pd
from database.ohlc import insert
from datetime import datetime, date, timedelta
from iqfeed.iqfeed import get_historical_data, minutes
today = date.today()
symbol = 'VIX1D.XO'
yesterday = date.today() - timedelta(days=1)
data = get_historical_data(symbol, minutes(5),
start_date = datetime.combine(date(2016, 1, 1), datetime.min.time()),
end_date = datetime.combine(yesterday, 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)