Check for NaNs before returning historical intraday data
This commit is contained in:
parent
575e106f32
commit
4e36de7bf0
@ -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,9 +95,11 @@ 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 = 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
|
||||
|
Loading…
Reference in New Issue
Block a user