How can I get to the price in a liquidity pool? I assumed it would be as simple as getting the balances of both tokens and doing quoteBalance / baseBalance, but that doesn't seem to be the case. Below is a sample code I was using to the get the pool information, but the division of the end values returned in the dictionaries base_token_info and quote_token_info does not match at all what I see on Solscan, what am I missing?
from solders.pubkey import Pubkey
from solana.rpc.api import Client
import json
import base64
from utils import LIQUIDITY_STATE_LAYOUT_V4
def get_token_amounts_example():
endpoint = 'https://api.mainnet-beta.solana.com'
solana_client = Client(endpoint)
pool_address = '58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2' # SOL-USDC
pool = Pubkey.from_string(pool_address)
info = json.loads(solana_client.get_account_info_json_parsed(pool).to_json())
data = info['result']['value']['data']
data_64 = base64.b64decode(data[0])
token_account_data = LIQUIDITY_STATE_LAYOUT_V4.parse(data_64)
marketId = Pubkey.from_bytes(token_account_data.marketId)
base_token_account = Pubkey.from_bytes(token_account_data.baseVault)
quote_token_account = Pubkey.from_bytes(token_account_data.quoteVault)
owner = Pubkey.from_bytes(token_account_data.owner)
print('marketId', marketId)
print('base_token_account', base_token_account)
print('quote_token_account', quote_token_account)
print('owner', owner)
base_token_info = solana_client.get_token_account_balance(base_token_account).to_json()
base_token_info = json.loads(base_token_info)
quote_token_info = solana_client.get_token_account_balance(quote_token_account).to_json()
quote_token_info = json.loads(quote_token_info)
owner_token_info = solana_client.get_token_account_balance(owner).to_json()
owner_token_info = json.loads(owner_token_info)
print('base_token_info', base_token_info)
print('quote_token_info', quote_token_info)
print('owner_token_info', owner_token_info)
get_token_amounts_example()