Skip to content

Commit

Permalink
add support for maxLatency
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Feb 27, 2024
1 parent 8c24cfc commit 1904505
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/example_ws_single_feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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]}`)
Expand Down
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -350,7 +353,8 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData =>
emaConfidence,
timestamp,
minPublishers,
drv2,
messageSent,
maxLatency,
drv3,
drv4,
productAccountKey,
Expand Down Expand Up @@ -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'

0 comments on commit 1904505

Please sign in to comment.