WebSocket Subscriptions
Methods
Method
Description
Signer
Usage
Monitor Orders and Prices
import { ethers } from 'ethers';
import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';
const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
const client = new ThetanutsClient({ chainId: 8453, provider });
// 1. Open the connection
await client.ws.connect();
// 2. Subscribe to order book updates
const unsubOrders = client.ws.subscribeOrders((update) => {
console.log(`Order ${update.event}:`, update);
});
// 3. Subscribe to ETH price updates
const unsubPrices = client.ws.subscribePrices((update) => {
console.log(`ETH price: $${update.price}`);
}, 'ETH');
// 4. Monitor connection state
const unsubState = client.ws.onStateChange((state) => {
console.log(`WebSocket state: ${state}`);
// state: 'connecting' | 'connected' | 'disconnecting' | 'disconnected'
});
// 5. Clean up when done
unsubOrders();
unsubPrices();
unsubState();
client.ws.disconnect();Generic subscribe()
Reconnection Behavior
Checking Connection State
Configuration
See Also
Last updated

