2

Maybe my approach is wrong. I'm new to Solana dev. I'm using the Solana mainnet API and I'm trying to get the liquidity pool amounts for a given token pair on raydium. My code:

res=solana_client.get_account_info(Pubkey.from_string(pair_address),encoding='base64')
data = res.value.data

and the data I get are bytes in base64. Now I found on the raydium documentation the struct that should allow me to decode the data bytes and get various elements of which some are the liquidity amounts.

This doesn't work. I'm using Python and it seems that in Java it is easier.

I honestly don't know what to do anymore. Anyone knows how to decode the data as a response to GetAccountInfo of a given raydium pair? I just need to get historical price data for a given pair on raydium without using any external third service api.

Sorry if it's not clear enough. Thank you in advance.

1 Answer 1

0

You wont find historical data in the account info data.

If you want historical data without an API I think you would probably just use a do while loop parsing the Raydium program's transactions, and just manually calculating each tokens price for each swap transaction and storing it. Ie: find swap instruction, find which two tokens, find the transfer instructions amounts, divide the quote by the base, and that would give you the amount of quote tokens they paid per base token they received, and assuming they werent MEV'd would be the price at whichever block you find in the tx data.

As for the actual layouts of the account you're looking at you can find the mint data layout under "SPL_MINT_LAYOUT" and the associated token account data layout under "SPL_ACCOUNT_LAYOUT" in the Raydium SDK.

To decode these with python you would want to convert your base 64 into base58, then for any pubkeys if you slice the bytes of your base58 string at the relevant offsets and create a new publicKey out of it you'll get a proper result. Ie: for the owner of a token account you can take a slice of the base58 data (32, 64), create a public key with it and you have the token accounts owner. The current balance of the account is stored at bytes 64-72 and are normally endcoded as u64 (8 bytes).

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.