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.
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)
};
Is there any way to do it faster?
New contributor
Shahria Emon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.