Predict near-term book depth and trade pacing per market for sizing decisions.
3. Why This Bot Matters
Strategies size on stale liquidity
Sizing decisions made from current top-of-book ignore that depth can collapse seconds before fill. A forecast — even a coarse one — gives strategies a concrete number to clamp size against before submitting an OrderIntent.
Execution router under-quotes its own fill probability
Without forward-looking depth, smartrouter can only react to the book it sees. With a forecast, it can prefer a passive ladder that is expected to refill, instead of crossing into thin liquidity that disappears mid-fill.
Risk caps lag the actual market
Static per-market notional caps assume yesterday's depth. A liquidity forecast lets Risk widen or tighten caps in line with predicted near-term depth, reducing both missed opportunities in deep books and oversize entries in thin ones.
Operators have no leading indicator before a liquidity collapse
When depth dries up before a known event (a debate, a game start), having no model means the team only sees the collapse on the chart after it happens. A forecast emits a warning the operator can act on.
4. Required Polymarket Inputs
Input
Source
Required?
Use
CLOB V2 order book snapshot (bids and asks) per condition_id
clob_public
Yes
Compute current bid/ask depth in pUSD for forecast baseline.
Historical fill rate for each condition_id
data
Yes
Weight forecast using observed fill rate to discount unfilled book depth.
5. Required Internal Inputs
Input
Source
Required?
Use
KillSwitch active flag
KillSwitch
Yes
Suppress all forecast emissions when KillSwitch is active.
6. Parameter Guide
Parameter
Default
Warning
Hard
What it controls
forecast_horizon_s
3600
7200
86400
Seconds ahead to forecast liquidity availability.
min_liquidity_pusd
1000
500
100
Minimum forecasted pUSD liquidity required to avoid a low-liquidity signal.
7. Detailed Parameter Instructions
forecast_horizon_s
What it means
Seconds ahead to forecast liquidity availability.
Default
{ "forecast_horizon_s": 3600 }
Why this default matters
3600 s (1 h) matches typical strategy hold horizon without requiring multi-day extrapolation.
Threshold logic
Condition
Action
horizon <= 3600 s
Normal
3600–7200 s
WARN — forecast uncertainty increases with horizon
> 86400 s
Reject — PARAMETER_CHANGE_REQUIRES_APPROVAL
Developer check
if (p.forecast_horizon_s > p.hard) throw ConfigError('PARAMETER_CHANGE_REQUIRES_APPROVAL');
User-facing English
Liquidity forecasts are computed for a configurable time horizon ahead.
min_liquidity_pusd
What it means
Minimum forecasted pUSD liquidity required to avoid a low-liquidity signal.
Default
{ "min_liquidity_pusd": 1000 }
Why this default matters
1000 pUSD ensures strategies have enough depth to enter and exit without significant slippage.
Strategy reduced size due to low-liquidity forecast
The model projects that available market depth will fall below the minimum threshold over the next hour. Position size was reduced to limit potential slippage.
Liquidity forecast indicates adequate depth
The market is projected to have sufficient depth over the strategy's hold horizon. No size adjustment was triggered.
18. Failure-Mode Block
main_failure_mode
CLOB API outage prevents fresh order book snapshots, causing LiquidityForecastModel to serve stale forecasts that may overstate available depth, leading strategies to size into low-liquidity markets.
false_positive_risk
Large spoof orders inflating apparent book depth cause the forecast to overestimate available liquidity and suppress low-forecast signals.
false_negative_risk
Rapid order withdrawal post-fill leaves the forecast below actual liquidity, causing unnecessary LIQUIDITYFORECAST_LOW_FORECAST signals on adequate markets.
safe_fallback
If CLOB API is unavailable for > staleness_threshold_s, emit STALE_DATA WARN and suspend new forecast emissions. Do not serve stale forecasts older than staleness_threshold_s to downstream consumers.
required_dependencies
Polymarket CLOB V2 public API, Polymarket Data API for fill rate, KillSwitch active flag, Redis for forecast state
19. Failure-Injection Recipes
Scenario
How to inject
Expected behaviour
Recovery
CLOB_API_DOWN
Block CLOB public API for 10 min
Automatic on API recovery; next poll cycle resumes normally
EMPTY_ORDER_BOOK
Return empty bids and asks for a test condition_id
Automatic when orders return to book
KILL_SWITCH_ON
Set killswitch.active=true during active forecasting
Automatic on KillSwitch reset
20. State & Persistence
Cold-start recovery
On cold start, re-compute on first poll cycle; no historical backfill required.
21. Concurrency & Idempotency
Aspect
Specification
Execution model
async per-market poll loop
Max in-flight
25
Idempotency key
condition_id + snapshot_ts_ms
Per-call timeout (ms)
10000
Backpressure strategy
drop-after-buffer — skip condition_ids that have not drained within 2x poll interval
Locking / mutual exclusion
Redis SETNX on condition_id + snapshot_ts to prevent duplicate computations
ObservationReport emitted with low_forecast=true, LIQUIDITYFORECAST_LOW_FORECAST WARN
KillSwitch suppresses emission
killswitch.active=true; forecast computed
No ObservationReport; KILL_SWITCH_ACTIVE logged
Integration Tests
Test
Expected result
Forecast consumed by LiquidityGuard for pre-trade risk check
LiquidityGuard receives forecast_pusd and horizon_s from ObservationReport
CLOB API down: STALE_DATA emitted; no new forecasts served
STALE_DATA WARN; downstream consumers receive no new forecast ObservationReports
Property Tests
Property
Required behaviour
LiquidityForecastModel never submits or signs orders
Always true
No ObservationReport emitted when KillSwitch is active
Always true
27. Operational Runbook
LiquidityForecastModel incidents are typically CLOB API outages. Low forecasts are signals, not errors. Extended outages will leave strategies without forward liquidity data.
On-call actions
Alert
First step
Diagnosis
Mitigation
Escalate to
LiquidityForecastModelLowForecast
Verify live order book depth on Polymarket.com for the affected market. If genuine, no action needed — downstream strategies will reduce size automatically.
Intelligence pod lead if multiple markets simultaneously below threshold
LiquidityForecastModelStale
Check CLOB API health and last_computed_at_ms for affected markets.
Intelligence pod lead if stale > 15 min
Manual overrides
force_recompute — POST /internal/liquidityforecastmodel/recompute?condition_id=<id> to trigger immediate recompute — After CLOB API recovery or suspected stale forecast
Healthcheck
Endpoint: /internal/health/liquidityforecastmodel | Green: Last forecast < 5 min ago AND Redis reachable AND CLOB API returning 200 | Red: No forecast for > 15 min OR Redis unreachable
28. Promotion Gates
A bot does not advance to the next readiness state until every gate below is green. Gates are observable from production data — no subjective sign-off.
Promote to Shadow
Gate
How measured
Threshold
Unit tests pass for low-forecast gate, empty book detection, and KillSwitch suppression
CI test run
100% pass
Promote to Limited live
Gate
How measured
Threshold
Forecast computation completes in < 5 s p99 over 24 h on staging
Integration test
p99 < 5 s
Promote to General live
Gate
How measured
Threshold
Zero missed forecasts during 14-day soak with live CLOB V2 API