-
Notifications
You must be signed in to change notification settings - Fork 44
Add a verbose callback with access to solana account data #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,15 @@ import { PythConnection } from './PythConnection' | |
import { getPythClusterApiUrl, getPythProgramKeyForCluster, PythCluster } from './cluster' | ||
import { PriceStatus } from '.' | ||
|
||
const SOLANA_CLUSTER_NAME: PythCluster = 'mainnet-beta' | ||
const SOLANA_CLUSTER_NAME: PythCluster = 'devnet' | ||
const connection = new Connection(getPythClusterApiUrl(SOLANA_CLUSTER_NAME)) | ||
const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME) | ||
|
||
const pythConnection = new PythConnection(connection, pythPublicKey) | ||
pythConnection.onPriceChange((product, price) => { | ||
pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { | ||
// The arguments to the callback include solana account information / the update slot if you need it. | ||
const product = productAccount.accountInfo.data.product; | ||
const price = priceAccount.accountInfo.data; | ||
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we also wanna keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think most people will prefer the verbose function (because you almost always need the account keys), hence why i used that in the example. |
||
// sample output: | ||
// SRM/USD: $8.68725 ±$0.0131 | ||
if (price.price && price.confidence) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by: this example fails when pointed to mainnet because the default solana mainnet RPC endpoint no longer accepts program subscribe calls.