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

# Sui Price Feed via Kafka

> Consume real-time Sui token price updates via Kafka topic

## Overview

The Kafka-based Sui Price Feed provides real-time token price updates from on-chain. Developers can consume these messages to power DeFi dashboards, automate trading logic, or monitor asset valuations in near real-time.

This document describes how to connect to the Kafka topic and consume structured price feed messages for Sui-based tokens.

## Kafka Consumer Setup

### Prerequisites

* Kafka info (connect our team to subscribe with supported plan)
* Node.js (or Python/Java, depending on your preference).
* Kafka client library (e.g., `kafkajs` for Node.js).

### Example Kafka Message Payload

Each message published to the Kafka topic contains structured price data:

```json theme={null}
{
  "contract_address": "0x2::sui::SUI",
  "timestamp": 1747753504,
  "price": 3.8052,
  "decimals": 9,
  "symbol": "SUI",
  "name": "Sui"
}
```

### Field Descriptions

| Field              | Description                                            |
| ------------------ | ------------------------------------------------------ |
| `contract_address` | On-chain address of the token contract.                |
| `timestamp`        | Unix timestamp in seconds when the price was recorded. |
| `price`            | Adjusted price based on the on-chain data.             |
| `decimals`         | Number of decimal places for the token.                |
| `symbol`           | Token symbol (e.g., `SUI`).                            |
| `name`             | Full name of the token.                                |

***

## Consuming Messages (Node.js Example)

Install the KafkaJS client:

```bash theme={null}
npm install kafkajs
```

### Kafka Consumer Script

```js theme={null}
const { Kafka } = require('kafkajs');

const kafka = new Kafka({
  clientId: 'sui-price-feed-consumer',
  brokers: ['your-kafka-broker:9092'], // Replace with our Kafka broker address
});

const topic = 'sui-price-feed';
const consumer = kafka.consumer({ groupId: 'price-feed-group' });

const run = async () => {
  await consumer.connect();
  await consumer.subscribe({ topic, fromBeginning: false });

  await consumer.run({
    eachMessage: async ({ message }) => {
      const payload = JSON.parse(message.value.toString());

      console.log(`Received price update for ${payload.symbol}:`);
      console.log(`Price: ${payload.price}`);
      console.log(`Timestamp: ${new Date(payload.timestamp).toISOString()}`);
    },
  });
};

run().catch(console.error);
```

***

### Best Practices

* **Use Consumer Groups**: Assign consumers to groups to avoid duplicate processing.
* **Graceful Failure Handling**: Add retry logic.
* **Number Consumers**: Best performance is typically achieved with 3 consumers.
