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

Polygon maxretry showpath #485

Merged
merged 2 commits into from
Jul 6, 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
17 changes: 13 additions & 4 deletions lumibot/tools/polygon_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
import os
from urllib3.exceptions import MaxRetryError
from urllib.parse import urlparse, urlunparse

import pandas as pd
import pandas_market_calendars as mcal
Expand Down Expand Up @@ -510,7 +511,6 @@ class PolygonClient(RESTClient):
''' Rate Limited RESTClient with factory method '''

WAIT_SECONDS_RETRY = 60
WAIT_SECONDS_UNPAID = 12

@classmethod
def create(cls, *args, **kwargs) -> RESTClient:
Expand Down Expand Up @@ -553,10 +553,19 @@ def _get(self, *args, **kwargs):
return super()._get(*args, **kwargs)

except MaxRetryError as e:
colored_message = colored(
f"Polygon rate limit reached. Sleeping for {PolygonClient.WAIT_SECONDS_RETRY} seconds before trying again. If you want to avoid this, consider a paid subscription with Polygon at https://polygon.io/?utm_source=affiliate&utm_campaign=lumi10 Please use the full link to give us credit for the sale, it helps support this project. You can use the coupon code 'LUMI10' for 10% off.",
"red",
url = urlunparse(urlparse(kwargs['path'])._replace(query=""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Naming

The variable name 'url' in the MaxRetryError exception block is not descriptive enough to indicate its purpose. Consider renaming it to 'sanitized_url_path' to clarify that it represents the URL path without query parameters.


message = (
"Polygon rate limit reached.\n\n"
f"REST API call affected: {url}\n\n"
f"Sleeping for {PolygonClient.WAIT_SECONDS_RETRY} seconds seconds before trying again.\n\n"
"If you want to avoid this, consider a paid subscription with Polygon at https://polygon.io/?utm_source=affiliate&utm_campaign=lumi10\n"
"Please use the full link to give us credit for the sale, it helps support this project.\n"
"You can use the coupon code 'LUMI10' for 10% off."
)
Comment on lines +558 to 565
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Logging Severity Major

The log message in the MaxRetryError exception handling block is too verbose and contains sensitive information. Please simplify the log message and remove the coupon code from the log. Consider sending the coupon code to the user through a more secure channel.


colored_message = colored(message, "red")

logging.error(colored_message)
logging.debug(f"Error: {e}")
time.sleep(PolygonClient.WAIT_SECONDS_RETRY)
Loading