From 8e78ee15ce600577d4f006bf5afffe190080d805 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Fri, 22 Nov 2024 11:45:06 -0800 Subject: [PATCH] Re-order intraday data columns, add a time column, and rename volume column --- iqfeed/iqfeed.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/iqfeed/iqfeed.py b/iqfeed/iqfeed.py index f52105a..7da1c78 100644 --- a/iqfeed/iqfeed.py +++ b/iqfeed/iqfeed.py @@ -98,14 +98,16 @@ def get_historical_data(symbol: str, interval: int, date: datetime = None, data = data.replace(',\n','\n')[:-1] data = StringIO(data) - data = pd.read_csv(data, index_col = False, names = columns) + data = pd.read_csv(data, index_col = False, names = iqfeed_columns) - if data[columns].isna().any(axis = 1).any() or data.empty: - return pd.DataFrame(columns = columns) + if data[iqfeed_columns].isna().any(axis = 1).any() or data.empty: + return pd.DataFrame(columns = intraday_columns) - data['Date'] = pd.to_datetime(data['Date']) - data['Date'] = data['Date'].dt.date - return data + timestamp = pd.to_datetime(data['Date']) + data['Date'] = timestamp.dt.date + data['Time'] = timestamp.dt.time + data = data.rename(columns = { 'Period Volume': 'Volume' }) + return data[intraday_columns] if __name__ == '__main__': symbols = ['SPY']