Get Odds Values
To clarify, the outcomes are linked to certain markers such that if the value of one outcome changes, all the others are affected as well. Each condition entity includes two outcomes associated with the same market, creating various possibilities for obtaining new odds values.
There are three options for fetching odds values:
Fetch multiple conditions
This option can be especially useful when you are aware that multiple conditions will undergo updates to their odds.
For instance, if you have subscribed to NewBet
events and are utilizing batching, you can accumulate conditions and
make a request every 3 seconds.
const QUERY = gql`
query ConditionOdds($where: Condition_filter, subgraphError: allow) {
conditions(where: $where) {
outcomes {
currentOdds
}
}
}
`
const ids = conditions.map(({ id }) => id)
useQuery(QUERY, {
variables: {
where: {
id_in: ids,
},
},
})
Alternatively, you can re-fetch all conditions for a particular game, such as when a user has accessed a game page and is viewing it.
const QUERY = gql`
query GameOdds($id: String, subgraphError: allow) {
game(id: $id) {
conditions {
outcomes {
currentOdds
}
}
}
}
`
useQuery(QUERY, {
variables: {
id: game.id,
},
})
Call calcOdds
method on the Core contract
type Outcome = {
outcomeId: string
condition: {
conditionId: string
coreAddress: string
}
}
const outcome: Outcome = ...
const coreAddress = outcome.condition.coreAddress
const conditionId = outcome.condition.conditionId
const outcomeId = outcome.outcomeId
const betAmount = '0' // when calculating the odds for outcomes, the bet amount should not be taken into account
const coreContract = new Contract(coreAddress, CORE_ABI, RPC_PROVIDER)
const odds = await coreContract.calcOdds(conditionId, betAmount, outcomeId)