Class HftOrderGateway

java.lang.Object
com.quantfinlib.trading.HftOrderGateway
All Implemented Interfaces:
AutoCloseable

public final class HftOrderGateway extends Object implements AutoCloseable
Ultra-low-latency order gateway — the fast lane from signal to venue. The hot path (submit(int, com.quantfinlib.orderbook.Side, long, double, long)) performs zero allocation, zero locking, zero map lookups: an inline HftRiskGate check over primitive arrays, then a release-store publish into a preallocated OrderRingBuffer. A dedicated venue thread (busy-spin optional) drains orders to the registered OrderListeners — the venue adapter (exchange session, simulator, ...) lives on that side.

Return convention of submit(int, com.quantfinlib.orderbook.Side, long, double, long): positive = accepted order id; negative = risk-rejected, with -returnValue the HftRiskGate reason code; 0 = ring full (backpressure — the caller chooses spin, drop, or kill-switch).

Single producer (the trading thread), single consumer (the venue thread) — the same threading model as HftMarketDataBus.

  • Constructor Details

    • HftOrderGateway

      public HftOrderGateway(int ringCapacity, HftRiskGate riskGate, boolean busySpin)
    • HftOrderGateway

      public HftOrderGateway(HftRiskGate riskGate)
      Parked venue thread, 8K ring.
  • Method Details

    • addOrderListener

      public void addOrderListener(OrderListener listener)
    • start

      public void start()
    • stop

      public void stop()
      Stops the venue thread after draining queued orders.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • submit

      public long submit(int symbolId, Side side, long quantity, double price, long timestampNanos)
      Risk-checks and submits one order. Zero allocation.
      Returns:
      positive order id if accepted; negative HftRiskGate reason code if rejected; 0 if the ring is full
    • riskGate

      public HftRiskGate riskGate()
    • submittedCount

      public long submittedCount()
    • deliveredCount

      public long deliveredCount()
      Orders handed to the venue thread so far.
    • ringFullCount

      public long ringFullCount()