DEV Community

Cover image for HFT-Lite: Prediction market arbitrage engine
Erich
Erich

Posted on

HFT-Lite: Prediction market arbitrage engine

How it works

The system connects to Kalshi and Interactive Brokers ForecastEx via WebSockets. Events are mapped to a unified symbol config tracking equivalent contracts across platforms. Market data is normalized into a central order book where an arbitrage detector continuously scans for cross-venue mispricings.

When complementary contracts (YES on one exchange, NO on the other) can be purchased for less than the guaranteed $1.00 settlement minus fees, both trades execute. The outcome doesn't matter, one side always pays.

Current scope: political and economic events (Fed decisions, presidential nominations, Senate majority control, House majority control).

Results

Pure arbitrage opportunities showed up immediately. In 35 minutes of monitoring:

Event Kalshi IBKR Combined Net Margin
SENATE_2026_REP YES @ $0.68 NO @ $0.26 $0.94 2.62%
HOUSE_2026_REP YES @ $0.27 NO @ $0.69 $0.96 0.62%
SENATE_2026_DEM NO @ $0.68 YES @ $0.28 $0.96 0.49%

The catch: these contracts settle February 1, 2027. That's 414 days of capital lock-up for 1-3% return. Treasury bills pay better.

Risks

Leg risk is the main concern. If one side fills and the other doesn't, the system rolls back by buying the opposite side on the filled exchange. Loss is limited to fees, but it's still a loss.

Regulatory uncertainty hangs over the entire space. Prediction markets occupy gray legal territory. Platforms could face restrictions that impact liquidity or access. That means holding cash and positions on an exchange that suddenly has problems.

What's next

The current margins only make sense with shorter-term contracts. Weekly or daily events reduce capital lock-up and make 1-3% spreads worthwhile.

The next evolution of this system is comparing options-implied probabilities to prediction market prices. If SPY options imply a 30% probability of closing between $595 and $600, and Kalshi has that bracket at 15 cents, someone's wrong. Retail prediction markets are probably the soft target.

Other improvements need to be made as well. On the execution side, parallel order placement and Kelly criterion position sizing. On infrastructure, WebSocket reconnection handling and a real-time dashboard. Risk management needs category exposure limits and correlation tracking. Holding ten different contracts with the same outcome isn't diversification.

Check out the project at the link below.


GitHub

Top comments (0)