-
Notifications
You must be signed in to change notification settings - Fork 214
Rate limiting #203
Description
As far as I can tell, this doesn't do any rate limiting so you'll get responses such as:
Exception: HTTP status code 403 {"errorCode":"error.public-api.exceeded-api-key-allowance"}
Info about rate limits here: https://labs.ig.com/faq#limits
We could use the ratelimit package do do this:
from ratelimit import limits, sleep_and_retry
And then decorate the appropriate function(s) such as the _req() function:
@sleep_and_retry
@limits(calls=30, period=60)
def _req():
...
There are however two different rate limits: One for trading requests e.g. placing orders, opening positions. And another for non-trading requests such as getting historical data.
We could have two functions e.g. _req_trade() and _req_non_trade() and these simply both call _req() but can have their own decorators to use the appropriate limits. Or perhaps it might be easier for _req() to be given the rate limit decorator and assume it's for non-trade calls which makes up the bulk of the functions, and add a _req_trade() and update the trade functions to call that.