Step-by-Step Guide to Creating a Market-Making Bot for Raydium (Solana AMM)
Creating a market-making bot for Raydium’s AMM involves several steps, from setting up a Solana
wallet to deploying a trading algorithm. Below is a structured guide to help you develop an automated
bot for liquidity provisioning and market-making on Raydium.
🛠️Step 1: Set Up Your Development Environment
1.1 Install Required Tools
You'll need the following:
Python (for coding the bot)
Rust & Solana CLI (for interacting with the blockchain)
Node.js (for using Solana Web3 libraries)
Raydium SDK (to interact with liquidity pools)
# Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
# Install Node.js & Yarn
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g yarn
# Install Python dependencies
pip install solana pyserum requests pandas
🔑 Step 2: Set Up Solana Wallet & RPC Node
2.1 Create or Import a Solana Wallet
You'll need a Solana wallet to interact with Raydium pools.
solana-keygen new --outfile ~/.config/solana/id.json
solana config set --keypair ~/.config/solana/id.json
solana airdrop 1 # Get test SOL (for Devnet)
2.2 Connect to an RPC Node
Use an RPC provider for low-latency transactions. Options:
Free: https://solana.com/rpc
Paid (faster): Alchemy, QuickNode
Set up the RPC endpoint:
solana config set --url https://api.mainnet-beta.solana.com
📊 Step 3: Get Pool Data from Raydium
You need to pull live price, liquidity depth, and order book data.
Raydium uses Serum DEX for order books.
3.1 Fetch Pool Data
Use pyserum (Python wrapper for Serum DEX):
from solana.rpc.api import Client
from pyserum.market import Market
from solana.publickey import PublicKey
# Connect to Solana RPC
client = Client("https://api.mainnet-beta.solana.com")
# Load Raydium's SOL/USDC market
market_address = PublicKey("9wFFW9rBp3QmGzJZsCC8VK68Gn52SGeXYAqE2nP4cKiv") # Example for
SOL/USDC
market = Market.load(client, market_address)
# Fetch order book data
bids = market.load_bids()
asks = market.load_asks()
# Print top bid/ask
print(f"Best Bid: {bids[0].price}, Best Ask: {asks[0].price}")
3.2 Get Liquidity Pool Reserves
Raydium has specific LP reserves you must check before making trades:
import requests
pool_address = "5EYUJF8ZsN3dfhmkGUZQZpg5MbmbzZ1Dk3JzNZt7FNN7" # Example pool
url = f"https://api.raydium.io/pairs/{pool_address}"
response = requests.get(url).json()
print(f"Liquidity Pool Reserve: {response['reserve']}")
🤖 Step 4: Develop the Market-Making Bot
4.1 Market-Making Strategy
Market makers place buy & sell orders continuously to profit from bid-ask spreads.
📌 Simple Strategy:
If spread > X%, place a buy order at bid and sell at ask.
If price moves, adjust buy/sell levels dynamically.
Maintain a neutral balance in both tokens.
4.2 Implement Order Execution
To place trades, you need Serum DEX instructions:
from pyserum.connection import conn
from pyserum.market import Market
# Connect to Serum DEX
solana_conn = conn("https://api.mainnet-beta.solana.com")
market = Market.load(solana_conn, market_address)
# Place a buy order at bid price
market.place_order(
owner=PublicKey("Your_Wallet_Address"),
payer=PublicKey("Your_USDC_Address"),
side="buy",
order_type="limit",
price=bids[0].price,
size=0.1 # Amount of SOL to buy
print("Buy order placed!")
4.3 Implement Dynamic Order Adjustment
Modify the script to adjust bids/asks based on market conditions:
import time
spread = 0.002 # 0.2% spread
while True:
bids = market.load_bids()
asks = market.load_asks()
new_bid = bids[0].price * (1 - spread)
new_ask = asks[0].price * (1 + spread)
# Adjust orders
market.cancel_all_orders(owner=PublicKey("Your_Wallet_Address"))
market.place_order(owner, payer, "buy", "limit", new_bid, 0.1)
market.place_order(owner, payer, "sell", "limit", new_ask, 0.1)
print(f"Updated Orders: Buy at {new_bid}, Sell at {new_ask}")
time.sleep(10) # Update every 10 seconds
⚡ Step 5: Deploy the Bot on a Server
To run continuously, deploy on a VPS (Cloud Server) like:
AWS EC2
DigitalOcean
Linode
Run the bot in screen mode or as a background service:
screen -S marketmaker
python3 market_maker_bot.py
📈 Step 6: Monitor & Optimize
Use logs & analytics to improve performance:
Monitor order execution rates.
Adjust spread & liquidity thresholds.
Use stop-loss triggers to minimize risk.
🛑 Risks & Considerations
✅ Impermanent Loss: Avoid holding too much in volatile pairs.
✅ Slippage & Front-running: Use limit orders to control execution price.
✅ Bot Latency: Use low-latency RPC nodes for better performance.
✅ Liquidity Depth: Avoid trading in low-volume pools to prevent price manipulation.
🚀 Final Summary
1️⃣ Set up Solana wallet & RPC connection
2️⃣ Fetch market data (Raydium AMM, Serum DEX)
3️⃣ Develop a market-making bot with bid-ask spread strategy
4️⃣ Execute orders dynamically (adjust based on price movements)
5️⃣ Deploy on a VPS for 24/7 trading
6️⃣ Optimize & manage risks
Would you like a ready-to-use bot script or help with backtesting strategies? 🚀