useOdds
The useOdds
hook is used to calculate the total odds before a bet is placed. These are the odds at which the bet will be placed, not accounting for slippage. The total odds vary based on chosen selections, as each selection can have its own settings for reinforcement and margin.
Usage
⚠️
Before utilizing useOdds
, it is essential to initialize the FeedSocketProvider
and ConditionUpdatesProvider
:
import { ChainProvider, FeedSocketProvider, ConditionUpdatesProvider } from '@azuro-org/sdk'
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
<ChainProvider>
<FeedSocketProvider>
<ConditionUpdatesProvider>
{children}
</ConditionUpdatesProvider>
</FeedSocketProvider>
</ChainProvider>
)
}
Provide selections for calculating.
import { useOdds } from '@azuro-org/sdk'
const { data, isFetching } = useOdds({
selections: [
{
conditionId: '486903008559711340',
outcomeId: '29',
},
],
})
const { odds, totalOdds } = data
ℹ️
The odds
is an object where the key combination is determined by the concatenation of conditionId
and outcomeId
:
odds[`${conditionId}-${outcomeId}`]
ℹ️
Example of usage: Obtain the total odds for the provided selections.
import { useOdds } from '@azuro-org/sdk'
import { type MarketOutcome } from '@azuro-org/toolkit'
type TotalOddsProps = {
outcomes: MarketOutcome[]
}
function TotalOdds(props: TotalOddsProps) {
const { outcomes } = props
const { totalOdds } = useOdds({
selections: outcomes,
})
return (
<span>{totalOdds}</span>
)
}
Props
{
selections: Selection[]
}
type Selection = {
conditionId: string
outcomeId: string
}
Return Value
{
data: {
odds: Record<string, number>
totalOdds: number
}
isFetching: boolean
}