buy and sell logic - cryptoking-max/solana-sniper-bot GitHub Wiki

Here’s a detailed Solana sniper bot buy and sell logic, optimized for meme tokens and DEXs like pump.fun, Jupiter, or Raydium, including:

  • βœ… Fast buy execution

  • βœ… Risk-managed sell logic (SL/TP, trailing, partials)

  • βœ… Dynamic strategies for volatile Solana meme markets


⚑ BUY LOGIC (Sniping New Tokens)

βœ… Sniping Conditions

Trigger buy when:

  • Token just launched (pool creation detected)

  • Liquidity > threshold (e.g. 500 SOL)

  • Dev wallet has no large allocation or honeypot flags

  • No blacklist triggers (e.g. blocked devs, blacklist tokens)

πŸ›’ Buy Execution Flow

def snipe_token(token_address, buy_amount_sol):
    # 1. Validate token (anti-honeypot, liquidity check, trading enabled)
    if not is_tradable(token_address):
        return "Blocked - Not tradable"
if not has_sufficient_liquidity(token_address, min_liquidity=500):
    return "Blocked - Low liquidity"

# 2. Estimate output via Jupiter or custom aggregator
best_route = get_jupiter_route("SOL", token_address, buy_amount_sol)

# 3. Execute Buy
tx_hash = execute_swap(route=best_route)
log_buy(token_address, buy_amount_sol, tx_hash)

# 4. Store state
save_trade_state(token_address, {
    "entry_price": get_price(token_address),
    "bought_at": current_timestamp(),
    "highest_price": get_price(token_address),
    "amount_tokens": get_balance(token_address)
})

πŸ’° SELL LOGIC (Dynamic, Risk-Aware)

βœ… Strategy Overview

Feature Method
Dynamic SL/TP Based on recent volatility or fixed %
Trailing Stop Sell if price drops from recent peak
Partial Sells Scale out (e.g. 25% at +50%, 25% at +100%)
Failsafe Exit Sell after X minutes or low volume

πŸ”’ Extra Risk Guards

  • 🚫 Block known scam contracts/devs

  • 🧠 Dev wallet blacklist check

  • 🐒 Disable sniping on high gas or low liquidity

  • 🚨 Telegram alerts for each buy/sell


⚠️ **GitHub.com Fallback** ⚠️