Pre-Trade Risk Gate in Python: Hysteresis, EWMA Spikes and Taker-Sweep Detection
The author presents a pre-trade risk gate that checks market microstructure before each order and returns an allow or block decision with reasons. The gate closes on four triggers: recent large taker sweeps, a VPIN reading in its top decile, an unusually lopsided order book relative to the pair's own history, and a sudden shift in the book's imbalance against its moving average. It uses hysteresis, reopening only after a cooldown and a lower VPIN re-arm level, and fails closed whenever a fresh snapshot cannot be obtained. Measurements show that reusing an HTTPS session cut median check latency from about 160 ms to 59 ms, and a one-second cache avoids redundant requests. The article also notes that REST-based gating cannot react fast enough to beat the first fill after a sweep, which would require a streaming feed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in