Hello,
I am developping a project, on Solana, where I am using the XAU:USD sponsored price feed.
Since gold is not quoted during week-ends, what is the right way to handle that in the Program?
I would like to get the last known price (with price feed id and shard), without checking it’s age (maybe conditionaly, based on the “market hours”) :
Metals From Sunday 6PM ET to Friday 5PM ET Daily maintenance window applies from 5PM ET to 6PM ET, Monday to Thursday. Spot gold and silver trading also follow CME holiday closures
For now, I am asking for a recent price, and if the provided price is not recent I am falling back to the sponsored price feed in shard 0. Is that a good way to proceed?
Here is my snippet:
let ref_price = ctx.accounts.ref_price_update().get_price_no_older_than(&Clock::get()?, MAX_AGE, &ref_feed_id)
.or_else(|_| {
// Check that the price feed account is the one expected from shard 0.
let expected_feed = Pubkey::from_str("2uPQGpm8X4ZkxMHxrAW1QuhXcse1AHEgPih6Xp9NuEWW")
.expect("Invalid fallback feed key");
msg!("Price feed is stale; using only fallback price (Shard 0).");
require!(ctx.accounts.ref_price_update().key() == expected_feed, MyError::InvalidPriceFeed);
Ok::<Price, anchor_lang::error::Error>(Price {
price: ctx.accounts.ref_price_update().price_message.price,
conf: ctx.accounts.ref_price_update().price_message.conf,
exponent: ctx.accounts.ref_price_update().price_message.exponent,
publish_time: ctx.accounts.ref_price_update().price_message.publish_time,
})
})?;
Thank you in advance ! ![]()