Skip to content
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

Cannot fetch price data using OracleAccount #52

Open
gabrielfior opened this issue Aug 8, 2022 · 3 comments
Open

Cannot fetch price data using OracleAccount #52

gabrielfior opened this issue Aug 8, 2022 · 3 comments

Comments

@gabrielfior
Copy link

Following the example available on test_oracle (https://github.com/switchboard-xyz/switchboard-v2/blob/main/libraries/py/tests/test_oracle.py), I tried executing the code in a Jupyter notebook but obtained the following problem:

provider = Provider(client, Wallet(Keypair()))
program = await Program.at(SBV2_DEVNET_PID, provider)
oracle = OracleAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))

# getting aggregator data
data = await oracle.load_data()
---------------------------------------------------------------------------
AccountInvalidDiscriminator               Traceback (most recent call last)
Input In [34], in <cell line: 6>()
      3 oracle = OracleAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))
      5 # getting aggregator data
----> 6 data = await oracle.load_data()

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/oracle.py:89, in OracleAccount.load_data(self)
     88 async def load_data(self):
---> 89     return await OracleAccountData.fetch(self.program.provider.connection, self.public_key)

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/generated/accounts/oracle_account_data.py:66, in OracleAccountData.fetch(cls, conn, address, commitment)
     64     raise ValueError("Account does not belong to this program")
     65 bytes_data = b64decode(info["data"][0])
---> 66 return cls.decode(bytes_data)

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/generated/accounts/oracle_account_data.py:89, in OracleAccountData.decode(cls, data)
     86 @classmethod
     87 def decode(cls, data: bytes) -> "OracleAccountData":
     88     if data[:ACCOUNT_DISCRIMINATOR_SIZE] != cls.discriminator:
---> 89         raise AccountInvalidDiscriminator(
     90             "The discriminator for this account is invalid"
     91         )
     92     dec = OracleAccountData.layout.parse(data[ACCOUNT_DISCRIMINATOR_SIZE:])
     93     return cls(
     94         name=dec.name,
     95         metadata=dec.metadata,
   (...)
    102         ebuf=dec.ebuf,
    103     )

AccountInvalidDiscriminator: The discriminator for this account is invalid

Any help very much appreciated.

@gallynaut
Copy link
Contributor

@gabrielfior Hey sorry I missed this

The account 88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz isnt an Oracle account. It's an AggregatorAccountData (or better known as a data feed).

Check out the switchboard CLI for help working with accounts. npm i -g @switchboard-xyz/switchboardv2-cli

Then you can run sbv2 print 88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz and it will output the account type and deserialized data

@gabrielfior
Copy link
Author

Thanks @gallynaut for the reply. I followed your suggestion and got interesting info from the 88FX4... account:

gabri@DESKTOP-P7TT9ED:~/solana-analytics-101/node_scripts$ npx sbv2 print 88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz
############ DEVNET ############
## Aggregator           88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz
latestResult            180.12115 (2021-12-17 07:20:30 L)
name                    SOL / USD

So I recognize that this account 88FX... corresponds to a SOL/USD data feed. Can you please point me to the addresses of the data feeds? Or even better, can I retrieve a list of addresses through the library?

@anoushk1234
Copy link

Thanks @gallynaut for the reply. I followed your suggestion and got interesting info from the 88FX4... account:

gabri@DESKTOP-P7TT9ED:~/solana-analytics-101/node_scripts$ npx sbv2 print 88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz
############ DEVNET ############
## Aggregator           88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz
latestResult            180.12115 (2021-12-17 07:20:30 L)
name                    SOL / USD

So I recognize that this account 88FX... corresponds to a SOL/USD data feed. Can you please point me to the addresses of the data feeds? Or even better, can I retrieve a list of addresses through the library?

You could try to load the program and call getProgramAccounts to get all the feed accounts but that would be very so you can use the aleph indexer api https://official.aleph.cloud/api/v0/posts.json?types=BUNDLE&pagination=200&page=2&tags=b5bfc7b2-4668-4f65-8ac5-8d12505ebab4 to load them. These are also visible on the switchboard dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants