Mid-price and spread
| Symbol | Meaning | Units / range |
|---|---|---|
| \(bid\) | Best bid | 0..1 |
| \(ask\) | Best ask | 0..1 |
| \(mid\) | Mid-price | 0..1 |
| \(spread\) | Top-of-book spread | 0..1 |
← All stages · stage 4 of 11
Measure market state. Never decide whether to trade.
Strategies want features — imbalance, volatility, flow, completeness. If every strategy re-implements them, they disagree about "the market is volatile" and trade on different facts.
Computes a shared feature vector at every tick: spread, midpoint, imbalance, top-of-book depth, 5-level depth, buy/sell flow over rolling windows, realised volatility, freshness flags. Versioned and replayable.
Signals are observation, not opinion. They make every downstream stage read the same numbers.
Every formula below is implemented in packages/polytraders-bots/ or packages/polytraders-runner/. Treat the worked example as the unit-test sanity check you should be able to reproduce locally.
| Symbol | Meaning | Units / range |
|---|---|---|
| \(bid\) | Best bid | 0..1 |
| \(ask\) | Best ask | 0..1 |
| \(mid\) | Mid-price | 0..1 |
| \(spread\) | Top-of-book spread | 0..1 |
| Symbol | Meaning | Units / range |
|---|---|---|
| \(bid_size\) | Shares resting at best bid | shares |
| \(ask_size\) | Shares resting at best ask | shares |
Positive imbalance favours upward drift; negative favours downward. Strategies consume the value, never re-derive it.
| Symbol | Meaning | Units / range |
|---|---|---|
| \(mid_t\) | Mid-price at time t | 0..1 |
| \(\sigma\) | Standard deviation of one-tick log returns | unitless |
Reported per rolling window (60s, 5m, 1h). Stage 7 sizes positions inversely to \sigma.
| Symbol | Meaning | Units / range |
|---|---|---|
| \(w\) | Rolling window | 60s · 5m · 1h |
| \(aggressive\) | Trade that crossed the spread | boolean per fill |
| Symbol | Meaning | Units / range |
|---|---|---|
| \(features filled\) | Number of features whose inputs were fresh | |
| \(features expected\) | Total features in signal_version |
Reference TypeScript implementation lives in packages/polytraders-* at the repository root. Stage owners maintain these files — read them before writing new code.
packages/polytraders-bots/src/intelReference intel bots: bookimbalance, flowdetector, microvol. Each produces one feature into the shared vector.packages/polytraders-contracts/src/MarketSnapshot.tsThe features field — strict typing keeps every strategy reading the same names.packages/polytraders-bots/src/_helpers.jsReusable feature helpers (EMA, rolling windows, RMS).The platform mock is the source of truth for what each stage's UI exposes. Open these alongside the code references.
INTEL_*INTEL — ingest, freshness, signalsSTRAT_*STRAT — strategy, model, fair-valueHover or tap any reason code on this page (or anywhere on the site) to see its canonical short description. Full registry: /standards/reason-codes.