The rate limiter of one connection (one app key): a RateLimitBucket on the steady clock, plus counters.
More...
#include <algotradelib/src/network/rate_limit.hpp>
The rate limiter of one connection (one app key): a RateLimitBucket on the steady clock, plus counters.
Not synchronized: use it only from the owning client's strand (see AsyncHttpClient::rate_limits).
Definition at line 397 of file rate_limit.hpp.
◆ Duration
◆ RateLimitController()
| algotradelib::network::RateLimitController::RateLimitController |
( |
RateLimitBudget | budget = {} | ) |
|
|
inlineexplicit |
Constructs a controller.
- Parameters
-
- Exceptions
-
| std::invalid_argument | if its burst or rate is below 1. |
Definition at line 407 of file rate_limit.hpp.
◆ acquire()
| bool algotradelib::network::RateLimitController::acquire |
( |
RateLimitGroup | group | ) |
|
|
inline |
Admits one request of a class if it may go now, and counts it.
- Parameters
-
- Returns
- true if admitted; false if it must wait, with nothing changed.
Definition at line 427 of file rate_limit.hpp.
◆ budget()
| const RateLimitBudget & algotradelib::network::RateLimitController::budget |
( |
| ) |
const |
|
inlinenoexcept |
◆ delay_until()
Returns how long a request of a class must wait.
- Parameters
-
- Returns
- The wait, zero if it may go now.
Definition at line 418 of file rate_limit.hpp.
◆ hold()
| void algotradelib::network::RateLimitController::hold |
( |
Duration | duration | ) |
|
|
inline |
Counts a broker refusal and holds every request for a duration, keeping the budget.
For a refusal this client's pacing could not have prevented (capacity shared with other customers). The refusal is counted in RateLimitStats::broker_rejections_, not per class.
- Parameters
-
Definition at line 462 of file rate_limit.hpp.
◆ record_delay()
Records that a request waited before admission.
- Parameters
-
| group | The class. |
| waited | How long. |
Definition at line 442 of file rate_limit.hpp.
◆ record_shed()
| void algotradelib::network::RateLimitController::record_shed |
( |
RateLimitGroup | group | ) |
|
|
inline |
Records that a request was refused unsent.
- Parameters
-
Definition at line 452 of file rate_limit.hpp.
◆ shrink()
| void algotradelib::network::RateLimitController::shrink |
( |
int | burst, |
|
|
int | per_second, |
|
|
Duration | retry ) |
|
inline |
Counts a broker refusal, adopts the burst and rate the broker reported, and holds.
The trading reserve is reduced if it would not be smaller than the new burst.
- Parameters
-
| burst | The broker's burst. |
| per_second | The broker's rate. |
| retry | How long to hold; zero or less holds for one interval. |
- Exceptions
-
| std::invalid_argument | if burst or per_second is below 1. |
Definition at line 477 of file rate_limit.hpp.
◆ stats()
| const RateLimitStats & algotradelib::network::RateLimitController::stats |
( |
| ) |
const |
|
inlinenoexcept |
Returns the counters.
- Returns
- The statistics.
Definition at line 494 of file rate_limit.hpp.
The documentation for this class was generated from the following file: