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.

const surge = new Surge({
apiKey: "sb_live_...",
network: "mainnet"
});

// Subscribe to symbol/source pairs
await surge.subscribe([
{ symbol: "BTCUSDT", source: "BINANCE" },
{ symbol: "ETHUSDT", source: "WEIGHTED" }
]);

surge.on('update', (response: SwitchboardOracleResponse) => {
console.log('Raw:', response.getRawResponse());
console.log('Formatted prices:', response.getFormattedPrices());
});

Hierarchy

  • EventEmitter
    • Surge

Constructors

Methods

  • Validate that feeds exist and sources are available before attempting to subscribe

    Parameters

    • feeds: FeedSubscription[]

      Array of feed subscriptions to validate

    • retryCount: number = 0

      Internal retry counter (defaults to 0)

    Returns Promise<void>

    Error if any feed is invalid with descriptive message after retries

  • 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

    Parameters

    • feeds: FeedSubscription[]

      Array of feed subscriptions

    • OptionalbatchIntervalMs: number

    Returns Promise<void>

    Error if validation fails, connection fails, or subscription fails

  • Check if a specific feed exists

    Parameters

    • symbol: string

      The symbol to check (e.g., "BTC/USD")

    • Optionalsource: string | Source

      Optional source to check (e.g., Source.WEIGHTED)

    Returns Promise<boolean>

    true if the feed exists