1

We are fixing the price at the time of creating pair for our token with BNB by adding liquidity. If the Price of the BNB/BUSD. How can we fetch the current market price and update in our DEX?

Is there is any external APIs to achieve this? I am using the Pancake router contract https://testnet.bscscan.com/address/0xd99d1c33f9fc3444f8101754abc46c52416550d1.

Thanks in advance

1 Answer 1

2

You can get price of BNB/BUSD using getAmountsOut method

//one WBNB in Wei    
const oneWBNB = '1000000000000000000';
const WBNB = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
const BUSD = '0xe9e7cea3dedca5984780bafc599bd69add087d56';
const busdAmount = await routerContract.methods.getAmountsOut(oneBNB, [WBNB, BUSD]).call();
3
  • Thanks. But If the BNB price increases in market. Is that price will update in this contract? Jul 3, 2021 at 8:53
  • No. You need to write a function to monitor prices changes. This function will check price every N seconds and notify user about new price.
    – M M
    Jul 3, 2021 at 9:58
  • 1
    @M M Is there is any API to monitor price change? Jul 3, 2021 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.