Currently, I am fetching all liquidity-related data from Raydium API. (https://api.raydium.io/v2/sdk/liquidity/mainnet.json) And then matching with my desired token address to filter the right PoolKeys. But this process is taking too much time. Is there any way to do it faster?
Here is my code snippet
// Pass both token addresses (mint), and it will return the data of the pool of those tokens.
const getPoolKeys = async (tokenA, tokenB) => {
const liquidityJsonResp = await fetch(liquidityFile);
if (!liquidityJsonResp.ok) return
const liquidityJson = await liquidityJsonResp.json()
const allPoolKeysJson = [...(liquidityJson?.official ?? []), ...(liquidityJson?.unOfficial ?? [])]
const poolData = allPoolKeysJson.find(
(i) => (i.baseMint === tokenA && i.quoteMint === tokenB) || (i.baseMint === tokenB && i.quoteMint === tokenA)
)
if (!poolData) return null
return jsonInfo2PoolKeys(poolData)
};