raydium-io/raydium-sdk

How to subscribe on pool reserves changes?

hurek opened this issue · 2 comments

Hello! Is it possible to subscribe on pool reserves changes via websocket and calculate real-time prices?

@hurek I think you can listen to the logs of the raydium amm programm and check the instructions to have GetPoolInfo with data for your specific pool. That's how Liquidity.fetchInfo works in raydium-sdk, they fetch the program logs and extract the data from there.

https://github.com/raydium-io/raydium-sdk/blob/master/src/liquidity/liquidity.ts#L1988C1-L1993C1
https://github.com/raydium-io/raydium-sdk/blob/master/src/common/web3.ts#L278

Here is a helpful comment in other thread with an example on how it could be done:
#42 (comment)

@shtelzerartem What about onProgramAccountChange() with Raydium_v4 pubkey as input? I suppose we can use LiquidityState layout to decode accountInfo.data and get baseReserve quoteReserve isn't it?

What is faster - listen the raydium accounts change or logs?