WebSocketApi class provides real-time connectivity to the 1inch Fusion Mode WebSocket API for streaming order events and performing RPC calls.
Constructor
Creates a new WebSocket API instance.Configuration object or custom WebSocket provider
WebSocket endpoint URL (e.g.,
wss://api.1inch.dev/fusion/ws)Network to connect to (e.g.,
NetworkEnum.ETHEREUM)Authentication key for API access
Defer connection until
init() is called (default: false)Static Methods
new
Alternative factory method for creating a WebSocket API instance.Base Methods
init
Manually initializes the WebSocket connection (whenlazyInit: true).
on
Subscribes to a WebSocket event.Event name to subscribe to
Callback function to handle the event
off
Unsubscribes from a WebSocket event.Event name to unsubscribe from
Callback function to remove
onOpen
Subscribes to the connection open event.Callback function called when connection opens
onMessage
Subscribes to incoming messages.Callback function to handle messages
onClose
Subscribes to the connection close event.Callback function called when connection closes
onError
Subscribes to error events.Callback function to handle errors
send
Sends a message through the WebSocket connection.Message to send (will be JSON serialized)
close
Closes the WebSocket connection.Order Namespace
Theorder namespace provides methods for subscribing to order-related events.
onOrder
Subscribes to all order events.Callback function receiving order events
onOrderCreated
Subscribes to order creation events.Callback function receiving
order_created eventsorderHash- Order hashsignature- Order signatureorder- Order structuredeadline- Order deadlineauctionStartDate- Auction start timestampauctionEndDate- Auction end timestampremainingMakerAmount- Remaining maker amount
onOrderInvalid
Subscribes to order invalidation events.Callback function receiving
order_invalid eventsorderHash- Order hash that became invalid
onOrderBalanceOrAllowanceChange
Subscribes to balance or allowance change events.Callback function receiving
order_balance_or_allowance_change eventsorderHash- Order hashremainingMakerAmount- Remaining maker amountbalance- Current balanceallowance- Current allowance
onOrderFilled
Subscribes to order filled events.Callback function receiving
order_filled eventsorderHash- Order hash that was filled
onOrderFilledPartially
Subscribes to partial fill events.Callback function receiving
order_filled_partially eventsorderHash- Order hashremainingMakerAmount- Amount remaining after partial fill
onOrderCancelled
Subscribes to order cancellation events.Callback function receiving
order_cancelled eventsorderHash- Order hash that was cancelled
RPC Namespace
Therpc namespace provides methods for making RPC calls and receiving responses.
ping
Sends a ping request for health checking.onPong
Subscribes to ping responses.Callback function receiving pong responses
getAllowedMethods
Requests the list of allowed RPC methods.onGetAllowedMethods
Subscribes to allowed methods responses.Callback function receiving the list of allowed methods
getActiveOrders
Requests the list of active orders via WebSocket.onGetActiveOrders
Subscribes to active orders responses.Callback function receiving active orders data
Types
OrderEventType
Union type of all order events:OrderCreatedEvent- Order createdOrderInvalidEvent- Order became invalidOrderBalanceOrAllowanceChangeEvent- Balance or allowance changedOrderFilledEvent- Order fully filledOrderFilledPartiallyEvent- Order partially filledOrderCancelledEvent- Order cancelled
RpcMethod
Allowed RPC methods:getAllowedMethodsping