0

I'm trying to get liquidity data from nasty nested panckaswap data, getting undefined or errors as value not he pairs is not matching data formats for axios/react

const lpPairs = await axios.get('https://api.pancakeswap.info/api/v2/pairs');
    
const DripTokenLP = '0x20f663CEa80FaCE82ACDFA3aAE6862d246cE0333_0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'
    
const lpPairsData = lpPairs?.data?.DripTokenLP?.liquidity;

And here is the sample of API response

{"updated_at":1662271588187,"data":{"0x55d398326f99059fF775485246999027B3197955_0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56":{"pair_address":"0x7EFaEf62fDdCCa950418312c6C91Aef321375A00","base_name":"Tether USD","base_symbol":"USDT","base_address":"0x55d398326f99059fF775485246999027B3197955","quote_name":"BUSD Token","quote_symbol":"BUSD","quote_address":"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","price":"0.99885282225728147407","base_volume":"3295681.36369702704157509418","quote_volume":"3297002.3943221676348452541","liquidity":"191329534.7899682426902966934735","liquidity_BNB":"687878.683701821324819656047896"},"0x20f663CEa80FaCE82ACDFA3aAE6862d246cE0333_0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56":{"pair_address":"0xa0feB3c81A36E885B6608DF7f0ff69dB97491b58","base_name":"DRIP Token","base_symbol":"DRIP","base_address":"0x20f663CEa80FaCE82ACDFA3aAE6862d246cE0333","quote_name":"BUSD Token","quote_symbol":"BUSD","quote_address":"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","price":"7.21846457833251119606","base_volume":"10485.867846203786025893999994","quote_volume":"75646.0569503976571106049996","liquidity":"8262178.77851145262116144193549","liquidity_BNB":"29704.03386536664548463298005976"}
PiotrK
  • 357
  • 3
  • 13

1 Answers1

0

I found the answer in the meantime

const DripTokenLP = "0x20f663CEa80FaCE82ACDFA3aAE6862d246cE0333_0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56";
    
    const [resp] = await Promise.all([
        axios.get("https://api.pancakeswap.info/api/v2/pairs"),
      ]);
  
      const { liquidity } = resp.data.data[DripTokenLP];
PiotrK
  • 357
  • 3
  • 13