Liquidation Hunting: How AI Agents Trade Market Cascades
In perpetual futures markets, liquidations are not random events. They cluster, they cascade, and they create some of the most predictable short-term price moves available in crypto trading. This guide teaches you how to build an AI agent that streams liquidation events in real time, scores cascade probability, and enters positions sized appropriately for the expected move.
What is a liquidation cascade?
Perpetual futures allow traders to use leverage โ a trader with $1,000 can open a $10,000 position at 10x leverage. When price moves 10% against them, their entire collateral is consumed and the exchange's liquidation engine forcibly closes their position at market price.
This forced close is itself a large market order. On BTC-PERP, a $5 million liquidated long is a $5 million market sell order hitting the order book immediately. If there are other leveraged longs clustered at nearby prices โ as there often are, because many traders use round numbers and similar technical levels for their entries โ the forced sell from the first liquidation drops price to the next cluster, triggering more liquidations, which drops price further. The cascade is self-reinforcing.
The cascade continues until one of two things happens: leveraged positions are exhausted at that price level, or a large buyer steps in and absorbs the selling. The end of a cascade is typically a sharp V-shaped bounce as the directional selling evaporates and the order book recovers.
How cascades create predictable price moves
Liquidation cascades are more predictable than most price moves for a structural reason: they are driven by mechanical forced selling, not by information. A trader selling because they know bad news is coming is adapting to information โ very hard to predict. A liquidation engine selling because a position's margin is exhausted is following a deterministic rule โ much easier to model.
The key inputs to cascade prediction are:
- Current liquidation volume in a rolling window: If $50M in longs have been liquidated in the last 90 seconds, momentum is strong.
- Open interest distribution: How many more longs are clustered just below current price? Purple Flea's liquidation heatmap API reveals this.
- Cascade score: A 0โ10 proprietary score combining speed of liquidations, size, and proximity to next liquidation cluster.
- Funding rate: High positive funding before the cascade means the market was overcrowded with longs โ more fuel for the fire.
Important edge: Most retail traders see the big candle on their chart and react after the fact. An agent streaming liquidation events reacts within milliseconds of the first large liquidation โ before the cascade has developed fully.
Streaming liquidation events with Purple Flea
Purple Flea's liquidation API streams every forced close across 275 perpetual markets in real time. The stream is filterable by minimum size, market, and side. Here is a complete async stream handler that logs events and builds a rolling window to detect developing cascades:
import asyncio
from collections import deque
import time
liq = purpleflea.LiquidationClient(api_key="YOUR_KEY")
trader = purpleflea.TradingClient(api_key="YOUR_KEY")
# Rolling 90-second window of liquidations per market
windows: dict[str, deque] = {}
WINDOW_SECS = 90
CASCADE_THRESHOLD_USD = 5_000_000 # $5M in window = cascade signal
async def handle(event):
mkt = event['market']
now = time.time()
if mkt not in windows:
windows[mkt] = deque()
w = windows[mkt]
w.append({'t': now, 'usd': event['size_usd'], 'side': event['side']})
# Prune events outside window
while w and now - w[0]['t'] > WINDOW_SECS:
w.popleft()
# Sum long vs short liquidations in window
long_liq = sum(e['usd'] for e in w if e['side']=='long')
if long_liq > CASCADE_THRESHOLD_USD:
print(f"CASCADE DETECTED {mkt}: ${long_liq/1e6:.1f}M longs liquidated in 90s")
await trader.place_order(market=mkt, side="sell", size=0.1, type="market")
async def main():
async with liq.stream(min_usd=50_000) as stream:
async for event in stream:
await handle(event)
asyncio.run(main())
Filtering for high-probability setups
Not every large liquidation is worth trading. Many single liquidations are isolated โ a poorly risk-managed position getting blown out with no follow-through. The setups with the highest win rate share several characteristics:
- Volume clustering: Multiple liquidations within a short window (60โ120 seconds) are stronger than a single large one. Clustering suggests multiple traders were stopped out at the same level, indicating a genuine structural break.
- High cascade score: Purple Flea's cascade score (0โ10) factors in the density of remaining leveraged positions just beyond the current cascade price. A score of 7+ means the cascade has significant fuel remaining.
- Elevated funding rate: A cascade that begins with high positive funding has more long inventory to burn through. More fuel = longer cascade = more profit potential.
- Low support levels nearby: Check the liquidation heatmap. If there is no large support cluster between current price and the next 3% lower, the cascade can travel further.
Combining these filters typically narrows the signal from dozens of liquidation events per day to 3โ8 genuinely high-probability cascade trades. Quality over quantity is the correct posture for this strategy.
Entry and exit mechanics
Entry timing matters. The ideal entry is 5โ15 seconds after the first large liquidation event fires, once it is clear that follow-on liquidations are occurring. Entering too early risks catching a single isolated liquidation. Entering too late means much of the move has already occurred.
# Position size: scale with cascade score and volume
confidence = cascade_score / 10 # 0.0 - 1.0
vol_factor = min(liq_vol_usd / 10_000_000, 2.0) # cap at 2x for $20M+
adj_size = round(size * confidence * vol_factor, 4)
if adj_size < 0.001:
return # too small, skip
# Enter cascade trade
entry = await trader.place_order(market=market, side=side,
size=adj_size, type="market")
entry_price = entry['avg_price']
print(f"ENTERED {side} {adj_size} {market} @ ${entry_price:,.2f}")
# Set stop-loss: 0.8% against entry, take-profit: 2% with entry
flip = 1 if side == "sell" else -1
stop_price = entry_price * (1 + flip * 0.008)
tp_price = entry_price * (1 - flip * 0.02)
await trader.set_stop_loss(market=market, trigger=stop_price)
await trader.set_take_profit(market=market, trigger=tp_price)
print(f" SL: ${stop_price:,.2f} | TP: ${tp_price:,.2f} | R:R 1:2.5")
Risk management
Cascade trading has a structural weakness: cascades can reverse violently. Once the fuel (leveraged positions to liquidate) is exhausted, the cascade ends โ often with a sharp snap-back as sellers are absorbed and the market bounces. An agent that stays in a cascade trade too long will give back all its profits on the reversal.
Warning: The most dangerous moment in cascade trading is right after the cascade appears to be slowing. This is when reversal risk is highest. Do not add to positions late in a cascade. Cut before the reversal, not after.
The core risk rules for cascade trading:
- Hard stop: Always enter with a stop-loss. A cascade that reverses on you is a fast loss. 0.8โ1.5% stop depending on market volatility.
- Liquidation volume monitoring: Track rolling liquidation volume. When it drops more than 60% from peak, begin exiting โ the cascade is exhausting.
- Maximum hold time: Cascade trades should resolve quickly. If you are still in a cascade trade after 10 minutes with no significant move, exit. The setup failed.
- Maximum daily trades: Limit cascade trades to 5โ8 per day per market. Beyond that, you are likely chasing noise rather than genuine cascade signals.
- No averaging into losses: A cascade that reverses against you is not "getting cheaper" โ it means the thesis was wrong. Never add to a losing cascade position.
Conclusion
Liquidation cascade trading is one of the few strategies in crypto where the price move is mechanically driven rather than information-driven. By streaming liquidation events in real time, building rolling window accumulators, applying quality filters, and enforcing strict risk management, an AI agent can systematically profit from these moves while avoiding the dangerous reversal risk that burns most amateur cascade traders.
The Purple Flea liquidation API provides everything needed โ streaming events, cascade scores, heatmap data, and trading execution โ in a single integrated platform. Start with small sizes, measure your win rate per cascade score tier, and scale the parameters that perform best for your target markets.