Check for NaNs before returning historical intraday data

This commit is contained in:
moshferatu 2024-11-13 07:28:41 -08:00
parent 575e106f32
commit 4e36de7bf0

View File

@ -8,6 +8,8 @@ from os import getenv
load_dotenv() load_dotenv()
columns = ['Date', 'High', 'Low', 'Open', 'Close', 'Total Volume', 'Period Volume']
def read_data_from_socket(sock, recv_buffer = 4096): def read_data_from_socket(sock, recv_buffer = 4096):
buffer = b'' buffer = b''
data = 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 = data.replace(',\n','\n')[:-1]
data = StringIO(data) data = StringIO(data)
data = pd.read_csv(data, index_col = False, data = pd.read_csv(data, index_col = False, names = columns)
names=['Date', 'High', 'Low', 'Open', 'Close', 'Total Volume', 'Period Volume'])
if not data.empty: if data[columns].isna().any(axis = 1).any() or data.empty:
data['Date'] = pd.to_datetime(data['Date']) return pd.DataFrame(columns = columns)
data['Date'] = data['Date'].dt.date
data['Date'] = pd.to_datetime(data['Date'])
data['Date'] = data['Date'].dt.date
return data return data
if __name__ == '__main__': if __name__ == '__main__':