schwab-py icon indicating copy to clipboard operation
schwab-py copied to clipboard

get_price_history doesn't honor start_datetime and end_datetime

Open s-maheshbabu opened this issue 7 months ago • 1 comments

Description of Bug get_price_history_every_minute and similar methods don't honor the start_datatime and end_datetime fields. Regardless of what the time bounds are, we return data for the entire day.

The API should either filter out data outside the provided bounds or just not accept bounds at all as an input.

Code to Reproduce

start_datetime = datetime(2024, 7, 3, 10, 0, 0, tzinfo=ZoneInfo("US/Eastern"))
end_datetime = datetime(2024, 7, 3, 11, 0, 0, tzinfo=ZoneInfo("US/Eastern"))
response = self.schwab_client.get_price_history_every_minute(
    "$SPX",
    start_datetime=start_datetime,
    end_datetime=end_datetime,
    need_extended_hours_data=False,
)

data = response.json()

data_for_the_hour = pd.json_normalize(data["candles"]).drop(columns=["volume"])

print(f"Number of datapoints returned: {len(data_for_the_hour)}")
print(data_for_the_hour)

Expected Behavior Data returned only for the requested hour i.e. 10 AM to 11 AM Eastern time. Number of candles returned should be 60.

Actual Behavior 224 one minute candles were returned. The earliest and latest timestamps are clearly beyond the provided time bounds in the API call.

Number of datapoints returned: 224
      open   high    low  close       datetime
0    12.06  12.06  12.05  12.05  1720013520000
1    12.04  12.05  12.04  12.05  1720013580000
2    12.06  12.07  12.06  12.07  1720013640000
3    12.08  12.09  12.08  12.09  1720013700000
4    12.07  12.07  12.05  12.05  1720013760000
..     ...    ...    ...    ...            ...
219  12.06  12.07  12.06  12.06  1720026660000
220  12.06  12.07  12.06  12.07  1720026720000
221  12.07  12.07  12.07  12.07  1720026780000
222  12.07  12.10  12.07  12.09  1720026840000
223  12.09  12.09  12.09  12.09  1720026900000

s-maheshbabu avatar Jul 03 '24 23:07 s-maheshbabu