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.

7 min read • View on GitHub • More from txbabaxyz

A shattered pocket watch revealing overlapping ticker tapes instead of gears, representing the collision of multiple asynchronous data streams in high-frequency trading.
In the final 30 seconds of a Polymarket contract, milliseconds of latency dictate profitability.
Key Takeaways

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 Three-Clock Engine synchronizes asynchronous data streams into a single state without dropping packets.

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.

A heavy steam locomotive moving on tracks with a sleek, modern motorcycle sidecar bolted to its side, symbolizing the Python and Node.js architectural hack.
A cross-language bridge prioritizes data integrity over architectural purity.

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.

txbabaxyz, Project Creator · txbabaxyz/polyrec Repository README

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.

A balance scale tipping drastically to one side under heavy iron weights, while a mechanical hand places a single feather on the elevated, lighter side.
The Fade Impulse strategy involves taking the contrarian, cheaper bet when market momentum spikes.

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.

FeaturepolyrecGeneric Frameworks (CCXT/Backtrader)
Target Environment15-Min Prediction MarketsStandard CEX/DEX Spot Markets
Oracle IntegrationNative Node.js sidecarRequires custom Web3 implementation
Derived Features70+ PM-specific metrics (eat-flow, microprice)Generic OHLCV standard indicators
Execution SimulationPolymarket 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.