0

By looking at pyth.network's website, We can see upto 1Months worth of historical prices, I don't know if this is onchain or offchain, but it means that the data is somewhere. I am mainly looking for onchain data though.

enter image description here

I will like to pull specifically the price of a basket of ticker symbols on a specific timestamp or a specific slot #.

Thanks all.

2 Answers 2

1

Yes, if you head over to Pyth's Price Feed page (for example, BTC/USD) you can pull the transaction history for any given Publisher to build a historical price chart. Each transaction includes the price of the asset as well as the publish time slot.

Below is an image of an inner instruction of one of the transactions by the AGaSHpDpyveuLyiaocNXMMFCf1LCBBynyaKMJkL8AKK4 BTC/USD Publisher.

4

Transaction history can be pulled pretty simply using the JS API. This is the @solana/web3.js package.

const { 
    Connection, 
    clusterApiUrl,
    PublicKey,
} = require("@solana/web3.js");

// The Publisher
const PUBLISHER_KEY = new PublicKey(
    "AGaSHpDpyveuLyiaocNXMMFCf1LCBBynyaKMJkL8AKK4"
);

// Start a new Connection.
const connection = new Connection(clusterApiUrl("mainnet-beta"));

// To circumvent the restriction of not being able
// to run top-level await.
const run = async () => {

    // The limit of signatures of 1,000. You might need to
    // paginate your request by using the before or until
    // parameters.
    const result = await connection.getConfirmedSignaturesForAddress2(
        PUBLISHER_KEY
    );

    // The structure of the result will be an array containing
    // objects with keys blockTime, confirmationStatus, err,
    // memo, signature, and slot. We just want the signatures.
    const signatures = result.map(i => i.signature);

    // Now we can fetch the transaction details for each
    // transaction signature. The limit here isn't specified
    // but I believe it is 250. You will need to split your
    // array of 1,000 signatures into 4 blocks to do this.
    return await connection.getParsedTransactions(
        signatures.slice(0, 250)
    );

};

// Run and show result.
run().then(result => console.dir(result, { depth: null }));

Then you can dive into each object to see where the information is stored (should be an inner instruction).

Note that transaction history isn't stored for long on Solana's native RPC endpoints. They're also quick to fire 429s back at you. You might need to use something like QuickNode, Alchemy, or GenesysGo.

3
  • Can you please point me to some docs, or a sample code showing how to pull this data? Thanks Commented Jul 24, 2022 at 10:50
  • @CyrialKamda sure, I'll update my original answer Commented Jul 24, 2022 at 17:58
  • Thanks alot for the answer, but I was looking more to intergrate it with my program in a trustless fashion, and I needed something onchain instead. Is that possible? Commented Jul 24, 2022 at 20:07
0

The example chart shown is most probably made from indexed, off-chain data (only on-chain possibility would be a storage on-chain solution, think shadow drive, areweave, filecoin).

This seems to be the team's example for an on-chain example. Basic idea is:

  • pass the price feed account for the asset you need (1 asset <=> 1 account),
  • deserialize it exactly as shown in the example

However this only returns the current state. If the question is concerned with historical price data on-chain, then afaik there is no such thing available.

2
  • So, We Were able to utilize the guys at switchboard.xyz. they had a historical datafeed that we could pull historical prices for specific timestamps. Commented Jul 26, 2022 at 13:26
  • Are you saying that my knowledge is incomplete?? jk, great to hear. It would be great if you could post an answer giving some basics/details on that solution, even if it's your own post. Then I'll edit mine to point to it, and you can mark yours as "correct".
    – man0s
    Commented Jul 26, 2022 at 13:59

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.