tda-api: Add rate limiter to ensure 120 API calls per minute limit is not exceeded.

Is your feature request related to a problem? Please describe. Per the TDAmeritrade documentation: All private, non-commercial use apps are currently limited to 120 requests per minute on all APIs except for Accounts & Trading https://developer.tdameritrade.com/content/getting-started

Due to the non-deterministic and asynchronous nature of the TDAmeritrade https API, hitting this limit can happen at unexpected times and I believe that many tda-api users will occasionally run into this rate limit. If those users haven’t coded their python script properly for this scenario, bad things might happen.

Describe the solution you’d like Implement a rate limiter. Something that is fast and precise. Make sure api users are able to turn off the rate limiter if they need too. One discord user recommended implementing the solution using a token bucket rate limiter, as I am not a computer scientist, I am not 100% sure that would be the right solution. https://en.wikipedia.org/wiki/Token_bucket

To be clear, below are the features that would ideally be in the solutions:

  • A way to enable/disable the rate limiter
  • Only rate limit API endpoints where a rate limit is enforced by TDAmeritrade. Meaning… don’t rate limit ‘Accounts & Trading’ API endpoints. If this cannot be safely implemented, then rate limit everything.

Describe alternatives you’ve considered Users can implement their own rate limiter. The easiest but terribly inefficient way to do this is with time.sleep(0.5).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (18 by maintainers)

Most upvoted comments

@nicmcd a rejection status.

Have you been able to trigger a problem with TDA yet? Yes. TDA was rate limiting me every once in a while when I was first working on my app. But, now that I am using my APP to screen a couple hundred stocks, I am running into the rate limit all of the time now.