Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API to get price of Binance Smart Chain token on PancakeSwap

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.

like image 574
dps Avatar asked Apr 01 '21 11:04

dps


People also ask

Is there an API for PancakeSwap?

The PancakeSwap API is a set of endpoints used by market aggregators (e.g. coinmarketcap.com) to surface PancakeSwap liquidity and volume information. All information is fetched from the underlying subgraphs.


Video Answer


2 Answers

Here is a way to get it directly from PancakeSwap

https://api.pancakeswap.info/api/v2/tokens/0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3
like image 98
TheDayIsDone Avatar answered Oct 13 '22 00:10

TheDayIsDone


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.

like image 42
Mendoza Avatar answered Oct 13 '22 02:10

Mendoza