> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orica.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Indexer

> How the Orica indexer processes and serves blockchain data.

The Orica indexer is a background service that monitors the Solana blockchain and maintains a structured database of all protocol activity.

***

## Purpose

The indexer solves fundamental challenges with blockchain data:

| Challenge | Solution |
| - | - |
| No complex queries on-chain | Indexer writes to PostgreSQL with full SQL support |
| No historical data | Indexer stores snapshots at regular intervals |
| Slow RPC queries | Indexer pre-computes aggregations |
| Limited real-time updates | Indexer broadcasts via WebSocket |

***

## Data Pipeline

```mermaid theme={"dark"}
flowchart LR
    Solana["Solana RPC"] --> |"WebSocket Subscription"| Indexer
    Indexer --> |"Parse Transactions"| Parser["Transaction Parser"]
    Parser --> |"Extract Events"| Events["Event Processor"]
    Events --> |"Write"| DB["PostgreSQL"]
    Events --> |"Broadcast"| WS["WebSocket Clients"]
```

***

## Indexed Data

The indexer tracks and stores:

> [accordion] Markets
>
> * Market creation events
> * Pool balances (outcome\_pools)
> * Supply changes (outcome\_supplies)
> * Status transitions
> * Resolution data

> [accordion] Trades
>
> * Buy transactions
> * Sell transactions
> * Redemption transactions
> * Fee calculations
> * Price at execution

> [accordion] Price Snapshots
>
> * Market cap per outcome
> * Supply per outcome
> * Volume per interval
> * Timestamp

> [accordion] Disputes
>
> * Dispute creation
> * Vote records
> * Messages and boosts
> * Resolution overrides

***

## Snapshot Intervals

Price history is stored at configurable intervals:

| Interval | Description |
| - | - |
| `1s` | Every second (raw data) |
| `1m` | Every minute |
| `5m` | Every 5 minutes |
| `15m` | Every 15 minutes |
| `1h` | Every hour |
| `4h` | Every 4 hours |
| `1d` | Every day |

The API automatically aggregates and gap-fills snapshots based on the requested interval.

***

## Real-Time Updates

The indexer broadcasts updates to connected WebSocket clients:

```mermaid theme={"dark"}
sequenceDiagram
    participant User
    participant Solana
    participant Indexer
    participant API
    participant Client

    User->>Solana: Send Transaction
    Solana->>Indexer: Transaction Confirmed
    Indexer->>API: Update Database
    Indexer->>Client: WebSocket Broadcast
```

Latency from transaction confirmation to WebSocket broadcast is typically **1-2 seconds**.

***

## Time Service

The indexer maintains an accurate representation of blockchain time:

1. Fetches current slot from Solana
2. Retrieves block time for that slot
3. Uses block time for all status computations

> [!NOTE]
>
> This ensures that market status (open/closed) is computed consistently across all clients, even if their system clocks differ.

***

## Failure Handling

The indexer is designed for resilience:

| Scenario | Handling |
| - | - |
| RPC disconnection | Automatic reconnection with exponential backoff |
| Missed transactions | Periodic full sync to catch gaps |
| Database downtime | Transaction buffering and retry |
| Invalid data | Logged and skipped without crashing |

***

## Health Monitoring

Check indexer status via the health endpoint:

```bash theme={"dark"}
curl https://api.orica.markets/health
```

Response:

```json theme={"dark"}
{
  "status": "ok",
  "version": "1.0.0",
  "indexer_running": true,
  "websocket_connections": {
    "total": 42,
    "by_ip": { "..." }
  }
}
```

***

## Next Steps

> [card] [API Reference](https://docs.orica.markets/api-reference/introduction.md)
>
> Explore the REST and WebSocket APIs.

> [card] [WebSocket](https://docs.orica.markets/api-reference/websocket/market-data.md)
>
> Connect to real-time data streams.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.