Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception handling for invalid interval #80

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"])
Loading