Skip to main content
The quote-worker keeps the Redis quote cache fresh for any (oracleId, strike) the UI has marked hot (someone subscribed via WS or hit /v1/quotes/… in the last HOT_TTL_S, default 60s).

Loop

for each hot (oracle, strike):
  devInspect predict::get_trade_amounts(oracle, strike, isUp=true)
  devInspect predict::get_trade_amounts(oracle, strike, isUp=false)
  if (new !== cached):
    SET  quote:<oracle>:<strike>   { yes_ask, no_ask, fairPerToken, asOf }
    PUBLISH quotes:v1:<oracle>:<strike>  { …payload }
  sleep(QUOTE_POLL_MS)              # default 2000ms
The diff check avoids spamming the WS channel with identical updates.

Hot set maintenance

  • WS sub → mark (oracle, strike) hot, set HOT_TTL_S expiry.
  • WS unsub → leave the TTL to expire; rapid re-sub avoids a re-quote round-trip.
  • REST GET /v1/quotes/:oracle/:strike cache miss → mark hot + immediate inline quote.
Non-hot strikes are quoted on demand by the api process when the cache misses.

File

packages/server/src/workers/quote-poller.ts.

Tuning

Env varDefaultEffect
QUOTE_POLL_MS2000Poll interval per hot strike
HOT_TTL_S60Strike stays hot for this many seconds after last subscriber
QUOTE_CACHE_TTL_S300How long a cached quote is served stale before forcing a re-quote
Higher polling rate → lower client-perceived latency but more RPC pressure. The 2s default is a good balance for a hackathon demo.