Skip to main content
The WebSocket API provides high-level functionality for working with Fusion+ mode, enabling real-time monitoring of cross-chain swap orders through event streaming.

Purpose

The WebSocket API allows you to:
  • Monitor order lifecycle events in real-time (creation, fills, cancellations)
  • Track order state changes like balance and allowance updates
  • Receive instant notifications when order status changes
  • Access active orders through RPC methods
  • Implement custom WebSocket providers for specialized use cases

When to Use WebSocket vs REST

Use WebSocket API when:

  • You need real-time updates on order status changes
  • You want to monitor multiple orders simultaneously
  • You’re building interactive UIs that require instant feedback
  • You need to react immediately to order fills or cancellations
  • You want to reduce polling overhead for order status checks

Use REST API when:

  • You need to fetch historical data or one-time queries
  • You’re performing administrative operations like creating quotes
  • You want simpler implementation for basic use cases
  • You need stateless interactions without persistent connections

Real-time Order Monitoring

The WebSocket API excels at real-time order monitoring through its event-driven architecture:
import { WebSocketApi } from '@1inch/cross-chain-sdk'

const wsSdk = new WebSocketApi({
  url: 'wss://api.1inch.com/fusion-plus/ws',
  authKey: 'your-auth-key'
})

// Monitor all order events
wsSdk.order.onOrder((data) => {
  console.log('received order event', data)
})

Key Capabilities

Order Events

Subscribe to order creation, fills, partial fills, and cancellations

State Changes

Track balance and allowance changes that affect order execution

Secret Sharing

Receive shared secrets for cross-chain order resolution

RPC Methods

Query active orders and available methods through the connection

Architecture

The WebSocket API is organized into three main components:
  • Base API (WebSocketApi) - Core connection management and low-level event handling
  • Order namespace (order.*) - Order-specific event subscriptions
  • RPC namespace (rpc.*) - Request/response methods for querying data
const ws = new WebSocketApi({ url: 'wss://api.1inch.com/fusion-plus/ws' })

// Base methods
ws.onOpen(() => console.log('Connected'))
ws.onError((error) => console.error('Error:', error))

// Order events
ws.order.onOrderCreated((data) => { /* handle creation */ })
ws.order.onOrderFilled((data) => { /* handle fill */ })

// RPC methods
ws.rpc.getActiveOrders()
ws.rpc.onGetActiveOrders((orders) => console.log(orders))

Next Steps

Setup

Learn how to establish WebSocket connections

Events

Explore available events and their data structures

Build docs developers (and LLMs) love