The Handler supports throttling, a mechanism to control the number of requests sent to Eurex. The implementation of throttling is based on the Sliding Window algorithm.
The throttling works as follows:
The Sliding Window algorithm is used to keep track of the number of requests sent to Eurex. The algorithm works as follows:
\[ T_w = T_i - (T_c - S_{fr}) \]
Where,Eurex provides information related to the throttling in the following messages:
When the Handler receives any of these messages it updates its internal settings to the new one according to the following fields:
The requests sent within the current ThrottleTimeInterval before an update, or before a reconnection, still count against the new limits. Requests sent while throttling is switched off are not counted. When an update lengthens the interval, requests older than the previous interval may not be counted.
Heartbeats are not counted either, as Eurex does not count them, and a heartbeat does not wait when the limit is reached. It still goes out only after a request that is already waiting for the limit.
The Handler keeps to a limit lower than the one set by Eurex: it subtracts HandlerSettings::throttleMessageMargin, 3 by default, from ThrottleNoMsgs. For example, when Eurex sets ThrottleNoMsgs to 50, the Handler sends at most 47 requests per ThrottleTimeInterval.
Eurex counts the requests by the time they enter the gateway, not by the time the Handler sends them: it rejects a request when the gateway has already received ThrottleNoMsgs requests within the ThrottleTimeInterval before it. Jitter on the network path can bunch requests that the Handler spaced out, so that more of them arrive within one interval than the Handler sent within any interval. The margin absorbs this. On a path with uneven latency, such as a VPN, a wide-area link or a loaded host, the default margin can be too small: Eurex then rejects requests with SessionRejectReason::ThrottleLimitExceeded although the Handler keeps to its limit. The Handler reports such a reject through AdminListener::onReject. After throttleDisconnectLimit consecutive rejects, as reported by SessionListener::onThrottleSettingsChanged, Eurex disconnects the session.
If this happens, raise the margin, for example to 10, and then lower it step by step for as long as no such rejects occur. The Handler takes the margin from the settings it is constructed with, so each new margin needs a new Handler. Keep the margin below the ThrottleNoMsgs set by Eurex.
If the first Session Logon Response a Handler receives sets a limit, other than 0, that does not exceed the margin, or sets a limit with a ThrottleTimeInterval that is not positive, the logon fails. Later limits never fail the session: if a later limit does not exceed the margin, the Handler allows one request per ThrottleTimeInterval. If a later ThrottleTimeInterval is not positive, the Handler keeps the current interval, or 1000 milliseconds if Eurex has not sent a valid one yet. In both cases the Handler logs a warning and reports it through WarningListener::onWarning with WarningCode::General.
The Handler provides the following callbacks related to the throttling:
When the Handler receives either Session Logon Response or Throttle Update Notification it calls SessionListener::onThrottleSettingsChanged.
When the Handler detects that the number of requests is higher than its limit it calls SessionListener::onThrottleDelayStarted and starts waiting. When waiting is finished, the Handler calls SessionListener::onThrottleDelayFinished and sends a blocked request.