Docs

Somnia Markets / How-to guides

Check venue health

This guide shows you how to ask one question before you show indexed data: does this venue serve trustworthy data now? Use the answer to switch your app to chain-only data during an indexer outage. It assumes a working SomniaMarkets configuration.

Read the verdict

client.getVenueHealth() returns a status of "ok", "degraded" or "down", a reason to show, and one check per configured subsystem.

const health = await exchange.client.getVenueHealth();
if (health.status === "ok") {
  showIndexedViews();
} else {
  showBanner(health.reason);
  showChainOnlyViews();
}

What still works when the main indexer is down lists the chain reads to use in showChainOnlyViews.

The call does not throw for a failed read. A failed read becomes a "down" or "degraded" check. The call rejects only when the exchange's signal aborts, stopLive() runs or the exchange closes. Each read gets 5 s, so the call resolves within about 5 s. Poll it every 15 s or more, not on each render.

What each check grades

A check runs only when its subsystem is configured. A subsystem that is not configured has no check.

Check Runs when "degraded" "down"
indexer indexerUrl is set over 30 s of chain time behind the head, or the lag cannot be measured over 120 s behind the head, no answer, no row for the chain, or no block processed
chain the chain has a WebSocket endpoint never no answer
priceFeed addresses.priceFeedScheduler is set no price requested for over 10 s, or its state cannot be read no price written for over 60 s, or never

The 120 s, 60 s and 10 s bounds are those of the production alerts IndexerFreshnessHigh, PriceFeedStale and PriceFeedSchedulerStopped. The indexer lag is measured against the chain head that the SDK reads, not against the head that the indexer reports, because the indexer's own head stops when the indexer stops. Price feed ages use the head's block time, so a wrong local clock does not change them.

There is no check for market creation and resolution yet.

Grade readings you already hold

assessVenueHealth(snapshot) is the same verdict as a pure function. Use it when you already read the indexer, the chain or the price feed, for example on a server.

import { assessVenueHealth } from "@somnia-chain/markets-sdk";

const chainId = exchange.client.config.chain.id;
const indexer = await exchange.client.getIndexerFreshness(chainId).then(
  (value) => ({ ok: true as const, value }),
  (error: unknown) => ({ ok: false as const, reason: String(error) }),
);
const health = assessVenueHealth({ nowMs: Date.now(), indexer });
console.log(health.status, health.reason);

Give a failed read as { ok: false, reason }. Leave out a subsystem that the venue does not configure.

Test the outage path

Set simulateIndexerOutage on the client. See Simulating an indexer outage. With "down", the indexer check is "down" at once. With "slow", it is "down" after its 5 s limit. The chain and price feed checks are not affected.

Send feedback

Agents: POST the same to /api/feedback.