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
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)
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)
})
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 |
-
π« Block known scam contracts/devs
-
π§ Dev wallet blacklist check
-
π’ Disable sniping on high gas or low liquidity
-
π¨ Telegram alerts for each buy/sell