Skip to content

Conversation

@IOITI
Copy link

@IOITI IOITI commented Apr 22, 2025

Hi !

Thanks for your API Handler ! I'm using it in my project WATA !

This PR adds a RateLimiter class to properly handle Saxo Bank's API rate limits. The implementation respects both the session rate limits reported in response headers and implements a smart waiting mechanism to avoid hitting rate limits.

Changes:

  • Added a new RateLimiter class that tracks remaining request quota and reset times
  • Integrated the rate limiter into the API request flow to:
    • Check remaining limits before making requests
    • Wait automatically when approaching limits
    • Add extra delay when request quota is running low
    • Update limits based on response headers after each request
  • Improved handling of 429 (Too Many Requests) responses with proper backoff

Benefits:

  • Prevents API lockouts due to excessive request rates
  • Automatically adapts to the current rate limit state
  • Adds progressive throttling as limits are approached
  • Makes the client more resilient in high-request scenarios

Implementation details:

  • The rate limiter uses a thread-safe approach with locks
  • Default values are used when headers aren't available
  • Configurable threshold for when to start adding delays
  • Detailed logging of rate limit states and wait times

This should help users of your library, in order to avoid hitting rate limits when making multiple API calls in quick succession, especially in automated trading scenarios :)

@hootnot
Copy link
Owner

hootnot commented Apr 23, 2025

Hi,
Thx, I'll have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants