polyrec: Engineering the 15-Minute Arbitrage
How a multi-threaded Python dashboard uses a Node.js sidecar to bring high-frequency quantitative trading to Polymarket’s short-term prediction markets.
- Retail traders are weaponizing institutional tactics against the micro-structure of 15-minute prediction markets.
- The dashboard synchronizes three disparate data clocks (Binance, Polymarket, Chainlink) using a lock-free queue to prevent disk I/O from throttling ingestion.
- A pragmatic Node.js sidecar bypasses Python's Web3 limitations to secure reliable real-time Oracle data.
- Beneath the terminal UI lies a machine-learning pipeline that captures over 70 derived features per tick for predictive modeling.
The Micro-Structure Knife Fight
Polymarket's 15-minute BTC UP/DOWN contracts are a brutal arena. Traders are not simply betting on the price of Bitcoin. They are betting on the microscopic lag between Binance spot prices, the Chainlink decentralized oracle, and the Polymarket central limit order book (CLOB).
In these short-duration markets, standard crypto exchange libraries fail. The final 30 seconds are pure chaos. If your data ingestion stutters while writing to disk, you lose the opportunity. This adversarial environment is exactly what polyrec was built to exploit.
Syncing the Asynchronous
The core technical achievement of the project lives in dash.py. The script acts as a state machine using Python's threading and dataclasses to manage three completely separate data streams.
It ingests Binance 1-second Klines, erratic Polymarket depth updates, and discrete Chainlink feed drops. It funnels them all into a single, lock-free queue. A dedicated worker thread then handles the disk I/O, ensuring that massive volatility spikes never throttle the real-time ingestion rate.
The Node.js Sidecar
The most surprising architectural choice in the repository is how it handles Web3 data. Rather than wrestling with Python's Web3 libraries to read the Chainlink Real-Time Data Service, polyrec launches a Node.js subprocess.
This pragmatic hack bridges two ecosystems. It allows the creator to use Python for heavy numerical processing and dashboard rendering while relying on native JavaScript implementations for reliable decentralized oracle connections.
The dashboard uses an external Node.js script for Chainlink oracle data. Make sure you have the Chainlink feed script available.
A Logger in Dashboard Clothing
The terminal user interface is visually striking, but it is ultimately a disguise. The true power of the system lies in the DataLogger class.
It calculates over 70 derived features on the fly. Metrics like 30-second relative volume and orderbook eat-flow are computed continuously. Every 15 minutes, the system rotates a massive CSV file, generating machine-learning-ready datasets for predictive modeling without any manual intervention.
Fading the Favorite
Observation is only half the battle. The project includes specialized simulation scripts like fade_impulse_backtest.py to move from data collection to execution.
This script simulates taking the contrarian position when momentum spikes. It accounts for the strict 2-second order expiration rules of the Polymarket CLOB, providing a far more realistic assessment of viability than generic backtesting tools.
| Feature | polyrec | Generic Frameworks (CCXT/Backtrader) |
|---|---|---|
| Target Environment | 15-Min Prediction Markets | Standard CEX/DEX Spot Markets |
| Oracle Integration | Native Node.js sidecar | Requires custom Web3 implementation |
| Derived Features | 70+ PM-specific metrics (eat-flow, microprice) | Generic OHLCV standard indicators |
| Execution Simulation | Polymarket CLOB latency-aware (2s expiry rules) | Standard fill-or-kill assumptions |
By combining specialized data acquisition, high-dimensional feature engineering, and latency-aware simulation, the repository provides a rare glimpse into the tooling required to survive on the bleeding edge of gamified crypto markets.