diff --git a/iqfeed/iqfeed.py b/iqfeed/iqfeed.py index e39fe93..c3e2219 100644 --- a/iqfeed/iqfeed.py +++ b/iqfeed/iqfeed.py @@ -8,6 +8,8 @@ from os import getenv load_dotenv() +columns = ['Date', 'High', 'Low', 'Open', 'Close', 'Total Volume', 'Period Volume'] + def read_data_from_socket(sock, recv_buffer = 4096): buffer = b'' data = b'' @@ -93,11 +95,13 @@ 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=['Date', 'High', 'Low', 'Open', 'Close', 'Total Volume', 'Period Volume']) - if not data.empty: - data['Date'] = pd.to_datetime(data['Date']) - data['Date'] = data['Date'].dt.date + data = pd.read_csv(data, index_col = False, names = columns) + + if data[columns].isna().any(axis = 1).any() or data.empty: + return pd.DataFrame(columns = columns) + + data['Date'] = pd.to_datetime(data['Date']) + data['Date'] = data['Date'].dt.date return data if __name__ == '__main__':