[Python] How to retrieve order book for newly created tokens in Solana network using python?

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    How to retrieve order book for newly created tokens in Solana network using python? Everything points to the Serum API, but I am getting errors when trying to import PublicKey from the Solana library. Are there any other ways to do this?

    Code:

    from pyserum.connection import conn
    from pyserum.market import Market
    from solders.pubkey import Pubkey

    # Replace with your Serum market address and program ID
    market_address = '4k3Dyjzvzp8eTxPZsHNT4X14X5R3FLeGkwWxNGj39fub' # Example for SOL/USDC
    serum_program_id = '9xQeWvG8169dZ2ib6KMvZr9VvJHZo2R5mPbiJQF1XhCk' # Standard Serum program ID for mainnet
    # Connect to the Solana mainnet-beta cluster
    client = conn('')

    # Load the market instance using the client, market address, and program ID
    market = Market.load(client, Pubkey(market_address), Pubkey(serum_program_id))

    # Retrieve the order book data for bids and asks
    bids = market.load_bids()
    asks = market.load_asks()

    # Print order book details
    print("Bids:")
    for bid in bids:
    print(f"Price: {bid.price}, Size: {bid.size}")

    print("\nAsks:")
    for ask in asks:
    print(f"Price: {ask.price}, Size: {ask.size}")


    Error:

    ModuleNotFoundError: No module named 'solana.publickey'

    FYI I have installed Solana lib

    Continue reading...

Compartilhe esta Página