Web3.py 查看流动资金池余额

Web3.py check liquidity pool balance

我正在尝试计算给定令牌地址的 lp 地址的余额。 所以我有这个功能:

web3 = Web3(Web3.HTTPProvider("https://bsc-dataseed.binance.org/"))

def CheckLiquidity(TokenAddress, web3):
   LPAddress = GetLiquidityAddress(TokenAddress) #returns the web3.toChecksumAddress()
   balance = web3.eth.get_balance(LPAddress)
   bnbBalance = web3.fromWei(balance, 'ether)

唯一的问题是这个 returns 我 0... 对于我尝试过的每一份合同。我还手动检查 bsc 扫描池中的 wbnb 余额并且不为 0。 有人可以帮我吗?

Web3 Ethereum Defi package中有例子。

    pair = get_deployed_contract(web3, "UniswapV2Pair.json", pair_address)
    token_a, token_b, timestamp = pair.functions.getReserves().call()

    # Check we got the liquidity
    assert token_a == 10 * 10**18
    assert token_b == 17_000 * 10**18

See full example.