gauss314 / defi

Tools for use in DeFi. Impermanent Loss calculations, staking and farming strategies, coingecko and pancakeswap API queries, liquidity pools and more
MIT License
554 stars 143 forks source link

Add function for get LP token value #1

Open ranamalo opened 3 years ago

ranamalo commented 3 years ago

I think this would be a great addition to what you have already built here. Perhaps there is a way to calculate this from the 'pcsPairInfo'? I usually calculate it from manually looking at the contract and dividing the total LP value by the total token supply, so being able to look up a contract from address would work too. These contract addresses aren't available from "https://api.pancakeswap.info/api/tokens" as far as I know.

gauss314 commented 3 years ago

The total pool liquidity and the token prices are available, but the pancake API does not provide information on the amount of LP, maybe they will add this info now that they have updated to the V2 of their pools but it's not available yet

ranamalo commented 3 years ago

Are you referring to the "price" available from https://api.pancakeswap.info/api/v2/pairs? If so, that price appears to just be the quote_volume / base_volume and doesn't seem to give the value of the LP token, which would be what I described above.

There is also https://api.pancakeswap.info/api/v2/tokens/

that has a "price" but doesn't appear to work for LP contracts. At least the three I tried.