Skip to content

Commit

Permalink
exception handling for invalid interval (#80)
Browse files Browse the repository at this point in the history
* expection handling for invalid interval

* remove linespace

---------

Co-authored-by: Surohit Tandon <surohittandon@Surohits-Macbook-Air-M2.local>
  • Loading branch information
Surohitt and Surohit Tandon authored Mar 26, 2024
1 parent 2bd0453 commit 5cdbf35
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qtrade/questrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -684,3 +689,7 @@ 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"])

0 comments on commit 5cdbf35

Please sign in to comment.