groupConditionsByMarket
Creates markets from subgraph or REST API conditions.
Returned markets are ordered by their first condition’s sort value (ascending). Each market and condition also carries a category (see ConditionCategory), and passing an empty or nullish conditions array returns [].
Usage
import { groupConditionsByMarket, ConditionsQuery } from '@azuro-org/toolkit'
const conditions: ConditionsQuery['conditions'] = [...]
const markets = groupConditionsByMarket(conditions)Props
type ConditionsQuery = ConditionsQuery['conditions']Return Value
type GameMarkets = Market[]type Market = {
marketKey: string
name: string
description: string
conditions: MarketCondition[]
category: ConditionCategory
type?: 'legacy' | 'v5'
}
type MarketCondition = {
conditionId: string
state: ConditionState
category: ConditionCategory
sort: number
margin: string
hidden?: boolean
isExpressForbidden: boolean
outcomes: MarketOutcome[]
}
type MarketOutcome = {
selectionName: string
odds: number
gameId: string
isExpressForbidden: boolean
hidden: boolean
/** the per-outcome source of truth: Active | Stopped | Won | Lost | Canceled */
state: OutcomeState
} & Selection
type Selection = {
conditionId: string
outcomeId: string
}
enum ConditionState {
Active = 'Active',
Stopped = 'Stopped',
}
enum OutcomeState {
Active = 'Active',
Canceled = 'Canceled',
Stopped = 'Stopped',
Won = 'Won',
Lost = 'Lost'
}
type ConditionCategory =
| 'correct_score'
| 'handicap'
| 'handicap_3_way'
| 'odd_even'
| 'participant_and_total'
| 'participant_and_yes_no'
| 'participant_slash_participant'
| 'players'
| 'result'
| 'result_or_neither'
| 'total'
| 'total_3_way'
| 'winner'
| 'yes_no'
| string // extensible — new categories may appear; null when unset
| nullMarketOutcome.state is the only per-outcome source of truth.
MarketOutcome.isWon was removed in toolkit v7. It was derived from the condition’s wonOutcomeIds and
was undefined whenever those were absent, so outcome.isWon ? 'Won' : 'Lost' rendered every outcome of
an unsettled market as lost, and could not express a void at all.
state distinguishes all five cases, and outcomes of the same condition can be in different states at
once — MarketCondition.state is only ever Active or Stopped and carries no result:
import { isOutcomeSettled, OutcomeState } from '@azuro-org/toolkit'
if (!isOutcomeSettled(outcome.state)) {
// still open - Active, or Stopped (temporarily not offered)
}
else if (outcome.state === OutcomeState.Won) {
// won
}
else if (outcome.state === OutcomeState.Canceled) {
// voided - stake refunded
}
else {
// OutcomeState.Lost
}See isOutcomeSettled.