Documentation Index Fetch the complete documentation index at: https://mintlify.com/1inch/cross-chain-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The WebSocket API provides RPC methods for querying order data and server status through the rpc namespace.
Available Methods
enum RpcMethod {
GetAllowedMethods = 'getAllowedMethods' ,
Ping = 'ping' ,
GetActiveOrders = 'getActiveOrders' ,
GetSecrets = 'getSecrets'
}
ping
Health check to verify server connectivity.
Usage
Response Handler
ws . rpc . onPong (( timestamp : string ) => {
console . log ( 'Pong received at:' , timestamp )
})
Example
import { WebSocketApi } from '@1inch/cross-chain-sdk'
const ws = new WebSocketApi ({
url: 'wss://api.1inch.com/fusion-plus/ws' ,
authKey: 'your-auth-key'
})
// Set up pong handler
ws . rpc . onPong (( timestamp ) => {
console . log ( 'Server responded:' , timestamp )
})
// Send ping every 30 seconds
setInterval (() => {
ws . rpc . ping ()
}, 30000 )
getAllowedMethods
Retrieves the list of RPC methods supported by the server.
Usage
ws . rpc . getAllowedMethods ()
Response Handler
ws . rpc . onGetAllowedMethods (( methods : RpcMethod []) => {
console . log ( 'Allowed methods:' , methods )
})
Example
ws . rpc . onGetAllowedMethods (( methods ) => {
console . log ( 'Server supports:' , methods . join ( ', ' ))
// Check if specific method is supported
if ( methods . includes ( RpcMethod . GetActiveOrders )) {
console . log ( 'GetActiveOrders is supported' )
}
})
ws . rpc . getAllowedMethods ()
getActiveOrders
Retrieves currently active orders.
Usage
Response Handler
ws . rpc . onGetActiveOrders (( response : PaginationOutput < ActiveOrder >) => {
console . log ( `Total: ${ response . meta . totalItems } ` )
response . items . forEach ( order => {
console . log ( `Order: ${ order . orderHash } ` )
})
})
Response Structure
Array of active orders Show ActiveOrder structure
Pagination metadata Total number of active orders
Number of items in current page
Example
ws . rpc . onGetActiveOrders (( response ) => {
console . log ( `Active orders: ${ response . meta . totalItems } ` )
console . log ( `Current page: ${ response . meta . currentPage } / ${ response . meta . totalPages } ` )
response . items . forEach ( order => {
console . log ( ` \n Order: ${ order . orderHash } ` )
console . log ( ` From: ${ order . srcChainId } → ${ order . dstChainId } ` )
console . log ( ` Created: ${ order . createDateTime } ` )
console . log ( ` Quote: ${ order . quoteId } ` )
})
})
ws . rpc . getActiveOrders ()
getSecrets
Retrieves published secrets for an order.
Usage
// Note: This method may require order hash parameter
ws . rpc . getSecrets ()
Complete Example
import { WebSocketApi , RpcMethod } from '@1inch/cross-chain-sdk'
const ws = new WebSocketApi ({
url: 'wss://api.1inch.com/fusion-plus/ws' ,
authKey: 'your-auth-key'
})
ws . onOpen (() => {
console . log ( 'Connected' )
// Check server capabilities
ws . rpc . getAllowedMethods ()
// Health check
ws . rpc . ping ()
// Get active orders
ws . rpc . getActiveOrders ()
})
// Handle responses
ws . rpc . onGetAllowedMethods (( methods ) => {
console . log ( 'Server supports:' , methods )
})
ws . rpc . onPong (( timestamp ) => {
console . log ( 'Pong:' , timestamp )
})
ws . rpc . onGetActiveOrders (( response ) => {
console . log ( `Found ${ response . items . length } active orders` )
response . items . forEach (( order , idx ) => {
console . log ( ` ${ idx + 1 } . ${ order . orderHash } ` )
})
})
Periodic Monitoring
const ws = new WebSocketApi ({
url: 'wss://api.1inch.com/fusion-plus/ws' ,
authKey: 'your-auth-key'
})
// Ping server every 30 seconds
setInterval (() => {
ws . rpc . ping ()
}, 30000 )
// Refresh active orders every minute
setInterval (() => {
ws . rpc . getActiveOrders ()
}, 60000 )
// Handle pong
ws . rpc . onPong (() => {
console . log ( 'Server is alive' )
})
// Handle active orders
ws . rpc . onGetActiveOrders (( response ) => {
console . log ( `Active orders: ${ response . meta . totalItems } ` )
})
Error Handling
ws . onError (( error ) => {
console . error ( 'WebSocket error:' , error )
})
ws . onClose (() => {
console . log ( 'Connection closed' )
})
// Request methods only when connected
ws . onOpen (() => {
ws . rpc . ping ()
ws . rpc . getActiveOrders ()
})
Notes
RPC methods require an active WebSocket connection. Set up response handlers before sending requests.
Responses are asynchronous. Use the corresponding on* handler to receive the response.
Not all RPC methods may be available on all servers. Use getAllowedMethods() to check capabilities.