Class HftRiskGate
PreTradeLimitChecker. All state
is primitive arrays indexed by dense symbol id; check(int, com.quantfinlib.orderbook.Side, long, double) performs no
allocation, no hashing and no string formatting, and returns an int reason
code. Rejection counts are kept per reason for observability.
Threading
The production wiring is inherently multi-threaded: check(int, com.quantfinlib.orderbook.Side, long, double) runs
on the trading/quoting thread (often the bus consumer), onFill(int, com.quantfinlib.orderbook.Side, long) on
the venue-ack thread, halt(int, boolean) from ops/dashboards, and
setReferencePrice(int, double) from the market-data thread. Cross-thread
element access therefore uses VarHandle acquire/release ordering:
on x86 an acquire load is a plain load and a release store a plain store,
so the ≈1 ns/check cost is unchanged (verified by re-running
HftOrderBenchmark after this change), while readers are guaranteed
fresh, untorn values — a plain long[] would let the JIT serve a
stale position to the quoter's skew and the position limit forever.
onFill uses an atomic add, so multiple fill sources are safe too.
Limit configuration remains setup-time single-threaded.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintValidates one order.voidhalt(int symbolId, boolean isHalted) Halts/unhalts a symbol — callable from any thread (ops, dashboards).booleanisKilled()Whether the gate-wide kill switch is currently engaged.voidkill(boolean isKilled) Gate-wide kill switch: every check rejects withREJECT_KILLEDuntil cleared.maxOrderNotional(double notional) maxOrderQuantity(long qty) maxPositionQuantity(long qty) voidApplies a fill to the position book — callable from the venue-ack thread (atomic add: concurrent fill sources cannot lose updates).longposition(int symbolId) Live position — readable from any thread (quoter skew, hedger, dashboards).priceCollarPct(double pct) Fat-finger guard versus the reference price (0.02 = 2%).static StringreasonName(int code) doublereferencePrice(int symbolId) The collar reference for a symbol (NaN = unset) — readable anywhere.longrejectionCount(int reasonCode) voidsetReferencePrice(int symbolId, double price) Updates the collar reference (e.g. from the market data bus).intSymbol capacity this gate was sized for (aggregators iterate to it).
-
Field Details
-
OK
public static final int OK- See Also:
-
REJECT_QUANTITY
public static final int REJECT_QUANTITY- See Also:
-
REJECT_NOTIONAL
public static final int REJECT_NOTIONAL- See Also:
-
REJECT_POSITION
public static final int REJECT_POSITION- See Also:
-
REJECT_PRICE_COLLAR
public static final int REJECT_PRICE_COLLAR- See Also:
-
REJECT_HALTED
public static final int REJECT_HALTED- See Also:
-
REJECT_KILLED
public static final int REJECT_KILLED- See Also:
-
-
Constructor Details
-
HftRiskGate
public HftRiskGate(int maxSymbols)
-
-
Method Details
-
maxOrderQuantity
-
maxOrderNotional
-
maxPositionQuantity
-
priceCollarPct
Fat-finger guard versus the reference price (0.02 = 2%). -
halt
public void halt(int symbolId, boolean isHalted) Halts/unhalts a symbol — callable from any thread (ops, dashboards). -
kill
public void kill(boolean isKilled) Gate-wide kill switch: every check rejects withREJECT_KILLEDuntil cleared. Callable from any thread — this is the lever a cross-shardGlobalRiskAggregatorpulls when firm-wide exposure breaches its cap. -
isKilled
public boolean isKilled()Whether the gate-wide kill switch is currently engaged. -
referencePrice
public double referencePrice(int symbolId) The collar reference for a symbol (NaN = unset) — readable anywhere. -
symbolCapacity
public int symbolCapacity()Symbol capacity this gate was sized for (aggregators iterate to it). -
setReferencePrice
public void setReferencePrice(int symbolId, double price) Updates the collar reference (e.g. from the market data bus). -
check
-
onFill
Applies a fill to the position book — callable from the venue-ack thread (atomic add: concurrent fill sources cannot lose updates). -
position
public long position(int symbolId) Live position — readable from any thread (quoter skew, hedger, dashboards). -
rejectionCount
public long rejectionCount(int reasonCode) -
reasonName
-