raydium-io / raydium-contract-instructions

121 stars 120 forks source link

any suggestion about get price from solana chain? #2

Open turfT opened 3 years ago

turfT commented 3 years ago

I want to monitor raydium pair’s price and liquidity by my scripts.

I fetch AccountInfo and decode it as following for usdc-sol pair.

{'AmmInfo': {'status': 1, 'nonce': 254, 'orderNum': 7, 'depth': 3, 'coinDecimals': 9, 'pcDecimals': 6, 'state': 4, 'resetFlag': 1, 'minSize': 100000000, 'volMaxCutRatio': 0, 'amountWaveRatio': 5000000, 'coinLotSize': 100000000, 'pcLotSize': 1000000, 'minPriceMultiplier': 1, 'maxPriceMultiplier': 1000000000, 'systemDecimalsValue': 1000000000, 'minSeparateNumerator': 5, 'minSeparateDenominator': 10000, 'tradeFeeNumerator': 25, 'tradeFeeDenominator': 10000, 'pnlNumerator': 12, 'pnlDenominator': 100, 'swapFeeNumerator': 25, 'swapFeeDenominator': 10000, 'needTakePnlCoin': 8140863902844, 'needTakePnlPc': 917642085053, 'totalPnlPc': 9066692582132, 'totalPnlCoin': 105254831342614, 'poolTotalDepositPc': 1047021925663273, 'poolTotalDepositCoin': 2415515000447854, 'swapCoinInAmount': 25165089716375387, 'swapPcOutAmount': 2737002418974453, 'swapCoin2PcFee': 6440123606819, 'swapPcInAmount': 2502424906491424, 'swapCoinOutAmount': 22786439552198306, 'swapPc2CoinFee': 61864243713227}

Can not figure out these number meaning and It is different from the swap page's price and liquidity.

besides, what "pc" means in Amm accountinfo layout?

oduoki commented 2 years ago

Looks like coin and pc are a pair, coin means base, pc means quote. I guess the full name of pc is popular coin.

tommyip commented 2 years ago

pc means price currency, it is a terminology inherited from Serum.

spectrum968 commented 2 years ago

total_token_pc = amminfo.pc_vault.balance + amminfo.openorder.total_quote - amminfo.need_taken_pnl_pc total_token_coin = amminfo.coin_vault.balance + amminfo.openorder.total_base - amminfo.need_taken_pnl_coin

spectrum968 commented 2 years ago

coin_price = total_token_pc / total_token_coin

fraggdiller commented 10 months ago

total_token_pc = amminfo.pc_vault.balance + amminfo.openorder.total_quote - amminfo.need_taken_pnl_pc total_token_coin = amminfo.coin_vault.balance + amminfo.openorder.total_base - amminfo.need_taken_pnl_coin

what is openorder.total_quote and openorder.total_base? And .pc_vault.balance /coin_vault.balance balance of tokens in vault Account?

pub struct AmmInfo {
    pub status: u64,
    pub nonce: u64,
    pub order_num: u64,
    pub depth: u64,
    pub coin_decimals: u64,
    pub pc_decimals: u64,
    pub state: u64,
    pub reset_flag: u64,
    pub min_size: u64,
    pub vol_max_cut_ratio: u64,
    pub amount_wave_ratio: u64,
    pub coin_lot_size: u64,
    pub pc_lot_size: u64,
    pub min_price_multiplier: u64,
    pub max_price_multiplier: u64,
    pub system_decimals_value: u64,
    pub min_separate_numerator: u64,
    pub min_separate_denominator: u64,
    pub trade_fee_numerator: u64,
    pub trade_fee_denominator: u64,
    pub pnl_numerator: u64,
    pub pnl_denominator: u64,
    pub swap_fee_numerator: u64,
    pub swap_fee_denominator: u64,
    pub need_take_pnl_coin: u64,
    pub need_take_pnl_pc: u64,
    pub total_pnl_pc: u64,
    pub total_pnl_coin: u64,
    pub pool_total_deposit_pc: u128,
    pub pool_total_deposit_coin: u128,
    pub swap_coin_in_amount: u128,
    pub swap_pc_out_amount: u128,
    pub swap_coin2pc_fee: u64,
    pub swap_pc_in_amount: u128,
    pub swap_coin_out_amount: u128,
    pub swap_pc2coin_fee: u64,
    pub pool_coin_token_account: Pubkey,
    pub pool_pc_token_account: Pubkey,
    pub coin_mint_address: Pubkey,
    pub pc_mint_address: Pubkey,
    pub lp_mint_address: Pubkey,
    pub amm_open_orders: Pubkey,
    pub serum_market: Pubkey,
    pub serum_program_id: Pubkey,
    pub amm_target_orders: Pubkey,
    pub pool_withdraw_queue: Pubkey,
    pub pool_temp_lp_token_account: Pubkey,
    pub amm_owner: Pubkey,
    pub pnl_owner: Pubkey,
}

pub struct SerumMarket {
    _blob_5: [u8; 5],
    pub account_flags: u64,
    pub own_address: Pubkey,
    pub vault_signer_nonce: u64,
    pub coin_mint: Pubkey,
    pub pc_mint: Pubkey,
    pub coin_vault: Pubkey,
    pub coin_deposits_total: u64,
    pub coin_fees_accrued: u64,
    pub pc_vault: Pubkey,
    pub pc_deposits_total: u64,
    pub pc_fees_accrued: u64,
    pub pc_dust_threshold: u64,
    pub req_q: Pubkey,
    pub event_q: Pubkey,
    pub bids: Pubkey,
    pub asks: Pubkey,
    pub coin_lot_size: u64,
    pub pc_lot_size: u64,
    pub fee_rate_bps: u64,
    pub referrer_rebates_accrued: u64,
    _blob_7: [u8; 7],
}