Matching Markets Across Sportsbooks with Stable IDs
How to join the same market across sportsbooks before comparing prices. What event, market and selection ids identify, why a market id changes when the line moves, why spreads and totals must be grouped by line first, the pitfalls that produce false best prices, and a reproducible grouping example.
By PreciseAPI Engineering
Published
Every odds comparison is a join. Before you can say which book has the best price, you have to know that two quotes describe the same contract: the same game, the same market, the same period, the same player and the same line. Get the join wrong and the comparison still produces an answer. It's just the wrong one, and nothing in the output tells you.
Normalizing odds across sportsbooks describes how PreciseAPI maps 36 sources, 23 of them sportsbooks, onto one schema. This post is about using that schema to compare prices. It covers which id answers which question, why lines must be grouped before prices, the pitfalls that create false best prices, and a grouping function you can run against the sample data below. Field names and id rules are from the data model and the best lines reference.
Three ids, three different questions
| Id | Identifies | Includes the book? | Includes the line? | Changes when |
|---|---|---|---|---|
evt_… | One game, match or fight | No | No | Never. Extra ids for the same game are listed in alternate_ids and keep resolving to it |
mkt_… | One source's offer: market key, period, player or team, variant and line | Yes | Yes | The book posts a different main line |
sel_… | One outcome: market key, period, player or team, variant, side and point | No | Yes, through the point | The point changes |
Two consequences matter for comparisons.
Market ids are per book and per line. DraftKings' full-game spread and Pinnacle's full-game spread on the same game have different market ids. When DraftKings moves its main spread from −4.5 to −5, the −5 line arrives as a new market and the −4.5 market is removed. On the stream that removal carries the reason line_moved. If you want to follow "DraftKings' spread on this game" across moves, key it by event, book, market key, period and subject. That is also how line history keeps one series per book across line moves.
Selection ids are shared across books. The home team at −4.5 for the full game has the same selection id at every book that deals it. Selection ids are the join key for price comparison, because they already encode the line.
Why lines must be grouped before prices
Here is a spread as three books might deal it. DraftKings and Pinnacle are at −4.5. The third book is synthetic: it deals −5, so its selection ids differ.
| Book | Home spread | Home price | Away price |
|---|---|---|---|
| DraftKings | −4.5 | −115 | −105 |
| Pinnacle | −4.5 | −108 | −102 |
| Third book (synthetic) | −5 | −102 | −118 |
Ask "which book has the best home spread price?" without grouping and the answer is −102 at the third book. That is wrong. Laying −5 at −102 and laying −4.5 at −108 are different bets. Whether half a point is worth six cents depends on the sport and on how often games land on that number, which how to compare point spreads covers in detail. Price comparison is only meaningful inside one line, so group first and compare second. The same holds for totals. Moneylines have no line, but they still split by period and, in soccer, by whether the market is two-way or three-way with a draw.
Build the comparison groups yourself
This function takes one event from a /v1/odds response in the default American format and returns, for every contract quoted by at least two books, the best price per outcome and the books offering it. A contract is identified by market key, period, subject, variant, and the side and point of every outcome.
const dec = (a) => (a > 0 ? 1 + a / 100 : 1 + 100 / -a); // American -> decimal
// The contract a market prices: key, period, subject, variant and every side's point.
function contractKey(m) {
const subject = m.player?.id ?? m.team?.id ?? '';
const sides = m.outcomes.map((o) => `${o.side}:${o.point ?? ''}`).sort().join(',');
return [m.key, m.period, subject, m.variant ?? '', sides].join('|');
}
// Groups one event's markets into comparable contracts and finds the best price per outcome.
function compareEvent(event, { minBooks = 2 } = {}) {
const groups = new Map();
for (const book of event.bookmakers) {
if (book.type === 'dfs') continue; // pick'em entries aren't priced like book odds
for (const m of book.markets) {
if (m.suspended || m.key.startsWith('alternate_')) continue;
if (m.variant && m.variant !== 'standard') continue;
if (m.outcomes.some((o) => !Number.isFinite(o.price))) continue;
const k = contractKey(m);
if (!groups.has(k)) groups.set(k, { key: m.key, period: m.period, line: m.line ?? null, books: new Set(), outcomes: new Map() });
const g = groups.get(k);
g.books.add(book.id);
for (const o of m.outcomes) {
if (!g.outcomes.has(o.id)) g.outcomes.set(o.id, { id: o.id, name: o.name, side: o.side, point: o.point ?? null, quotes: [] });
g.outcomes.get(o.id).quotes.push({ book: book.id, price: o.price });
}
}
}
return [...groups.values()]
.filter((g) => g.books.size >= minBooks)
.map((g) => ({
key: g.key, period: g.period, line: g.line, books: g.books.size,
outcomes: [...g.outcomes.values()].map((o) => {
const best = Math.max(...o.quotes.map((q) => dec(q.price)));
const top = o.quotes.filter((q) => dec(q.price) === best);
return { id: o.id, name: o.name, point: o.point, best_price: top[0].price, best_books: top.map((q) => q.book) };
}),
}));
}
To run it without a key, feed it the table above in the API's shape. The DraftKings and Pinnacle markets and their ids come from the example response in the docs. The third book's market is synthetic and filed under a real source id only so the shape is complete:
const spread = (id, line, home, away, homeSel, awaySel) => ({
id, key: 'spread', period: 'full_game', line, suspended: false,
outcomes: [
{ id: homeSel, name: 'Phoenix Suns', side: 'home', point: line, price: home },
{ id: awaySel, name: 'San Antonio Spurs', side: 'away', point: -line, price: away },
],
});
const event = {
id: 'evt_1iazqk4srnb',
bookmakers: [
{ id: 'draftkings', type: 'sportsbook', markets: [spread('mkt_14ivq762bz0', -4.5, -115, -105, 'sel_1d92w0erhd2', 'sel_1lhzilnwepp')] },
{ id: 'pinnacle', type: 'sportsbook', markets: [spread('mkt_19gvfk2ks6p', -4.5, -108, -102, 'sel_1d92w0erhd2', 'sel_1lhzilnwepp')] },
// Synthetic: a third book dealing -5. Its selection ids differ because the point differs.
{ id: 'fanduel', type: 'sportsbook', markets: [spread('mkt_synthetic_fd', -5, -102, -118, 'sel_synthetic_h5', 'sel_synthetic_a5')] },
],
};
console.log(JSON.stringify(compareEvent(event), null, 2));
console.log(compareEvent(event, { minBooks: 1 }).map((g) => `${g.key} ${g.line}: ${g.books} book(s)`).join('\n'));
The output, trimmed to the fields that matter:
[ { "key": "spread", "period": "full_game", "line": -4.5, "books": 2,
"outcomes": [
{ "id": "sel_1d92w0erhd2", "name": "Phoenix Suns", "point": -4.5, "best_price": -108, "best_books": ["pinnacle"] },
{ "id": "sel_1lhzilnwepp", "name": "San Antonio Spurs", "point": 4.5, "best_price": -102, "best_books": ["pinnacle"] } ] } ]
spread -4.5: 2 book(s)
spread -5: 1 book(s)
The −5 line forms its own group. With minBooks: 2 it is left out, because a "best price" quoted by one book isn't a comparison. To use it with real data, call /v1/odds?league=nba&markets=main and pass each element of data to compareEvent. If you request format=decimal, replace dec with the identity function.
What /v1/best-lines does for you
/v1/best-lines runs the same grouping on the server. It groups markets by key, period, subject, variant and line, plus each outcome's side and point, and reports only groups that at least two sources quote. Each group carries books_quoting, and each outcome carries best_price and every tied book in best_books. It leaves out the following:
- Alternate lines and suspended markets.
- Promotional offers and variants other than
standard. - DFS apps, and outcomes whose price is
nullbecause the payout depends on the whole entry.
It handles one case the function above doesn't. Some sportsbooks list a full-game moneyline with one side only. Best lines adds that side as a partial quote to the two-way group for the same game.
Choose between them by what you need. /v1/best-lines costs 3 credits and returns only the winners. /v1/odds costs 2 credits and returns every book's price, which you need to show a full comparison row, to measure each book's margin, or to devig per book. The odds comparison API page covers typical uses.
Pitfalls that produce false best prices
- Matching on names or array position. Team names vary by source and outcome order isn't a contract. Match on
side(home,away,draw,over,under) and on ids. - Signs. A spread market's
lineis the home team's point. The away outcome'spointhas the opposite sign, so a −4.5 home spread has an away outcome atpoint: 4.5. Totals carry the same point on both sides. - Comparing points computed by arithmetic. Points arrive as JSON numbers. Halves and quarters are exact in binary floating point, so equality on the delivered values is safe. Values you derive yourself by addition or division may not be. Key on the delivered
point, or on its negation for the other side, and never on a value rounded withtoFixed. - Mixing periods. A first-half total and a full-game total share the key
total./v1/oddsand/v1/best-linesdefault tofull_game. Keepperiodin every group key when you ask for more. - Joining main lines to alternate rungs. A selection id includes the market key. The −4.5 rung of an
alternate_spreadladder therefore has a different id from a mainspreadat −4.5. If you want to price-shop main lines against alternates, join on event, period, side and point yourself. - Variants. DFS lines carry
standard,goblinordemon, and onlystandardlines compare with each other. A sportsbook prop with one Over and no Under is labelledmilestoneand isn't an over/under line. The market fields in the data model list every variant. - Suspended and old quotes. A suspended price is not available. REST leaves suspended markets out unless you pass
include_suspended=true. For comparisons that must use recently confirmed quotes, passmax_source_age_ms(1 to 300,000). Quotes the source hasn't confirmed within that window are left out, including quotes from sources that give no read time. - Event merges. When two ids turn out to be one game, the event keeps the id most sources use and lists the others in
alternate_ids. On the stream, markets filed under the other id are removed with reasonevent_mergedandmerged_into, then follow under the surviving id. Props whose player two books spelled differently are moved under one player id with reasonplayer_merged.
The API already refuses some prices that would poison a comparison. These include placeholder prices, markets whose sides add up to a book above 140% or below 90%, and, before the game, a main spread or total far from the line at least three other sportsbooks use. The price guards section describes them. Don't reintroduce such quotes from another feed without the same checks.
Frequently asked questions
Do selection ids match across sportsbooks?
Yes. Two outcomes share a selection id when they have the same event, market key, period, player or team, variant, side and point, whichever source quotes them. That makes the selection id the natural join key for comparing prices.
Why did a market id disappear when the spread moved?
A market id includes its line. When a book posts a new main spread or total, the new line is a new market and the old one is removed, with reason line_moved on the stream. For full-game moneylines, spreads and totals, history still follows the book's series: /v1/history?market_id= with an id from an earlier line returns the same series.
How do I compare books that deal different lines?
Not by price alone. Either compare at a common line, using a book's alternate ladder where it offers one, or convert between lines with a model for your sport. Grouping by line, as above, keeps the comparison honest until you do.
Can I compare exchange prices with sportsbook prices?
They arrive in the same schema, and /v1/best-lines includes exchanges alongside sportsbooks. Exchange outcomes also carry liquidity in USD, which tells you how much is available at the posted price. Prices are as each source posts them. See pricing for plan access.
Should I build comparisons myself or use /v1/best-lines?
Use /v1/best-lines when you only need the top price and the books offering it. Group /v1/odds yourself when you need every book's quote, your own filters on books, or your own rules for alternates and one-sided markets.
References
- IEEE, IEEE 754-2019: Standard for Floating-Point Arithmetic.
- T. Bray (ed.), RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, section 6, Numbers, IETF, 2017.
- PreciseAPI docs: data model, odds formats, best lines, get odds, streaming removal reasons and coverage.