12

I have address of a token and I need to get its price in BUSD or BNB. It's not a problem to use paid API, if there is no other way. This token may not be listed on popular listings so it would be nice to get price somehow directly from PancakeSwap.

dps
  • 764
  • 3
  • 7
  • 16

4 Answers4

4

Here is a way to get it directly from PancakeSwap

https://api.pancakeswap.info/api/v2/tokens/0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3
TheDayIsDone
  • 323
  • 5
  • 11
  • 3
    doesn't work with all tokens, try to use it with yCln 0x0997E2905CDa889Db78D030599989e3121453B6F – dps May 21 '21 at 08:15
  • + it's not live data, it is refreshed hourly. That's why scraping is the only solution ;) Would require an headless chromium for doing so – Romain-p Jan 18 '22 at 15:14
  • 3
    @TheDayIsDone This just stopped working... any idea? I see `{"error":{"code":500,"message":"Network error: Unexpected token i in JSON at position 0"}}` – WebMW Feb 10 '23 at 09:18
2

A friend of mine used Moralis. https://docs.moralis.io/introduction/readme https://docs.moralis.io/moralis-dapp/web3-api/token#gettokenprice

Maybe you can already do something with the documentation, I have otherwise asked my colleague for example code

curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/erc20/0x42F6f551ae042cBe50C739158b4f0CAC0Edb9096/price?chain=bsc&exchange=PancakeSwapv2' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'

Result:

{
  "nativePrice": {
    "value": "8409770570506626",
    "decimals": 18,
    "name": "Ether",
    "symbol": "ETH"
  },
  "usdPrice": 19.722370676,
  "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
  "exchangeName": "Uniswap v3"
}

Greetings.

Mendoza
  • 101
  • 1
  • 5
  • Thank you @Mendoza. Next thing I would need is to fetch the price at a certain date, if possible. – Tulleb May 03 '22 at 15:03
  • 1
    @Tulleb A direct API query is not possible as far as I know, but you can query the price if you specify the parameter `to_block` to get the price for a specific date , But I don't know how to find the right block for the date, sorry :/ – Mendoza May 03 '22 at 16:13
0

Alternatively, if you are using React you can try the following package: react-pancakeswap-token-price

Nightcrawler
  • 943
  • 1
  • 11
  • 32
-2

you can scrape charts.bogged.finance or poocoin.app

Romain-p
  • 518
  • 2
  • 9
  • 26