Fetch latest transaction via WebSocket

WebSockets allow for real-time updates, making them ideal for receiving the latest transactions on tracked wallets. This guide will walk you through setting up a WebSocket connection, subscribing to the feed, and managing your subscriptions.


Setting up a WebSocket Connection

To start, you'll need to establish a WebSocket connection to the server. The WebSocket URL will be provided by your API provider. Typically, you can use libraries like WebSocket in JavaScript, WebSockets in Python, or any other WebSocket-compatible library in your preferred programming language.

Subscribing to the Feed

Once connected, you can send command messages to the WebSocket to subscribe to various feeds. Here are the different ways you can subscribe:


Subscribe to All Feed Events

  1. To receive all feed events:
{
  "type": "subscribe_feed"
}

  1. Subscribe with Filters

Filter the feed by transaction types, chains, and minimum USD value:

{
  "type": "subscribe_feed",
  "filter": {
      "tx_types": ["transfer", "swap"],
      "chains": ["eth", "bsc"],
      "min_usd_value": 1000
  }
}


  1. Subscribe to a Specific List
{
  "type": "subscribe_feed",
  "bundle_id": "list-id"
}


  1. Subscribe for a specific wallet address
{
  "type": "subscribe_wallet",
  "wallet": "<wallet-address-here>",
}



Example Implementation

const WebSocket = require('ws');

const ws = new WebSocket('wss://feed-api.cielo.finance/api/v1/ws', {
  headers: {
    'X-API-KEY': 'your-api-token-here' // Replace 'your-api-token-here' with your actual API token
  }
});

ws.on('open', function open() {
  ws.send(JSON.stringify({
    type: 'subscribe_feed',
    filter: {
      tx_types: ['transfer', 'swap'],
      chains: ['eth', 'bsc'],
      min_usd_value: 1000
    }
  }));
});

ws.on('message', function incoming(data) {
  console.log('Received:', data);
});

ws.on('error', function error(err) {
  console.error('WebSocket error:', err);
});

ws.on('close', function close() {
  console.log('WebSocket connection closed');
});

This example demonstrates how to connect to the WebSocket, subscribe to a filtered feed, and log incoming messages.

By following this guide, you should be able to effectively use WebSockets to receive real-time updates of on-chain transactions for the wallets and feeds you are interested in. If you have any questions or need further assistance, please refer to the API documentation or contact support.