Skip to Content

getBetsByBettor

Retrieves all bet orders for a specific bettor address with optional filtering. Supports pagination and filtering by state, result, affiliate, and redemption status.

Usage

import { getBetsByBettor, BetOrderResult } from '@azuro-org/toolkit' const chainId = 137 const bettor = '0x...' // Get the latest 100 bet orders in any state const allBets = await getBetsByBettor({ chainId, bettor }) // Get only redeemable bets const redeemableBets = await getBetsByBettor({ chainId, bettor, result: [BetOrderResult.Won, BetOrderResult.Canceled], isRedeemed: false, limit: 1000, })

Props

type GetBetsByBettorParams = { chainId: ChainId bettor: Address affiliate?: Address result?: BetOrderResult | BetOrderResult[] state?: BetOrderState | BetOrderState[] isRedeemed?: boolean offset?: number /** default: 100 */ limit?: number }
export enum BetOrderState { /** First status when created */ Created = 'Created', /** Bet is included in the calculation of potential loss/wins */ Placed = 'Placed', /** The relayer has been taken into processing to send the bet to the contracts */ Sent = 'Sent', /** Bet successfully accepted in the contracts */ Accepted = 'Accepted', /** An error occurred during the contracts checks */ Rejected = 'Rejected', /** The process of canceling the bet. The bet placed in the contracts still has the "GraphBetStatus.Accepted" status */ PendingCancel = 'PendingCancel', /** Cancellation error. The bet placed in the contracts still has the "GraphBetStatus.Accepted" status */ CancelFailed = 'CancelFailed', /** Bet is canceled */ Canceled = 'Canceled', /** The bet is settled (won or lost) */ Settled = 'Settled', } enum BetOrderResult { Won = 'Won', Lost = 'Lost', Canceled = 'Canceled', }

Return Value

Returns BetOrderData[] array or null if no bets found (404 response).

type BetOrderData = { id: string state: BetOrderState environment: Environment betType: 'ORDINARY' | 'COMBO' core: Address bettor: Address owner: Address affiliate: Address amount: number payout: number | null odds: number bonusId: string | null isFreebet: boolean betId: number | null txHash: Hex | null margin: string settledMargin: string | null result: BetOrderResult | null createdAt: ISOTimestamp updatedAt: ISOTimestamp settledAt: ISOTimestamp | null redeemedAt: ISOTimestamp | null conditions: BetOrderConditionData[] meta: BetMetaData | null // subgraph mirror - carries the per-outcome results, see below error: string | null errorMessage: string | null }
type BetOrderConditionData = { conditionId: string outcomeId: number orderId: string gameId: string /** * State of the game at the moment of bet placing, to determine whether the bet is Live or not. * */ gameState: GameState.Live | GameState.Prematch conditionMargin: string selectionMargin: string settledSelectionMargin: string | null result: BetConditionStatus | null /** * Formatted odds of the condition, e.g. "1.55" * */ price: string /** * Formatted amount, * e.g. "18.5" * * in COMBO bets, it can have more fractional digits than bet token decimals, * e.g. "18.057553956834532374" for 6 decimals USDT * */ potentialAmount: string | null potentialLoss: string | null }

Per-outcome results

Settlement is per-outcome: within a single condition, one outcome can be Won, another Lost and a third Canceled (voided, stake refunded). The result of each of a bet’s legs therefore lives on meta.selections[].outcome.condition.outcomes[], keyed by outcomeId:

type BetMetaData = { // ... selections: Array<{ id: string odds: string /** per-selection signal, typed `SelectionResult` (Won | Lost) - cannot express a void */ result: SelectionResult | null outcome: { outcomeId: string sortOrder: number condition: { conditionId: string gameId: string /** subgraph condition status - NOT the feed's `ConditionState`, and NOT a per-leg result */ status: ConditionStatus outcomes: { /** the authoritative per-outcome settlement signal for this bet's leg */ result: OutcomeResult | null outcomeId: string sortOrder: number }[] wonOutcomeIds: null | string[] // ... } } // ... }> // ... } enum OutcomeResult { Won = 'Won', Lost = 'Lost', Canceled = 'Canceled' }
import { OutcomeResult } from '@azuro-org/toolkit' const selection = order.meta!.selections[0]! const legResult = selection.outcome.condition.outcomes .find(({ outcomeId }) => outcomeId === selection.outcome.outcomeId)?.result const isLegVoided = legResult === OutcomeResult.Canceled const isLegWon = legResult === OutcomeResult.Won const isLegPending = !legResult
⚠️

A voided leg must be excluded from a combo’s odds and potential win. Multiplying a refunded leg into the total reports a payout the protocol will never pay. Do not derive a leg’s result from condition.status or from wonOutcomeIds — the former describes the condition entity, the latter only ever describes wins. See the Toolkit v7 Migration Guide.

See getBet for the full BetMetaData shape.