Class OrderThrottle
java.lang.Object
com.quantfinlib.trading.OrderThrottle
Order-rate throttle: a nanosecond token bucket for exchange message-rate
limits (every real venue enforces one; exceeding it earns disconnects or
fines, so the gateway must self-limit). Sustained rate
ratePerSec
with bursts up to burst — a quiet spell banks up to one burst of
headroom, then the bucket refills continuously.
Single-writer (call from the order-entry thread), zero allocation,
no clock reads of its own — the caller passes System.nanoTime()
so tests are deterministic and the hot path controls its syscalls.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongPermits granted so far.longnanosUntilAvailable(long nowNanos) Nanoseconds until a permit would be available (0 when one already is) — for pacing loops that would rather sleep than spin-fail.longDenials so far — a persistent nonzero rate means the strategy outruns the venue limit.booleantryAcquire(long nowNanos) Attempts to take one send permit atnowNanos.
-
Constructor Details
-
OrderThrottle
public OrderThrottle(double ratePerSec, int burst) - Parameters:
ratePerSec- sustained messages per second (> 0)burst- bucket depth: messages allowed back-to-back (≥ 1)
-
-
Method Details
-
tryAcquire
public boolean tryAcquire(long nowNanos) Attempts to take one send permit atnowNanos. False = do not send (queue or drop per your policy — this class only counts). -
nanosUntilAvailable
public long nanosUntilAvailable(long nowNanos) Nanoseconds until a permit would be available (0 when one already is) — for pacing loops that would rather sleep than spin-fail. -
acquiredCount
public long acquiredCount()Permits granted so far. -
throttledCount
public long throttledCount()Denials so far — a persistent nonzero rate means the strategy outruns the venue limit.
-