Developer Hub
🔮 For applications
Guides & Tutorials
Advanced integration
Live betting
Data retrieval

Live data retrieval

All the live games and markets data is stored in the HostCore smart contract in the HostChain (currently is a Gnosis chain) and can be retrieved via a LiveDataFeed subgraph.

Data structure is almost the same as the one in the main Subgraph for prematch core contracts.

ℹ️

Key differences in the entities structure comparing to prematch subgraphs:

  • Removed all entities and events related to bets (bets, freebets, expresses) and contracts (cores, liquidity pools).
  • Removed selection entity and its relations.
  • Entity condition doesn't have an isExpressForbidden field.
  • Event GameShifted changed to GameUpdated (triggers by changing game status and/or start time).
  • Event ConditionShifted completely removed.

Typical data feed lifecycle:

  1. Game appears in the LiveDataFeed subgraph in the Created state. It means that the game is in live state.
  2. Conditions start to appear in this game (usually they start to appear almost when the game starts and finish appearing in 5-10 minutes).
  3. During the game each Condition can change its state between Paused and Created. Also condition's odds can be changed.
  4. Game finishes and its status changes to Finished.
  5. After some period Conditions start to finalize their status to Resolved/Canceled.
  6. After all Conditions are resolved, the game change its status to Resolved.

How to display live games and markets

Here we'll describe the logic of displaying live games and their markets. Supposed that you already have a frontend with setup prematch games.

Load live games

When game goes live, it saves its id (so the same game in prematch and live subgraphs have the same gameId value), but it's stored in another smart contract, and you should load its info from another subgraph called LiveDataFeed.

We recommend you to call a snapshot of live games almost the same way you did it for prematch games (see Get Games section), but you need to filter them by Created status:

useQuery(QUERY, {
  variables: {
    where: {
      status: 'Created',
      hasActiveConditions: true, // Avoid this parameter if you want to get the game with no available markets
    },
  },
})
⚠️

While most of the games that we provide in prematch will go live, we don't guarantee it for each particular game. Consider this when planning your UX.

💎

If you want to effectively update your games list without querying big snapshots each time, you need to listen to the following events in the LiveDataFeed subgraph: NewGame, GameUpdated, GameCanceled. For each new event you can get its gameId field and retrieve an actual game's info.

Load markets

For each live game you can request its markets (called conditions) the same way you do this for prematch games (see Prepare game markets section).

⚠️

Take into consideration that markets appear after the game created in the HostCore smart contract. It means that this is a normal situation if a game doesn't have any live markets for a while. You should continue to request game markets all the time and be ready to add a new ones until the game is finished.

Get realtime markets updates

As for prematch games, live game's markets are constantly updated:

  • Market can be stopped and unstopped.
  • Outcomes odds can be changed.

To receive updates, utilize the Socket API. Begin by creating a new socket instance.

// For development
const socketUrl = wss://dev-streams.azuro.org/v1/streams/conditions
// For pre-production
const socketUrl = wss://preprod-streams.azuro.org/v1/streams/conditions
// For production
const socketUrl = wss://streams.azuro.org/v1/streams/conditions
 
const socket = new WebSocket(socketUrl)

You can now subscribe to updates by passing condition IDs to listen.

socket.send(JSON.stringify({
  action: 'subscribe',
  conditionIds: [ '123456789' ],
}))
⚠️

Ensure to unsubscribe from updates for conditions that are not in use.

  socket.send(JSON.stringify({
    action: 'unsubscribe',
    conditionIds: [ '123456789' ],
  }))

Afterward, you should listen for new data messages. The message.data object holds the updated condition status and odds. Additionally, other data is utilized to calculate the minOdds for live betting.

To handle market stop/unstop actions, monitor the state field. If it is present, update the condition status in your UI.

For changes in odds, examine the outcomes field. If it is present, update the odds for the corresponding outcome in your UI.

ℹ️

Upon making a subscription request, you will receive all data associated with the subscribed conditions.

enum ConditionStatus {
  Created = 'Created',
  Resolved = 'Resolved',
  Canceled = 'Canceled',
  Paused = 'Paused'
}
 
type SocketData = {
  id: string // condition id
  state?: ConditionStatus // condition status
  margin: number
  reinforcement: number
  winningOutcomesCount: number
  outcomes?: Array<{
    id: number // outcome id
    odds: number // current odds
    clearOdds: number // current odds without marginality
  }>
}[]
 
socket.onmessage = (message: MessageEvent<SocketData>) => {
  const data = JSON.parse(message.data.toString())
 
  data.forEach(data => {
    if (data.outcomes) { // new odds received
    }
 
    if (data.state) { // new condition status received
    }
  });
}

Finish a game

When game finishes, its status changes on Finished until it has unsettled markets. When all markets are settled, its status changes on Resolved.