/stream

WSwss://api.aori.io

Connect to the real-time WebSocket stream to receive live order events and status updates. Provides instant notifications for all order lifecycle events across the Aori protocol.

Connection

Connect to the WebSocket endpoint to start receiving real-time events. No authentication required for public order events.

JavaScript

const ws = new WebSocket('wss://api.aori.io/stream');

ws.onopen = () => {
  console.log('Connected to Aori stream');
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Received event:', data);
};

Event Messages

All events follow the same message structure with complete order data.

  • Name
    eventType
    Type
    string
    Description

    Type of event (created, received, completed, failed)

  • Name
    timestamp
    Type
    number
    Description

    Unix timestamp when the event occurred

  • Name
    orderHash
    Type
    string
    Description

    Unique identifier for the order

  • Name
    offerer
    Type
    string
    Description

    Address that initiated the order

  • Name
    recipient
    Type
    string
    Description

    Address receiving the output tokens

  • Name
    inputToken
    Type
    string
    Description

    Input token contract address

  • Name
    inputAmount
    Type
    string
    Description

    Amount of input tokens

  • Name
    inputChain
    Type
    string
    Description

    Source chain identifier

  • Name
    outputToken
    Type
    string
    Description

    Output token contract address

  • Name
    outputAmount
    Type
    string
    Description

    Amount of output tokens

  • Name
    outputChain
    Type
    string
    Description

    Destination chain identifier

  • Name
    startTime
    Type
    number
    Description

    Unix timestamp when order became valid

  • Name
    endTime
    Type
    number
    Description

    Unix timestamp when order expires

  • Name
    txHash
    Type
    string | null
    Description

    Transaction hash (for received/completed/failed events)

  • Name
    blockNumber
    Type
    number | null
    Description

    Block number (for on-chain events)

Event Message

{
  "eventType": "completed",
  "timestamp": 1703001780,
  "orderHash": "0x1234567890abcdef1234567890abcdef12345678",
  "offerer": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  "recipient": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  "inputToken": "0x4200000000000000000000000000000000000006",
  "inputAmount": "1000000000000000000",
  "inputChain": "base",
  "outputToken": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
  "outputAmount": "3200000000",
  "outputChain": "arbitrum",
  "startTime": 1703001600,
  "endTime": 1703005200,
  "txHash": "0xdef456abc123789...",
  "blockNumber": 87654321
}

Event Types

Created Events

Emitted when a new order is submitted to the protocol.

Received Events

Emitted when the source chain transaction is confirmed.

Completed Events

Emitted when the order is successfully completed on the destination chain.

Failed Events

Emitted when order execution fails and is reverted.

Event Filtering

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  
  switch (data.eventType) {
    case 'created':
      handleOrderCreated(data);
      break;
    case 'received':
      handleOrderReceived(data);
      break;
    case 'completed':
      handleOrderCompleted(data);
      break;
    case 'failed':
      handleOrderFailed(data);
      break;
  }
};

Client-Side Filtering

The WebSocket streams all events. Implement client-side filtering to monitor specific orders, addresses, or chains.

Filter by Order Hash

Monitor a specific order's progress.

Filter by Address

Track orders for specific offerer or recipient addresses.

Filter by Chain

Monitor cross-chain activity for specific networks.

Filter by Token

Track swaps involving specific tokens.

Filtering Examples

// Filter by order hash
const targetOrderHash = "0x1234...";
if (data.orderHash === targetOrderHash) {
  updateOrderStatus(data);
}

// Filter by offerer address
const userAddress = "0x742d35...";
if (data.offerer === userAddress) {
  addToUserOrders(data);
}

// Filter by chain pair
if (data.inputChain === "base" && 
    data.outputChain === "arbitrum") {
  trackBaseToArbitrumSwap(data);
}

// Filter by token
const WETH = "0x4200000000000000000000000000000000000006";
if (data.inputToken === WETH || data.outputToken === WETH) {
  trackWETHActivity(data);
}

Connection Management

Reconnection Logic

Implement automatic reconnection for production applications.

Heartbeat/Ping

The server sends periodic ping frames to maintain connection.

Error Handling

Handle connection errors and implement exponential backoff.

Production WebSocket

class AoriWebSocket {
  constructor() {
    this.reconnectAttempts = 0;
    this.maxReconnectAttempts = 5;
    this.connect();
  }

  connect() {
    this.ws = new WebSocket('wss://api.aori.io/stream');
    
    this.ws.onopen = () => {
      console.log('Connected to Aori stream');
      this.reconnectAttempts = 0;
    };

    this.ws.onclose = () => {
      this.handleReconnect();
    };

    this.ws.onerror = (error) => {
      console.error('WebSocket error:', error);
    };
  }

  handleReconnect() {
    if (this.reconnectAttempts < this.maxReconnectAttempts) {
      const delay = Math.pow(2, this.reconnectAttempts) * 1000;
      setTimeout(() => {
        this.reconnectAttempts++;
        this.connect();
      }, delay);
    }
  }
}

Notes

  • All events include complete order data for immediate use without additional API calls
  • Events are emitted in real-time as they occur on the blockchain
  • No subscription or filtering is done server-side - implement client-side filtering as needed
  • Connection is automatically maintained with periodic ping/pong frames
  • Use this stream for real-time order monitoring, status updates, and analytics
  • Consider implementing connection pooling for high-volume applications