@drift-labs/sdk
Version:
SDK for Drift Protocol
92 lines • 4.36 kB
TypeScript
/// <reference types="node" />
import { Channel, PriceFeedProperty } from '@pythnetwork/pyth-lazer-sdk';
import { DriftEnv } from '../config';
/**
* Configuration for a group of Pyth Lazer price feeds.
*/
export type PythLazerPriceFeedArray = {
/** Optional channel for update frequency (e.g., 'fixed_rate@200ms') */
channel?: Channel;
/** Array of Pyth Lazer price feed IDs to subscribe to */
priceFeedIds: number[];
};
/**
* Manages subscriptions to Pyth Lazer price feeds and provides access to real-time price data.
* Automatically filters out non-stable feeds and handles reconnection logic.
*/
export declare class PythLazerSubscriber {
private endpoints;
private token;
private priceFeedArrays;
private resubTimeoutMs;
private sdkLogging;
private static readonly SYMBOLS_API_URL;
private symbolsCache;
private pythLazerClient?;
feedIdChunkToPriceMessage: Map<string, string>;
feedIdToPrice: Map<number, number>;
feedIdHashToFeedIds: Map<string, number[]>;
subscriptionIdsToFeedIdsHash: Map<number, string>;
allSubscribedIds: number[];
timeoutId?: NodeJS.Timeout;
receivingData: boolean;
isUnsubscribing: boolean;
marketIndextoPriceFeedIdChunk: Map<number, number[]>;
marketIndextoPriceFeedId: Map<number, number>;
private readonly feedProperties;
/**
* Creates a new PythLazerSubscriber instance.
* @param endpoints - Array of WebSocket endpoint URLs for Pyth Lazer
* @param token - Authentication token for Pyth Lazer API
* @param priceFeedArrays - Array of price feed configurations to subscribe to
* @param env - Drift environment (mainnet-beta, devnet, etc.)
* @param resubTimeoutMs - Milliseconds to wait before resubscribing on data timeout
* @param sdkLogging - Whether to log Pyth SDK logs to the console. This is very noisy but could be useful for debugging.
* @param feedProperties - Price feed properties to request. Must include both 'price' and 'exponent' (required for getPriceFromMarketIndex). Defaults to ['price', 'bestAskPrice', 'bestBidPrice', 'exponent']. Stored by copy so caller mutation does not affect this instance.
*/
constructor(endpoints: string[], token: string, priceFeedArrays: PythLazerPriceFeedArray[], env?: DriftEnv, resubTimeoutMs?: number, sdkLogging?: boolean, feedProperties?: PriceFeedProperty[]);
private fetchSymbolsIfNeeded;
private filterStableFeeds;
/**
* Subscribes to Pyth Lazer price feeds. Automatically filters out non-stable feeds
* and establishes WebSocket connections for real-time price updates.
*/
subscribe(): Promise<void>;
protected setTimeout(): void;
/**
* Unsubscribes from all Pyth Lazer price feeds and closes WebSocket connections.
*/
unsubscribe(): Promise<void>;
hash(arr: number[]): string;
/**
* Retrieves the latest Solana-format price message for a group of feed IDs.
* @param feedIds - Array of price feed IDs
* @returns Hex-encoded price message data, or undefined if not available
*/
getLatestPriceMessage(feedIds: number[]): Promise<string | undefined>;
/**
* Retrieves the latest Solana-format price message for a specific market.
* @param marketIndex - The market index to get price data for
* @returns Hex-encoded price message data, or undefined if not found
*/
getLatestPriceMessageForMarketIndex(marketIndex: number): Promise<string | undefined>;
/**
* Gets the array of price feed IDs associated with a market index.
* @param marketIndex - The market index to look up
* @returns Array of price feed IDs, or empty array if not found
*/
getPriceFeedIdsFromMarketIndex(marketIndex: number): number[];
/**
* Gets the array of price feed IDs from a subscription hash.
* @param hash - The subscription hash
* @returns Array of price feed IDs, or empty array if not found
*/
getPriceFeedIdsFromHash(hash: string): number[];
/**
* Gets the current parsed price for a specific market index.
* @param marketIndex - The market index to get the price for
* @returns The price as a number, or undefined if not available
*/
getPriceFromMarketIndex(marketIndex: number): number | undefined;
}
//# sourceMappingURL=pythLazerSubscriber.d.ts.map