From 36d1f8d76c9a3e6f0089b828d4ae456d50d958f5 Mon Sep 17 00:00:00 2001 From: Surohit Tandon Date: Sat, 23 Mar 2024 11:55:21 -0700 Subject: [PATCH 1/2] expection handling for invalid interval --- qtrade/questrade.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qtrade/questrade.py b/qtrade/questrade.py index 29337f5..edfcdc3 100644 --- a/qtrade/questrade.py +++ b/qtrade/questrade.py @@ -480,6 +480,11 @@ def get_historical_data( else: log.error(f"Something went wrong retrieving the symbol ID for ticker {ticker}...") raise Exception(f"Something went wrong retrieving the symbol ID for ticker {ticker}...") + + if interval not in self._valid_intervals(): + log.error(f"{interval} not a valid interval option.") + raise Exception(f"{interval} must be one of {list(self._valid_intervals())}") + payload = { "startTime": str(start_date) + "T00:00:00-05:00", "endTime": str(end_date) + "T00:00:00-05:00", @@ -684,3 +689,8 @@ def get_option_quotes(self, filters: List[Dict], option_ids: List[int]) -> Dict: def __del__(self): """Close session when class instance is deleted.""" self.session.close() + + @staticmethod + def _valid_intervals(): + return set(["OneDay", "OneWeek", "OneMonth", "OneYear"]) + From b0f0461fb0e7f4039e63b14b5d691e38d8a2a3a4 Mon Sep 17 00:00:00 2001 From: Surohit Tandon Date: Sat, 23 Mar 2024 12:14:27 -0700 Subject: [PATCH 2/2] remove linespace --- qtrade/questrade.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qtrade/questrade.py b/qtrade/questrade.py index edfcdc3..1a0198a 100644 --- a/qtrade/questrade.py +++ b/qtrade/questrade.py @@ -693,4 +693,3 @@ def __del__(self): @staticmethod def _valid_intervals(): return set(["OneDay", "OneWeek", "OneMonth", "OneYear"]) -