Skip to content

Instantly share code, notes, and snippets.

@Canx
Last active May 18, 2024 08:34
Show Gist options
  • Save Canx/2f8987a6686fce919e5cdea10a8bdd9a to your computer and use it in GitHub Desktop.
Save Canx/2f8987a6686fce919e5cdea10a8bdd9a to your computer and use it in GitHub Desktop.
class RLRESTClient(RESTClient):
''' Rate Limited RESTClient '''
def __init__(self, *args, **kwargs):
self.paid = kwargs.pop('paid', True)
self.seconds = 60
super().__init__(*args, **kwargs)
def _get(self, *args, **kwargs):
if not self.paid:
print(
f"\nSleeping {self.seconds} seconds while getting data from Polygon because "
f"we don't want to hit the rate limit. IT IS NORMAL FOR THIS TEXT TO SHOW UP SEVERAL TIMES "
"and IT MAY TAKE UP TO 10 MINUTES PER ASSET while we download all the data from Polygon. The next "
"time you run this it should be faster because the data will be cached to your machine. \n"
"If you want this to go faster, you can get a paid Polygon subscription at https://polygon.io/pricing "
f"and set `polygon_has_paid_subscription=True` when starting the backtest.\n"
)
time.sleep(self.seconds)
return super()._get(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment