guides

Odds alerts in Node: line moves across books and prices above fair from the WebSocket

By · Published · Updated · 6 min read

Odds alerts tell you when a price moves or when a price sits above its fair value. The Node script below does both from one PricedOdds WebSocket connection: it flags a selection that moves the same way at 3 or more books within 2 minutes, and a pre-match price at least 3% above the no-vig fair price. In a 180-second run on NBA, NHL and college basketball it read 5,717 price changes and raised 10 line-movement alerts and 26 EV alerts. It uses no packages.

What do I need to run odds alerts?

  • A PricedOdds API key on a plan with WebSocket access (All-Access, or the WebSocket add-on; see pricing).
  • Node 22 or later, which has WebSocket and fetch built in. We ran the script on Node 24.22.1 without installing anything.

How is this different from the Discord bot?

The Discord odds alert bot polls GET /v1/changes every 30 seconds and posts any single book that moves. This script listens on the WebSocket, so changes arrive as they happen; it waits until several books move the same selection before it raises a move; and it adds a second kind of alert, prices above the fair price. It prints to the terminal. To post to a channel, replace console.log in alert() with the webhook call from the Discord article.

How does the script work?

  1. It calls GET /v1/ev once per league with min_ev=0.03, to show what is already above the fair price before the stream starts.
  2. It opens wss://api.pricedodds.com/v1/stream, sends the key in an auth message and, on ready, subscribes to the leagues with moneyline, spread and total and include: ["fair"]. With that, each price frame carries the fair price of the selections it changes.
  3. The snapshot frames give the starting state: each game's name and status, each book's price and the fair probability of each selection.
  4. Line movement. For every change it turns american and prev_american into implied probability. A change of 1 point or more counts as a move at that book. When 3 different books have moved the same selection the same way within 120 seconds, it prints a MOVE line. "Shorter" means the price fell (the books now rate that side more likely); "longer" means it rose.
  5. EV. For a game that has not started, it computes EV = decimal odds × fair probability − 1, the same formula as GET /v1/ev (explained in expected value from odds data). A price between 0.03 and 0.15 prints an EV line. The upper cap is the default max_ev of GET /v1/ev, because a much higher value is usually a stale or wrong price.
  6. Each selection gets one move alert, and each selection at each book one EV alert, every 10 minutes; the rest are counted as muted.
  7. At the end it calls GET /v1/ev again and checks its own formula against the API on the prices it holds.

If the connection drops, it reconnects and sends resume with the last seq. It does not retry on close codes 4001, 4002 and 4003, which mean the key, the billing or the plan needs fixing.

What is the code?

// odds-alerts-ws.mjs: line-movement and +EV alerts from the PricedOdds WebSocket, checked against GET /v1/ev.
// No packages: fetch and WebSocket are built into Node 22 or later. Usage: PRICEDODDS_API_KEY=... node odds-alerts-ws.mjs
const KEY = process.env.PRICEDODDS_API_KEY;
const BASE = "https://api.pricedodds.com/v1";
const LEAGUES = (process.env.LEAGUES ?? "nba,nhl,ncaab").split(",");
const MARKETS = ["moneyline", "spread", "total"];
const MOVE_POINTS = Number(process.env.MOVE_POINTS ?? 1); // a move at one book, in points of implied probability
const MOVE_BOOKS = Number(process.env.MOVE_BOOKS ?? 3);   // books that must move the same selection the same way
const WINDOW_SECONDS = 120;                               // ... within this window
const MIN_EV = Number(process.env.MIN_EV ?? 0.03);        // EV alert: price at least 3% above the fair price
const MAX_EV = 0.15;                                      // same cap as GET /v1/ev: higher is usually a stale or wrong price
const COOLDOWN_MINUTES = 10;                              // one alert per selection (and book) in this time
const SECONDS = Number(process.env.SECONDS ?? 300);

const implied = (am) => (am > 0 ? 100 / (am + 100) : -am / (-am + 100));
const fmt = (am) => (am > 0 ? `+${am}` : `${am}`);
const events = new Map();     // event_id -> { name, status }
const selections = new Map(); // selection_id -> { event_id, label }
const price = new Map();      // `${selection_id}|${book}` -> decimal
const fair = new Map();       // selection_id -> fair probability
const moves = new Map();      // selection_id -> [{ book, at, dir, from, to }]
const lastAlert = new Map();
const n = { frames: 0, changes: 0, move: 0, ev: 0, muted: 0 };

function alert(key, text) {
  const now = Date.now();
  if (now - (lastAlert.get(key) ?? -Infinity) < COOLDOWN_MINUTES * 60000) return void n.muted++;
  lastAlert.set(key, now);
  console.log(text);
  return true;
}

function remember(eventId, m, s) {
  const line = s.line == null ? "" : ` ${s.line > 0 && m.market === "spread" ? "+" : ""}${s.line}`;
  selections.set(s.id ?? s.selection_id, { event_id: eventId, label: `${m.market}@${m.period} ${s.side}${line}` });
}

function onSnapshot(frame) {
  for (const { event, markets } of frame.data) {
    events.set(event.id, { name: `${event.away.abbr ?? event.away.name} @ ${event.home.abbr ?? event.home.name}`, status: event.status });
    for (const m of markets) for (const s of m.selections) {
      remember(event.id, m, s);
      if (s.fair?.prob) fair.set(s.id, s.fair.prob);
      for (const p of s.prices) if (p.decimal) price.set(`${s.id}|${p.book}`, p.decimal);
    }
  }
}

function onPrice(frame) {
  const { event_id, book, changes } = frame.data;
  n.frames++;
  for (const [id, f] of Object.entries(frame.data.fair ?? {})) f ? fair.set(id, f.prob) : fair.delete(id); // null: no fair price now
  const ev = events.get(event_id) ?? { name: event_id, status: "scheduled" };
  for (const c of changes) {
    n.changes++;
    if (!selections.has(c.selection_id)) remember(event_id, c, c);
    const what = `${ev.name} ${selections.get(c.selection_id).label}`;
    price.set(`${c.selection_id}|${book}`, c.decimal);
    if (c.american == null || c.prev_american == null) continue; // pulled or new price

    // 1. Line movement: the same selection moves the same way at several books within the window.
    const points = (implied(c.american) - implied(c.prev_american)) * 100;
    if (Math.abs(points) >= MOVE_POINTS) {
      const now = Date.now();
      const list = (moves.get(c.selection_id) ?? []).filter((x) => now - x.at < WINDOW_SECONDS * 1000 && x.book !== book);
      list.push({ book, at: now, dir: Math.sign(points), from: c.prev_american, to: c.american });
      moves.set(c.selection_id, list);
      const same = list.filter((x) => x.dir === Math.sign(points));
      if (same.length >= MOVE_BOOKS) {
        const secs = Math.round((now - Math.min(...same.map((x) => x.at))) / 1000);
        const way = points > 0 ? "shorter" : "longer";
        if (alert(`move|${c.selection_id}`, `MOVE ${frame.ts.slice(11, 19)} ${what}: ${same.length} books ${way} in ${secs}s (${same.map((x) => `${x.book} ${fmt(x.from)}->${fmt(x.to)}`).join(", ")})`)) n.move++;
      }
    }

    // 2. EV: a pre-match price above the fair price by MIN_EV or more.
    const prob = fair.get(c.selection_id);
    if (prob && c.decimal && ev.status === "scheduled") {
      const value = c.decimal * prob - 1;
      if (value >= MIN_EV && value <= MAX_EV)
        if (alert(`ev|${c.selection_id}|${book}`, `EV   ${frame.ts.slice(11, 19)} ${what}: ${book} ${fmt(c.american)}, fair ${(prob * 100).toFixed(1)}%, ev ${value.toFixed(4)}`)) n.ev++;
    }
  }
}

async function evRows() {
  const rows = [];
  for (const league of LEAGUES) {
    const r = await fetch(`${BASE}/ev?league=${league}&min_ev=${MIN_EV}&limit=200`, { headers: { Authorization: `Bearer ${KEY}` } });
    if (!r.ok) throw new Error(`GET /v1/ev ${league}: HTTP ${r.status}`);
    rows.push(...(await r.json()).data.map((x) => ({ ...x, league })));
  }
  return rows;
}

const start = await evRows();
const per = LEAGUES.map((l) => `${l} ${start.filter((x) => x.league === l).length}`).join(", ");
console.log(`start: GET /v1/ev returned ${start.length} prices at or above ${MIN_EV} (${per})`);

let lastSeq = 0, stopping = false, ws;
function connect(resumed = false) {
  ws = new WebSocket("wss://api.pricedodds.com/v1/stream");
  ws.addEventListener("open", () => ws.send(JSON.stringify({ type: "auth", key: KEY })));
  ws.addEventListener("message", (msg) => {
    const frame = JSON.parse(msg.data);
    if (frame.seq) lastSeq = Math.max(lastSeq, frame.seq);
    const filters = { leagues: LEAGUES, markets: MARKETS, include: ["fair"] };
    if (frame.type === "ready") ws.send(JSON.stringify(resumed ? { type: "resume", since_seq: lastSeq, ...filters } : { type: "subscribe", ...filters }));
    if (frame.type === "snapshot") onSnapshot(frame);
    if (frame.type === "price") onPrice(frame);
    if (frame.type === "event" && frame.data?.event_id && events.has(frame.data.event_id) && frame.data.status)
      events.get(frame.data.event_id).status = frame.data.status;
    if (frame.type === "error") console.error(frame);
  });
  ws.addEventListener("close", (e) => {
    if (stopping || [4001, 4002, 4003].includes(e.code)) return; // key, billing or plan: fix the account first
    setTimeout(() => connect(true), 2000);
  });
}
connect();

setTimeout(async () => {
  stopping = true;
  ws.close();
  console.log(`summary: ${n.frames} price frames, ${n.changes} price changes, ${n.move} move alerts, ${n.ev} EV alerts, ${n.muted} muted by the cooldown`);
  // Check: the EV of GET /v1/ev against the same formula on the prices the stream holds now.
  const end = (await evRows()).filter((r) => MARKETS.includes(r.market)); // /v1/ev also lists props and other periods
  const same = end.filter((r) => price.get(`${r.selection_id}|${r.book}`) === r.decimal && fair.has(r.selection_id));
  const match = same.filter((r) => Math.abs(r.decimal * fair.get(r.selection_id) - 1 - r.ev) < 0.0005);
  console.log(`check: GET /v1/ev returned ${end.length} moneyline, spread and total prices, ${same.length} had the same price in the stream; the formula gave the same ev (to 0.0005) for ${match.length}`);
}, SECONDS * 1000);

Run it with PRICEDODDS_API_KEY=$PRICEDODDS_API_KEY node odds-alerts-ws.mjs. By default it watches NBA, NHL, NCAAB for 300 seconds; LEAGUES, MOVE_POINTS, MOVE_BOOKS, MIN_EV and SECONDS change that. To keep it running, remove the final setTimeout and run it under a process manager.

What did a real run return?

We ran the script on November 25, 2026, 08:55 UTC, about 4 a.m. Eastern, with SECONDS=180 and the default thresholds, against live prices. The start, the first alerts and the end of its output:

start: GET /v1/ev returned 80 prices at or above 0.03 (nba 1, nhl 57, ncaab 22)
MOVE 08:55:37 Memphis Tigers @ Penn State Nittany Lions spread@game home -1.5: 3 books longer in 18s (kalshi +170->+186, novig +156->+163, polymarket +156->+163)
MOVE 08:55:39 USC Trojans @ South Carolina Gamecocks spread@game away -9.5: 3 books longer in 15s (polymarket -144->-138, kalshi -133->-127, prophetx -152->-143)
MOVE 08:55:43 Yale Bulldogs @ Wright State Raiders spread@game away -1.5: 3 books longer in 10s (kalshi +233->+257, prophetx +174->+210, novig +207->+222)
MOVE 08:56:06 St. Bonaventure Bonnies @ Belmont Bruins spread@game home -2.5: 3 books longer in 32s (prophetx +174->+198, kalshi +213->+233, novig +194->+203)
EV   08:55:07 Charlotte 49ers @ Northern Iowa Panthers spread@game home -1.5: kalshi +355, fair 23.9%, ev 0.0865
EV   08:55:07 Eastern Washington Eagles @ Loyola Marymount Lions spread@game home -13.5: kalshi +245, fair 30.8%, ev 0.0633
EV   08:55:10 Eastern Washington Eagles @ Loyola Marymount Lions spread@game home -18.5: kalshi +400, fair 20.7%, ev 0.0355
EV   08:55:10 Saint Peter's Peacocks @ Columbia Lions spread@game away +7.5: kalshi +317, fair 26.5%, ev 0.1059
EV   08:55:17 DEN @ UTA moneyline@game home: polymarket +285, fair 27.1%, ev 0.0430
EV   08:55:18 Northern Illinois Huskies @ SIU Edwardsville Cougars spread@game away -11.5: kalshi +270, fair 28.0%, ev 0.0342
...
summary: 3365 price frames, 5717 price changes, 10 move alerts, 26 EV alerts, 179 muted by the cooldown
check: GET /v1/ev returned 91 moneyline, spread and total prices, 19 had the same price in the stream; the formula gave the same ev (to 0.0005) for 19

In 180 seconds it read 3,365 price frames with 5,717 price changes. 10 selections moved at 3 books together and 26 prices were 3% or more above fair; another 179 alerts were held back because the same selection had already alerted in the last 10 minutes. These are prices of one night, shown as an example and not as current prices.

Three things stand out in this run:

  • Every move alert came from Kalshi, Novig, Polymarket and ProphetX, prediction markets and exchanges whose prices kept changing at that hour. A quick move there can be a thin price, so check the sportsbooks before you read anything into it.
  • The EV alerts came from Kalshi (19), Polymarket (4) and Fanatics (3). 22 of the 26 were spreads and 24 had prices of +200 or longer. Their EV ran from 0.0321 to 0.1392.
  • The check matched: at the end, GET /v1/ev listed 91 moneyline, spread and total prices; 19 of them had the same price in the script's state, and the script's formula gave the same EV as the API for all 19. The other 72 were not in the script's state at the same price, so they were not compared.

Prices at Kalshi and Polymarket do not include their fees, which lower the real return; Kalshi and Polymarket vs sportsbooks covers them.

How do I change what the script alerts on?

  • MOVE_POINTS and MOVE_BOOKS: how big a move must be at each book, in points of implied probability, and how many books must agree. Raise MOVE_BOOKS to wait for a wider move.
  • MIN_EV: the EV threshold. The EV calculator shows what a given price and probability are worth, and the implied probability calculator converts one price.
  • Books: add books: ["draftkings", "fanduel", ...] to the subscribe message to watch only some books; the WebSocket subscription builder writes that message for you.
  • LEAGUES: any league id from the coverage page. Player props also arrive on the WebSocket, with a player object on each change; add their market keys and the player name to the alert.

What are the limits of odds alerts?

EV is a calculation against an estimate: the fair price is the API's no-vig estimate (its sources field names the books it used), and a positive EV is an average over many bets, not a promise on one. Prices move in seconds, so check the price at the book before you act on an alert. The EV alert skips games in play, as GET /v1/ev does, because in-play prices follow the score and go stale fast. A move alert says that books moved, not why. The script keeps no history: the API returns current prices and changes, so to look back you have to record them yourself, as in odds history in SQLite. Nothing here is betting advice.

To send moves to a chat instead of the terminal, see the Telegram odds bot, which follows Telegram's message and rate limits.

FAQ

Is a move at several books the same as steam?

Bettors call a fast move across many books steam. The script finds moves at several books inside a time window; whether a move comes from bets, news or one book copying another is not something the prices say.

Why check the EV against GET /v1/ev?

To make sure the formula and the fair price in the script are the ones the API uses. In our run they gave the same EV for all 19 prices the two had in common.

Can I send the alerts to Discord or Slack?

Yes. Replace console.log in alert() with a POST to the webhook URL; the Discord odds alert bot has a version that respects Discord's rate limits.

Where do I start?

Run the script for three minutes on one league and watch what it prints before you change the thresholds. The fields are in the docs and the books and leagues are on the coverage page. Every plan starts with a 3-day free trial with a $1 card verification that is refunded immediately. The plan you pick at signup is charged from day 4 unless you cancel before the trial ends. See pricing or create an account.