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:

{
  "contract_address": "0x2::sui::SUI",
  "timestamp": 1747753504,
  "price": 3.8052,
  "decimals": 9,
  "symbol": "SUI",
  "name": "Sui"
}

Field Descriptions

FieldDescription
contract_addressOn-chain address of the token contract.
timestampUnix timestamp in seconds when the price was recorded.
priceAdjusted price based on the on-chain data.
decimalsNumber of decimal places for the token.
symbolToken symbol (e.g., SUI).
nameFull name of the token.

Consuming Messages (Node.js Example)

Install the KafkaJS client:

npm install kafkajs

Kafka Consumer Script

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.