Back to blog

2026-03-23

How to Build a Solana Trading Bot in 2026

Building a trading bot on Solana requires three things: a reliable data source for market activity, logic to decide when to trade, and infrastructure to execute transactions. This guide walks through the architecture using the Sailfish SDK for real-time data.

Architecture Overview

A Solana trading bot has four core components:

  1. Data feed: Real-time trade and pool events from DEXs
  2. Strategy logic: Rules that decide when to buy, sell, or hold
  3. Execution layer: Transaction building and submission to the Solana network
  4. State management: Tracking positions, balances, and order history

Step 1: Set Up Real-Time Data with Sailfish

The Sailfish SDK provides WebSocket streaming of trades, pool initializations, token mints, and graduations from Raydium, PumpFun, PumpSwap, and Meteora.

import { Sailfish, SailfishTier, Trade, PoolInit } from "sailfish-sdk";

const sailfish = new Sailfish({
  tier: SailfishTier.free({ apiKey: "YOUR_API_KEY" }),
  filter: {
    token_addresses: [],     // empty = all tokens
    pool_addresses: [],      // empty = all pools
    dex_types: [],           // empty = all DEXs
  },
  callbacks: {
    onTrade: (trade: Trade) => {
      // Process each trade — price, volume, wallet
      handleTrade(trade);
    },
    onPoolInit: (poolInit: PoolInit) => {
      // New pool detected — potential opportunity
      evaluateNewPool(poolInit);
    },
  },
});

sailfish.swim(); // Start streaming

The onTrade callback fires for every trade across all supported protocols. Each Trade object includes the price, base/quote amounts, pool address, and trader wallet.

Step 2: Choose Your Strategy

Common Solana bot strategies include:

Sniping New Pools

React to onPoolInit events. When a new pool is initialized on Raydium or PumpFun, evaluate the token (check supply, mint authority, metadata) and decide whether to buy early.

Volume-Based Trading

Use onTrade to track volume spikes. When a token sees unusual buy volume over a short window, enter a position. Exit on predefined profit targets or stop-losses.

Arbitrage

Monitor the same token across multiple DEXs (e.g., Raydium AMM vs PumpSwap). When prices diverge beyond fees, execute simultaneous buy/sell across pools.

Graduation Trading

Use onTokenGraduate to detect when tokens graduate from PumpFun's bonding curve to Raydium. This migration event often creates short-term trading opportunities.

Step 3: Build the Execution Layer

To execute trades on Solana, you need:

  • @solana/web3.js: For building and signing transactions
  • RPC endpoint: Helius, QuickNode, or a private node for transaction submission
  • A funded wallet with SOL for gas and wSOL for trading
import { Connection, Keypair, Transaction } from "@solana/web3.js";

const connection = new Connection("https://your-rpc-endpoint.com");
const wallet = Keypair.fromSecretKey(/* your key */);

async function executeTrade(instruction: TransactionInstruction) {
  const tx = new Transaction().add(instruction);
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.sign(wallet);
  const sig = await connection.sendRawTransaction(tx.serialize());
  return sig;
}

For DEX-specific swap instructions, use the respective program SDKs (Raydium SDK, PumpFun client, etc.) to build the swap instruction.

Step 4: Backtest with Historic Data

Before running live, backtest your strategy against real market data. Sailfish's Historic API provides trade data queryable by pool address, token address, or block range.

Use 0xfire's free Historic Trade Data tool to explore data visually, or query the API directly for programmatic backtesting.

Step 5: Deploy and Monitor

For production deployment:

  • Run on a VPS close to Solana validators (low latency regions)
  • Use a dedicated RPC endpoint with priority fee support
  • Implement circuit breakers (max loss per day, position limits)
  • Log all trades for post-analysis

Key Considerations

  • MEV and sandwich attacks: Solana bots can be sandwiched by MEV bots. Use priority fees and consider Jito bundles for transaction ordering protection.
  • Slippage: Set appropriate slippage limits on swaps. Too tight and trades fail; too loose and you lose money.
  • Rate limits: Sailfish free tier has rate limits. For production bots, subscribe at $75/month per chain.
  • Risk management: Never risk more than you can afford to lose. Start with small amounts and scale up after validating your strategy.

Getting Help

If you want hands-on guidance building your first bot, 0xfire offers 1-on-1 mentorship starting at $499/month with weekly live sessions. For a fully managed approach, the Scale Your Strategy tier handles implementation, backtesting, and deployment.

Resources