StaticinitInitialize a Surge instance with a gateway
Configuration parameters
The API key for authentication
Gateway URL string or Gateway instance
Optionalverbose?: booleanWhether to enable verbose logging (defaults to false)
A new Surge instance
// Using a gateway URL string
const surge = Surge.init({
apiKey: "sb_live_...",
gateway: "https://gateway.switchboard.xyz",
verbose: true
});
// Using a Gateway object
const gateway = await queue.fetchGatewayFromCrossbar(crossbar);
const surge = Surge.init({
apiKey: "sb_live_...",
gateway: gateway,
});
Connect to the gateway and authenticate
OptionalfeedHints: FeedSubscription[]Optional feeds for oracle selection (oracle mode only)
Subscribe to feeds
OptionalbatchIntervalMs: numberValidate that feeds exist and sources are available before attempting to subscribe
Array of feed subscriptions to validate
Internal retry counter (defaults to 0)
Connect to gateway and subscribe to feeds in one operation with proper error handling This is the recommended method for most use cases as it validates feeds before any connection attempts
Array of feed subscriptions
OptionalbatchIntervalMs: numberSubscribe to all available feeds with optional source filtering
Optionalsources_: Source[]OptionalbatchIntervalMs: numberCheck if a specific feed exists
The symbol to check (e.g., "BTC/USD")
Optionalsource: string | SourceOptional source to check (e.g., Source.WEIGHTED)
true if the feed exists
Get available feeds for a specific symbol
The symbol to query (e.g., "BTC/USD")
The feed data for this symbol, or null if not found
Disconnect from the gateway
Get current connection state
Get list of active subscriptions
Surge - WebSocket streaming client for Switchboard On-Demand feeds
Provides real-time streaming of price updates with automatic processing into Solana transaction instructions. Supports both direct symbol/source subscriptions and feedHash-based subscriptions with automatic detection and conversion.
Example