Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token Price Issue! #19

Open
Crow1994 opened this issue Nov 29, 2024 · 1 comment
Open

Token Price Issue! #19

Crow1994 opened this issue Nov 29, 2024 · 1 comment

Comments

@Crow1994
Copy link

Crow1994 commented Nov 29, 2024

New tokens return an empty response value. Is there an alternative method to retrieve the token price? I keep encountering the error 'Invalid curve state: No data,' but this issue doesn’t occur for tokens launched 3–10 minutes ago.

async def get_pump_curve_state(conn: AsyncClient, curve_address: Pubkey) -> BondingCurveState:
    response = await conn.get_account_info(curve_address)
    if not response.value or not response.value.data:
        raise ValueError("Invalid curve state: No data")

    data = response.value.data
    if data[:8] != EXPECTED_DISCRIMINATOR:
        raise ValueError("Invalid curve state discriminator")

    return BondingCurveState(data)


def calculate_pump_curve_price(curve_state: BondingCurveState) -> float:
    if curve_state.virtual_token_reserves <= 0 or curve_state.virtual_sol_reserves <= 0:
        raise ValueError("Invalid reserve state")

    return (curve_state.virtual_sol_reserves / LAMPORTS_PER_SOL) / (
                curve_state.virtual_token_reserves / 10 ** TOKEN_DECIMALS) 
    # Fetch the token price
        curve_state = await get_pump_curve_state(client, bonding_curve)
        token_price_sol = calculate_pump_curve_price(curve_state)
        token_amount = amount / token_price_sol
@creosmart
Copy link

Did you try increasing the waiting time (trade.py)? If not try increasing it to 20 seconds.
print("Waiting for 15 seconds for things to stabilize...") await asyncio.sleep(15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants