From 07b3af1877ea21d94f8b6dd7772c4dc8655edbf7 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 12 Nov 2024 06:33:08 -0800 Subject: [PATCH] Handle scenario where historical data is unavailable for the specified date(s) --- iqfeed/iqfeed.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iqfeed/iqfeed.py b/iqfeed/iqfeed.py index 5377ea1..1caff0a 100644 --- a/iqfeed/iqfeed.py +++ b/iqfeed/iqfeed.py @@ -95,6 +95,9 @@ def get_historical_data(symbol: str, interval: int, date: datetime = None, data = StringIO(data) data = pd.read_csv(data, index_col = False, names=['Date', 'High', 'Low', 'Open', 'Close', 'Total Volume', 'Period Volume']) + if data.empty: + return data + data['Date'] = pd.to_datetime(data['Date']) data['Date'] = data['Date'].dt.date return data