3
  1. Does PancakeSwap use the same constant product formula as Uniswap (x * y = k)? Because then I should be able to calculate a token pair exchange rate by just dividing the amount of token1 reserves by the amount of token2 reserves.

  2. Is there an API that could deliver me the wanted token pair exchange rates?

  3. Is there any other function in their contract to fetch price data from?

3
  • I am voting to close this question because this question is not about Ethereum blockchain, but it is about Binance Smart Chain and belongs to a different forum. Commented Mar 25, 2021 at 23:00
  • 2
    @Mikko Ohtamaa the Binance Smart Chain runs on the EVM like Ethereum...
    – Paulus
    Commented Mar 25, 2021 at 23:02
  • 2
    I would agree with OP. Almost all questions relating to Ethereum apply to BSC, It makes no sense to have a separate stackexchange for BSC.
    – Undead8
    Commented Mar 26, 2021 at 0:30

2 Answers 2

3

Pancake Swap uses the same formula as Uniswap, but they have a 0.2% fee instead of 0.3% fee, which affects the calculation.

3
  • I can easily find Uniswap router address online, but I am not able to find PancakeSwap router address online, I want to use the router to swap a token from my ERC20 contract. Commented Apr 28, 2021 at 14:05
  • 1
  • 2
    Please consider that they have recently migrated to V2 and therefore also created a new router and factory contract! -> New router contract: 0x10ED43C718714eb63d5aA57B78B54704E256024E -> New Factory contract: 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73
    – Paulus
    Commented Apr 30, 2021 at 14:58
1

You can try out Bitquery DexTradesByTokens API to get the token pair exchange rates on Pancake Swap.

Try this API in the Bitquery Playground, to retrieve price data for a token pair on Pancake Swap: https://ide.bitquery.io/Retrieve-price-data-from-PancakeSwap-BSC_1

API Example:

query MyQuery {
  EVM(dataset: archive, network: bsc) {
    DEXTradeByTokens(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Currency: {SmartContract: {is: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"}}, Side: {Currency: {SmartContract: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}}}, Dex: {ProtocolFamily: {is: "PancakeSwap"}}}}
    ) {
      Block {
        Time
      }
      Trade {
        Amount
        Buyer
        Seller
        Currency {
          SmartContract
          Name
          Symbol
        }
        Dex {
          ProtocolName
          ProtocolFamily
          SmartContract
        }
        Seller
        PriceAgainstSellCurrency: Price
        PriceInUSD
        Side {
          Amount
          Buyer
          Seller
          Currency {
            Name
            SmartContract
            Symbol
          }
        }
      }
    }
  }
}

You will get the below response for the above API query:

{
  "EVM": {
    "DEXTradeByTokens": [
      {
        "Block": {
          "Time": "2024-05-15T16:49:01Z"
        },
        "Trade": {
          "Amount": "0.189522540123136174",
          "Buyer": "0x802b65b5d9016621e66003aed0b16615093f328b",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.121810874030648,
          "PriceInUSD": 2972.7357317632554,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.970698606876588580",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x802b65b5d9016621e66003aed0b16615093f328b"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:48:31Z"
        },
        "Trade": {
          "Amount": "0.000000036494715934",
          "Buyer": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          },
          "PriceAgainstSellCurrency": 5.105079146277922,
          "PriceInUSD": 2963.0245170839207,
          "Seller": "0x00000e719aeae2afad3b00be068b00dc2770dc00",
          "Side": {
            "Amount": "0.000000186308413264",
            "Buyer": "0x00000e719aeae2afad3b00be068b00dc2770dc00",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:48:13Z"
        },
        "Trade": {
          "Amount": "0.000630529581370240",
          "Buyer": "0xead6bdab1b9fc66c9a1c0e647674845971f57032",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.121062908198362,
          "PriceInUSD": 2972.301607034627,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.003228981651676977",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0xead6bdab1b9fc66c9a1c0e647674845971f57032"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:48:13Z"
        },
        "Trade": {
          "Amount": "0.000000016046043593",
          "Buyer": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          },
          "PriceAgainstSellCurrency": 5.105079146409372,
          "PriceInUSD": 2963.024517160215,
          "Seller": "0x000000eed287174a06550eabe6a00074255cab34",
          "Side": {
            "Amount": "0.000000081916322529",
            "Buyer": "0x000000eed287174a06550eabe6a00074255cab34",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:48:04Z"
        },
        "Trade": {
          "Amount": "0.000000009252167540",
          "Buyer": "0x000000eed287174a06550eabe6a00074255cab34",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0xd0e226f674bbf064f54ab47f42473ff80db98cba"
          },
          "PriceAgainstSellCurrency": 5.123177363582416,
          "PriceInUSD": 2973.5288520907197,
          "Seller": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
          "Side": {
            "Amount": "0.000000047400495305",
            "Buyer": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x000000eed287174a06550eabe6a00074255cab34"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:47:58Z"
        },
        "Trade": {
          "Amount": "2.168855494289186435",
          "Buyer": "0xdb6f1920a889355780af7570773609bd8cb1f498",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0xd0e226f674bbf064f54ab47f42473ff80db98cba"
          },
          "PriceAgainstSellCurrency": 5.122701825573347,
          "PriceInUSD": 2973.2528464227753,
          "Seller": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
          "Side": {
            "Amount": "11.110400000000000000",
            "Buyer": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0xdb6f1920a889355780af7570773609bd8cb1f498"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:47:31Z"
        },
        "Trade": {
          "Amount": "0.000565926227948759",
          "Buyer": "0x85d246ad444a38ddde3b169e2dc8a16823718d22",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.121058202636733,
          "PriceInUSD": 2972.2988758929396,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.002898141151724258",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x85d246ad444a38ddde3b169e2dc8a16823718d22"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:47:10Z"
        },
        "Trade": {
          "Amount": "0.002149315389323317",
          "Buyer": "0x577d005912c49b1679b4c21e334fdb650e92c077",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.121047523843721,
          "PriceInUSD": 2972.2926778449564,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.011006746252453375",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x577d005912c49b1679b4c21e334fdb650e92c077"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:46:25Z"
        },
        "Trade": {
          "Amount": "0.015684131269839378",
          "Buyer": "0x85ec4c91a27cd8ea773280025e732d1be73844d9",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.120977387545968,
          "PriceInUSD": 2970.7516838911693,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.080318081576150087",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x85ec4c91a27cd8ea773280025e732d1be73844d9"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T16:45:25Z"
        },
        "Trade": {
          "Amount": "0.193394458044264080",
          "Buyer": "0x802b65b5d9016621e66003aed0b16615093f328b",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.12015524586706,
          "PriceInUSD": 2970.2747478314723,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.990209648876955677",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x802b65b5d9016621e66003aed0b16615093f328b"
          }
        }
      }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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