I need to get a price for ETH/USD and BTC/USD for the specified time. For example yesterday at 9:00 am. How can I do it in the on-chain Solana program? What oracle can be used?

I have checked the Pyth network, but it seems to work only for the last price. There is an option for historical prices, but only on Ethereum.

2 Answers 2


You can use Pyth, the GitHub example just happens to get the data for Ethereum.

There's a comment mentioning where to find other price feeds:

    // Pyth ETH/USD price account on pythnet (can be found on https://pyth.network/developers/price-feed-ids#solana-mainnet-beta which has the same price feed IDs as pythnet)
    let key = "JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB";
    let clnt = RpcClient::new(url.to_string());
    let eth_price_key = Pubkey::from_str(key).unwrap();

Replace eth_price_key with the base/quote token pairs you are interested in.

The function declarations indicate that you can find historical prices too:

    let maybe_price = eth_price_feed.get_price_no_older_than(current_time, 60);
    let maybe_ema_price = eth_price_feed.get_ema_price_no_older_than(current_time, 60);

Instead of current_time, pass in the time for yesterday at 9:00 am.

  • 1
    The get_price_no_older_than doesn't work for historical prices. It only works for the last price. I also asked on the Pyth discord and they answered that they don't support back-in-time price feeds. Feb 13 at 7:13

Until an oracle provides historical prices, and I don't know of any that do, it won't be possible to retrieve historical prices, unfortunately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.