⚠️
Important! We’ve moved to V3! This documentation is for V2 only and will be updated in May.
Developer Hub
🔮 For applications
SDK
Watch Hooks
useSelectionOdds

useSelectionOdds

The useSelectionOdds hook is used for maintain updated odds for a selection and also monitors the suspension of bets for that selection.

Whenever a bet is placed on the Azuro protocol, the system updates the odds related to the outcomes influenced by this bet. Utilize this hook to subscribe to the updated odds for the outcomes displayed in your UI. This ensures that bettors can observe the current changes and make informed betting decisions.

Usage

⚠️

Before utilizing useSelectionOdds, it is essential to initialize the FeedSocketProvider and ConditionUpdatesProvider:

  import { ChainProvider, FeedSocketProvider, ConditionUpdatesProvider, useWatchers } from '@azuro-org/sdk'
 
  function Providers(props: { children: React.ReactNode }) {
    const { children } = props
 
    return (
      <ChainProvider>
        <FeedSocketProvider>
          <ConditionUpdatesProvider>
            {children}
          </ConditionUpdatesProvider>
        </FeedSocketProvider>
      </ChainProvider>
    )
  }

Subscribe to changes in your outcome.

import { useSelectionOdds } from '@azuro-org/sdk'
import { type MarketOutcome } from '@azuro-org/toolkit'
 
const outcome: MarketOutcome = {...}
 
const { data: odds, isFetching } = useSelectionOdds({
  selection: outcome,
  initialOdds: outcome.odds,
})
ℹ️

Example of usage: Outcome button.

We've retrieved markets with outcomes and rendered a button for each outcome. The useSelectionOdds hook offers a method to maintain updated odds for the outcome button. Full Example (opens in a new tab)

import { useSelectionOdds } from '@azuro-org/sdk'
import { type MarketOutcome } from '@azuro-org/toolkit'
 
type OutcomeProps = {
  outcome: MarketOutcome
}
 
export function OutcomeButton(props: OutcomeProps) {
  const { outcome } = props
 
  const { data: odds, isFetching } = useSelectionOdds({
    selection: outcome,
    initialOdds: outcome.odds,
  })
 
  return (
    <button>
      <span>{outcome.selectionName}</span>
      <span>{odds}</span>
    </button>
  )
}

Props

{
  selection: Selection
  initialOdds?: number
}
ℹ️

The initialOdds is optional. If it's not provided, the useSelectionOdds hook will automatically retrieve the initial value.

type Selection = {
  conditionId: string
  outcomeId: string
}

Return Value

{
  data: number, // outcome's odds
  isFetching, // flag indicates initial odds fetching
}