Here's a Python script that monitors new liquidity pools on Raydium in real-time and displays the latest pool metadata. The solution combines WebSocket subscriptions with Solana RPC calls to track pool creations efficiently.
Real-time Raydium Pool Monitor
This script uses Solana's WebSocket API to listen for new Raydium pool creations and fetches relevant metadata:
python
import asyncio
import json
from solana.rpc.async_api import AsyncClient
from solana.rpc.websocket_api import connect
from solders.pubkey import Pubkey
from solders.signature import Signature
from solders.rpc.responses import GetTransactionResp
from solders.transaction_status import UiPartiallyDecodedInstruction, UiInstruction
# Constants
RAYDIUM_PROGRAM_ID = Pubkey.from_string("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8")
SOLANA_RPC_URL = "https://api.mainnet-beta.solana.com"
SOLANA_WS_URL = "wss://api.mainnet-beta.solana.com"
async def fetch_pool_metadata(pool_address: Pubkey, client: AsyncClient):
"""Fetch metadata for a newly created pool"""
try:
account_info = await client.get_account_info_json_parsed(pool_address)
return {
"pool_address": str(pool_address),
"data": account_info.value.data,
"lamports": account_info.value.lamports,
"owner": str(account_info.value.owner),
"executable": account_info.value.executable,
"rent_epoch": account_info.value.rent_epoch
}
except Exception as e:
print(f"Error fetching metadata: {e}")
return None
async def monitor_new_pools():
client = AsyncClient(SOLANA_RPC_URL)
async with connect(SOLANA_WS_URL) as websocket:
# Subscribe to program account changes for Raydium
await websocket.program_subscribe(RAYDIUM_PROGRAM_ID)
async for response in websocket:
if response.result is None:
continue
# Get transaction details
tx_sig = Signature.from_string(response.result.value.pubkey)
tx = await client.get_transaction(tx_sig, max_supported_transaction_version=0)
if not isinstance(tx, GetTransactionResp):
continue
# Process instructions to find pool creations
for instruction in tx.value.transaction.transaction.message.instructions:
if isinstance(instruction, UiPartiallyDecodedInstruction) or isinstance(instruction, UiInstruction):
if instruction.program_id == str(RAYDIUM_PROGRAM_ID):
# Extract pool address from instruction accounts
if len(instruction.accounts) > 0:
pool_address = Pubkey.from_string(instruction.accounts)
metadata = await fetch_pool_metadata(pool_address, client)
if metadata:
print("New Raydium Pool Detected:")
print(json.dumps(metadata, indent=2))
if __name__ == "__main__":
asyncio.run(monitor_new_pools())
Key Components
WebSocket Subscription
Establishes a real-time connection to Solana's mainnet-beta cluster
Subscribes specifically to the Raydium program ID to filter relevant transactions[[3]][[4]]
Transaction Processing
Extracts transaction signatures when new program accounts are detected
Fetches complete transaction details using Solana's RPC API[[1]]
Metadata Extraction
Identifies pool creation instructions within transactions
Retrieves account information for new pools including:
Pool address
Account data
Ownership details
Resource allocation[[5]][[6]]
Alternative Implementation
For a more robust solution that includes additional pool details, consider using the Raydium SDK:
python
from raydium.sdk import create_amm_v4_pool_keys, fetch_pool_keys
import asyncio
async def track_new_pools():
while True:
try:
# Fetch latest pool keys from Raydium
pools = await fetch_pool_keys()
latest_pool = pools[-1] # Get most recent pool
print(f"New Pool Detected: {latest_pool['name']}")
print(f"Base Mint: {latest_pool['base_mint']}")
print(f"Quote Mint: {latest_pool['quote_mint']}")
print(f"LP Mint: {latest_pool['lp_mint']}")
await asyncio.sleep(5) # Check every 5 seconds
except Exception as e:
print(f"Error: {e}")
await asyncio.sleep(10)
asyncio.run(track_new_pools())
Consider adding error handling and reconnection logic
Implement rate limiting to avoid RPC node bans
Store detected pools in a database for historical tracking[[2]][[7]]
The first script provides lower-level access to pool creation events, while the second offers a more streamlined approach using Raydium's SDK. Both methods effectively monitor new liquidity pools in real-time, with the choice depending on your specific requirements for data granularity versus implementation simplicity.