Two prices appear next to the same team. One is 1.91 and the other is 2.02. Can we compare them?

Only after we establish what each price represents.

A full-match selection and a first-half selection can share a team name. Two handicap selections can refer to the same team with different lines. A familiar label is a useful clue, but it is not a comparison rule.

In this tutorial, we build a small comparison gate in Python. It accepts a deliberately narrow set of selections and rejects anything outside that contract.

All examples are synthetic. The script runs locally and makes no API requests.

Separate event matching from selection matching

Our application needs to answer two questions:

  1. Do these source events refer to the same real-world fixture?
  2. Do these selections represent equivalent bets within that fixture?

A market parser cannot answer the first question.

Instead, our comparison function receives an application-owned fixture ID after event matching has already happened. We keep each source event ID for traceability without assuming that different bookmakers share identifiers.

We also need consistent participant orientation. If our application maps two source events to the same fixture but reverses home and away in one of them, comparing their HOME selections would compare different teams.

Before generating signatures, we must align participants and validate the settlement rules for the supported markets.

This separation makes debugging easier. If the wrong teams appear together, we investigate event matching. If a first-half price appears beside a full-match price, we investigate selection matching.

Start with a narrow contract

PulseScore exposes canonical market and outcome fields alongside original labels, with period and line information where applicable.

We use those fields to build our comparison key and retain the original labels for diagnosis.

For this example, our application supports regulation-time soccer markets only:

Market Allowed outcomes Line required?
Three-way match result: MATCH_RESULT HOME, DRAW, AWAY No
Match goal totals: OVER_UNDER OVER, UNDER Yes

Both use FULL_TIME.

Our calling code must first establish that a market belongs to this scope. A canonical type and period alone cannot prove that two sources use identical settlement rules.

For example, match goal totals and team goal totals must remain separate, even when their thresholds match. Likewise, a three-way match result must stay separate from draw-no-bet or qualification markets.

We leave handicaps, player props, exchange quotes and contextual markets outside this first version. Each needs additional rules.

The function below checks the structure of eligible candidates. It does not independently discover the sport, inspect bookmaker rules or resolve participant identities.

Implement the comparison gate

Save the following as compare_selections.py.

It uses only the Python standard library and runs with Python 3.10 or newer.

from decimal import Decimal, InvalidOperation def decimal_line(value): if value is None or isinstance(value, bool): return None try: number = Decimal(str(value)) except InvalidOperation: return None return number if number.is_finite() else None def signature(fixture_id, market, selection): """Build a key for a candidate already admitted to our market scope.""" if not fixture_id or market.get("period") != "FULL_TIME": return None if market.get("isActive") is not True: return None if selection.get("isActive") is not True: return None kind = market.get("canonicalMarket") outcome = selection.get("canonicalOutcome") # Contextual markets need their own explicit matching policy. if market.get("context") or selection.get("context"): return None if kind == "MATCH_RESULT": if outcome not in {"HOME", "DRAW", "AWAY"}: return None if ( market.get("line") is not None or selection.get("line") is not None ): return None line = None elif kind == "OVER_UNDER": if outcome not in {"OVER", "UNDER"}: return None market_line = decimal_line(market.get("line")) selection_line = decimal_line(selection.get("line")) if market.get("line") is not None and market_line is None: return None if selection.get("line") is not None and selection_line is None: return None if market_line is not None and selection_line is not None: if market_line != selection_line: return None line = ( selection_line if selection_line is not None else market_line ) if line is None: return None else: return None return (fixture_id, kind, "FULL_TIME", outcome, line) if __name__ == "__main__": market = { "canonicalMarket": "OVER_UNDER", "period": "FULL_TIME", "line": 2.5, "isActive": True, "rawName": "Total Goals", } selection = { "canonicalOutcome": "OVER", "line": "2.50", "isActive": True, "odds": 1.95, } original = signature("our-fixture-42", market, selection) assert original is not None # Different raw labels can describe the same supported market. assert original == signature( "our-fixture-42", {**market, "rawName": "Goals Over/Under"}, selection, ) # A first-half market is outside our contract. assert signature( "our-fixture-42", {**market, "period": "FIRST_HALF"}, selection, ) is None # Conflicting market and selection lines are rejected. assert signature( "our-fixture-42", market, {**selection, "line": 3.5}, ) is None # An inactive selection is rejected. assert signature( "our-fixture-42", market, {**selection, "isActive": False}, ) is None # The same selection structure in another fixture stays separate. assert original != signature( "our-fixture-99", market, selection, ) print("Selection comparison checks passed.") 

Run it with:

python compare_selections.py 

Expected output:

Selection comparison checks passed. 

Understand what the checks establish

The decimal conversion makes 2.5 and "2.50" equivalent as dictionary-key values. It preserves the distinction between different thresholds.

We reject conflicting line values instead of choosing whichever field is convenient.

Changing the original market label does not change the signature for an otherwise supported candidate. Changing the period, fixture or threshold prevents an equivalent match.

However, we must check that both signatures are valid before comparing them. Two rejected candidates both return None; that does not make them equivalent.

Our calling code should use this pattern:

left_key = signature(fixture_id, left_market, left_selection) right_key = signature(fixture_id, right_market, right_selection) equivalent_candidate = ( left_key is not None and right_key is not None and left_key == right_key ) 

A matching key means the candidates passed this limited structural check. Our earlier event and settlement checks remain essential.

Keep comparison identity and source identity separate

The signature excludes the bookmaker so equivalent candidates can meet across sources.

Our stored quote should still retain:

  • Bookmaker or source identifier.
  • Source event ID.
  • Market and selection IDs.
  • Original market and selection labels.
  • Price and availability status.
  • Time our application received the observation.

The signature also excludes the price. Otherwise, a price change would create a different comparison identity for the same selection.

We should validate the price separately before displaying or ranking a quote. This example checks selection identity, not whether a price is valid, current or executable.

If several quotes produce the same signature, we should group them into a list. A dictionary assignment that silently overwrites an earlier quote can hide duplicate markets or remove another source from the comparison.

Expand by adding explicit rules

As we expand coverage, the comparison key needs to carry the distinctions our new markets require.

For handicaps, we preserve the selected side's signed line.

For tennis game markets, we include the relevant set and game context.

For player props, we resolve the player's identity, statistic, period and threshold.

For exchange and prediction-market data, we preserve quote type and trading context before deciding how to compare prices.

If we add markets with different settlement policies, we also need a validated rule-group identifier in our comparison key. The same fixture, outcome and period are insufficient when one source includes extra time and another excludes it.

In a production implementation, we should replace a bare rejection with a reason in our logs: unsupported market, missing line, conflicting line, inactive selection or unresolved context.

That gives us something concrete to investigate when a comparison is absent.

A reliable comparison begins with proving that two selections describe the same bet. Once that identity is established, comparing their prices becomes the straightforward part.

Which market causes the most matching problems in your application?

References