From 8bf31cde1d0f7c6deeb9fe5bb1c53dc6ad5f0c30 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sat, 30 Mar 2024 06:18:04 -0700 Subject: [PATCH] Add support for querying a single day's worth of historical OHLC data --- iqfeed/iqfeed.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/iqfeed/iqfeed.py b/iqfeed/iqfeed.py index fc762d0..0e08140 100644 --- a/iqfeed/iqfeed.py +++ b/iqfeed/iqfeed.py @@ -1,7 +1,7 @@ import pandas as pd import socket -from datetime import datetime +from datetime import datetime, time from dotenv import load_dotenv from os import getenv from io import StringIO @@ -63,11 +63,15 @@ def minutes(value): def hours(value): return value * 3600 -def get_historical_data(symbol: str, interval: int, - start_date: datetime, end_date: datetime = None, +def get_historical_data(symbol: str, interval: int, date: datetime = None, + start_date: datetime = None, end_date: datetime = None, start_filter_time: datetime = datetime.strptime('093000', '%H%M%S').time(), end_filter_time: datetime = datetime.strptime('160000', '%H%M%S').time()) -> pd.DataFrame: - + + if date: + start_date = date + end_date = datetime.combine(date, time.max) + message = 'HIT,{symbol},{interval},{begin},{end},,{begin_filter},{end_filter},1\n'.format( symbol = symbol, interval = interval, @@ -94,8 +98,7 @@ def get_historical_data(symbol: str, interval: int, if __name__ == '__main__': symbols = ['SPY'] - start_date = datetime(2023, 1, 1, 7, 50) - end_date = datetime(2023, 1, 31, 16, 0) + date = datetime(2024, 3, 28) for symbol in symbols: - data = get_historical_data(symbol, minutes(5), start_date, end_date) + data = get_historical_data(symbol, minutes(5), date) print(data)