From 1904505234640404cca6164e59e83ccd622542f5 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 10:21:50 +0900 Subject: [PATCH] add support for maxLatency --- package.json | 2 +- src/example_ws_single_feed.ts | 6 +++--- src/index.ts | 18 +++++++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f23a0a9..8c9983d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/client", - "version": "2.19.0", + "version": "2.20.0", "description": "Client for consuming Pyth price data", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/src/example_ws_single_feed.ts b/src/example_ws_single_feed.ts index 75c089d..028f87f 100644 --- a/src/example_ws_single_feed.ts +++ b/src/example_ws_single_feed.ts @@ -7,7 +7,7 @@ const connection = new Connection(getPythClusterApiUrl(PYTHNET_CLUSTER_NAME)) const pythPublicKey = getPythProgramKeyForCluster(PYTHNET_CLUSTER_NAME) // This feed ID comes from this list: https://pyth.network/developers/price-feed-ids#solana-mainnet-beta // This example shows Crypto.SOL/USD -const feeds = [new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')] +const feeds = [new PublicKey('HD7fKr26unn2521YNNKeV7o45c4qzpzbNMceg2NCysE1')] const pythConnection = new PythConnection(connection, pythPublicKey, 'confirmed', feeds) pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { @@ -16,9 +16,9 @@ pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { const price = priceAccount.accountInfo.data // sample output: // SOL/USD: $14.627930000000001 ±$0.01551797 - if (price.price && price.confidence) { + if (price.price && price.confidence && price.status === PriceStatus.Trading) { // tslint:disable-next-line:no-console - console.log(`${product.symbol}: $${price.price} \xB1$${price.confidence}`) + console.log(`${price.timestamp} ${product.symbol}: $${price.aggregate.price} $${price.aggregate.priceComponent} \xB1$${price.confidence}`) } else { // tslint:disable-next-line:no-console console.log(`${product.symbol}: price currently unavailable. status is ${PriceStatus[price.status]}`) diff --git a/src/index.ts b/src/index.ts index 64bf9bd..5cef564 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,7 +103,8 @@ export interface PriceData extends Base { emaConfidence: Ema timestamp: bigint minPublishers: number - drv2: number + messageSent: number + maxLatency: number drv3: number drv4: number productAccountKey: PublicKey @@ -285,10 +286,12 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData => const timestamp = readBigInt64LE(data, 96) // minimum number of publishers for status to be TRADING const minPublishers = data.readUInt8(104) + // message sent flag + const messageSent = data.readUInt8(105) + // configurable max latency in slots between send and receive + const maxLatency = data.readUInt8(106) // space for future derived values - const drv2 = data.readInt8(105) - // space for future derived values - const drv3 = data.readInt16LE(106) + const drv3 = data.readInt8(107) // space for future derived values const drv4 = data.readInt32LE(108) // product id / reference account @@ -350,7 +353,8 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData => emaConfidence, timestamp, minPublishers, - drv2, + messageSent, + maxLatency, drv3, drv4, productAccountKey, @@ -394,5 +398,5 @@ export const parsePermissionData = (data: Buffer): PermissionData => { export { PythConnection } from './PythConnection' export { PythHttpClient } from './PythHttpClient' -export { getPythProgramKeyForCluster, PythCluster, getPythClusterApiUrl } from './cluster' -export { pythOracleProgram, pythOracleCoder, pythIdl } from './anchor' +export { pythIdl, pythOracleCoder, pythOracleProgram } from './anchor' +export { PythCluster, getPythClusterApiUrl, getPythProgramKeyForCluster } from './cluster'