forked from pyth-network/pyth-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_http_usage.ts
25 lines (20 loc) · 946 Bytes
/
example_http_usage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Connection } from '@solana/web3.js'
import { PriceStatus, PythHttpClient, getPythClusterApiUrl, getPythProgramKeyForCluster, PythCluster } from '.'
const PYTHNET_CLUSTER_NAME: PythCluster = 'pythnet'
const connection = new Connection(getPythClusterApiUrl(PYTHNET_CLUSTER_NAME))
const pythPublicKey = getPythProgramKeyForCluster(PYTHNET_CLUSTER_NAME)
async function runQuery(): Promise<void> {
const pythClient = new PythHttpClient(connection, pythPublicKey)
const data = await pythClient.getData()
for (const symbol of data.symbols) {
const price = data.productPrice.get(symbol)!
if (price.price && price.confidence) {
// tslint:disable-next-line:no-console
console.log(`${symbol}: $${price.price} \xB1$${price.confidence}`)
} else {
// tslint:disable-next-line:no-console
console.log(`${symbol}: price currently unavailable. status is ${PriceStatus[price.status]}`)
}
}
}
runQuery()