Class OrderThrottle

java.lang.Object
com.quantfinlib.trading.OrderThrottle

public final class OrderThrottle extends Object
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
    Constructor
    Description
    OrderThrottle(double ratePerSec, int burst)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Permits granted so far.
    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.
    long
    Denials so far — a persistent nonzero rate means the strategy outruns the venue limit.
    boolean
    tryAcquire(long nowNanos)
    Attempts to take one send permit at nowNanos.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 at nowNanos. 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.