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

Auto polygon has paid #476

Merged
merged 4 commits into from
Jun 30, 2024
Merged

Auto polygon has paid #476

merged 4 commits into from
Jun 30, 2024

Conversation

grzesir
Copy link
Contributor

@grzesir grzesir commented Jun 29, 2024

No description provided.

Copy link
Contributor

korbit-ai bot commented Jun 29, 2024

My review is in progress 📖 - I will have feedback for you in a few minutes!

Copy link
Contributor

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

I have reviewed your code and found 12 potential issues. To discuss my individual comments that I have added, tag me in replies using @korbit-ai.


Please react with a 👍 to my comments that you find helpful and a 👎 to those you find unhelpful - this will help me learn and improve as we collaborate.

@@ -91,5 +91,4 @@ def on_trading_iteration(self):
backtesting_end,
benchmark_asset="SPY",
polygon_api_key="YOUR_POLYGON_API_KEY_HERE", # Add your polygon API key here
Copy link
Contributor

Choose a reason for hiding this comment

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

category Security Severity Major

Security issue identified: The Polygon API key is hardcoded directly in the code as 'YOUR_POLYGON_API_KEY_HERE'. Hardcoding sensitive information like API keys is a security risk. If an attacker gains access to the codebase, they could extract the API key. To resolve this, remove the API key from the code and instead read it from an environment variable or a separate configuration file that is not committed to version control.

@@ -189,7 +196,7 @@ def get_price_data_from_polygon(

return df_all

def validate_cache(force_cache_update: bool, asset: Asset, cache_file: Path, api_key: str, paid: bool):
def validate_cache(force_cache_update: bool, asset: Asset, cache_file: Path, api_key: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

category Objects and Data Structures Severity Major

The 'validate_cache' function has been updated to remove the 'paid' parameter, but the function body still references a 'paid' variable. To avoid potential runtime errors, please update the function to work correctly without this parameter.

@@ -1,6 +1,6 @@
import datetime
import logging
import warnings
from termcolor import colored
from asyncio.log import logger
Copy link
Contributor

Choose a reason for hiding this comment

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

category Readability and Maintainability

The import 'from asyncio.log import logger' appears to be unused and should be removed to clean up the code.

@@ -773,7 +773,7 @@ def run_backtest(
sell_trading_fees=[],
api_key=None,
polygon_api_key=None,
polygon_has_paid_subscription=False,
polygon_has_paid_subscription=None, # Depricated, this is now automatic. Remove in future versions.
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

There is a spelling mistake in the comment next to the polygon_has_paid_subscription parameter. It should be corrected from 'Depricated' to 'Deprecated' to maintain professionalism in the codebase.

Comment on lines +168 to +171
colored_message = colored(
"Polygon rate limit reached. Sleeping for 1 minute 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",
)
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

The log message includes an affiliate link and a coupon code, which may not be suitable for logging purposes. Please remove these to keep the logs neutral and focused on operational information.

"Polygon rate limit reached. Sleeping for 1 minute 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",
)
logging.error(colored_message)
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

The current log message is unstructured. Please use structured logging with key-value pairs to improve log analysis capabilities.

@@ -951,6 +948,17 @@ def run_backtest(
if stats_file is None:
stats_file = f"{logdir}/{basename}_stats.csv"

# Check if polygon_has_paid_subscription is set (it is deprecated and will be removed in the future)
if polygon_has_paid_subscription is not None:
colored_warning = colored("The parameter `polygon_has_paid_subscription` is deprecated and will be removed in the future. "
Copy link
Contributor

Choose a reason for hiding this comment

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

category Tests

The use of termcolor for logging a deprecation warning within the run_backtest method may not be captured in certain test environments. Consider replacing it with standard logging practices to ensure that the deprecation warning can be captured and asserted in tests.

@@ -1,6 +1,6 @@
import datetime
import logging
import warnings
from termcolor import colored
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

The use of 'termcolor' for coloring log messages is not recommended as it may cause compatibility issues across different environments. Consider using a logging configuration that supports colored output in a more controlled way, such as 'colorlog' or custom log formatters.



def _get(self, *args, **kwargs):
logging.info(
f"\nSleeping {PolygonClient.WAIT_SECONDS} seconds while getting data from Polygon "
"to avoid hitting the rate limit; "
"consider a paid Polygon subscription for faster results.\n"
"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.\n"
)
time.sleep(PolygonClient.WAIT_SECONDS)
Copy link
Contributor

Choose a reason for hiding this comment

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

category Tests

The hardcoded sleep calls to avoid hitting the Polygon API rate limit can hinder automated testing by making it slow. Consider refactoring to allow for dependency injection of the PolygonClient, enabling you to mock out the actual API calls during testing for faster execution.

force_cache_update = validate_cache(force_cache_update, asset, cache_file, api_key, has_paid_subscription)

force_cache_update = validate_cache(force_cache_update, asset, cache_file, api_key)
df_all = None
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 'df_all' could be more descriptive to better indicate its purpose. Consider renaming it to 'combined_price_data' to clarify that it holds the combined data from cache and Polygon.

@@ -123,7 +120,7 @@ def get_price_data_from_polygon(
# Check if we need to get more data
missing_dates = get_missing_dates(df_all, asset, start, end)
if not missing_dates:
# TODO: Do this upstream so we don't called repeatedly for known-to-be-missing bars.
# TODO: Do this upstream so we don't repeatedly call for known-to-be-missing bars.
Copy link
Contributor

Choose a reason for hiding this comment

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

category Documentation

The TODO comment in the get_price_data_from_polygon function is vague. Please clarify what action should be taken upstream and why it's necessary to avoid repeated calls for known-to-be-missing bars.

@@ -5,7 +5,7 @@

setuptools.setup(
name="lumibot",
version="3.5.8",
version="3.5.9",
Copy link
Contributor

Choose a reason for hiding this comment

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

category Systems and Environment

I noticed that the version number of the package has been incremented in the setup.py file. However, there is no information in the pull request summary about what changes have been made that justify this version increment. Could you please update the pull request summary to include this information? This will help to ensure that the versioning of the package is managed properly.

@grzesir grzesir merged commit 0b66802 into dev Jun 30, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant