Skip to content

BNB (Pancakeswap Sniper Bot) - Sniper Bot with TPSL, trade on pancakeswap - monitoring new token launch, pool generation, allow advanced filter logic

Notifications You must be signed in to change notification settings

Trum3it/pancakeswap-sniper-bot

Repository files navigation

BNB Sniper Bot - Pancakeswap Edition

Advanced BNB Chain sniper bot for detecting and buying tokens instantly on Pancakeswap platform.

Features

  • Real-time Token Detection: Monitors PancakeSwap factory for new token pair creations
  • Auto-Buy: Instantly purchases tokens upon detection with competitive gas pricing
  • Auto-Sell: Monitors price and automatically sells when take-profit target is reached
  • Multi-RPC Broadcasting: Submits transactions to multiple RPC endpoints for faster propagation
  • Atomic Nonce Management: Prevents race conditions with proper nonce locking
  • Emergency Sell: Automatic sell after timeout to prevent stuck positions
  • Trade Metrics: Tracks profit percentage, duration, and entry/exit prices
  • Error Recovery: Automatic unlock mechanism prevents bot from getting stuck

Configuration

Environment Variables

Required:

  • PRIVATE_KEY - Your wallet private key
  • SNIPER_CONTRACT_ADDRESS - Your sniper contract address
  • WS_PROVIDER_URL - WebSocket provider URL for event monitoring
  • RPC_PROVIDER_URL - RPC provider URL for transactions
  • SEND_BNB - Amount of BNB to send per trade (e.g., "0.0005"). Default: "0.000001"

Optional:

  • TAKE_PROFIT_PERCENT - Take profit percentage (default: 5). Bot will sell when price reaches this percentage above entry
  • EMERGENCY_SELL_TIMEOUT - Timeout in milliseconds before emergency sell triggers (default: 600000 = 10 minutes)
  • TOKEN_NAME_CONTAINS - Filter out tokens by name (see Token Filtering section) - Available in index.ts
  • MIN_LIQUIDITY_BNB - Minimum liquidity filter (see Liquidity Filtering section) - Available in index.ts

Take Profit Configuration

The bot automatically monitors the price after buying and sells when the target is reached:

# Sell when price reaches +5% above entry (default)
TAKE_PROFIT_PERCENT=5

# Sell when price reaches +10% above entry
TAKE_PROFIT_PERCENT=10

# Sell when price reaches +20% above entry
TAKE_PROFIT_PERCENT=20

Emergency Sell Timeout

If the take-profit target is not reached within the timeout period, the bot will automatically sell to prevent stuck positions:

# Emergency sell after 5 minutes (300000 ms)
EMERGENCY_SELL_TIMEOUT=300000

# Emergency sell after 10 minutes (600000 ms) - default
EMERGENCY_SELL_TIMEOUT=600000

# Emergency sell after 15 minutes (900000 ms)
EMERGENCY_SELL_TIMEOUT=900000

Token Filtering (Optional - Available in index.ts)

You can filter out tokens by name before buying. Add this to your .env file:

  • TOKEN_NAME_CONTAINS - Tokens with names containing these strings will be SKIPPED (case-insensitive)
    • Multiple keywords can be separated by commas
    • The bot will SKIP tokens if the name contains ANY of the specified keywords
    • The bot will BUY all other tokens that don't match the filter

Examples:

# Skip tokens where name contains "Moon" (buy everything else)
TOKEN_NAME_CONTAINS=Moon

# Skip tokens where name contains "Moon" OR "DOGE" OR "Pepe" (buy everything else)
TOKEN_NAME_CONTAINS=Moon,DOGE,Pepe

# Skip tokens where name contains "Safe" OR "Moon" OR "Rocket" (buy everything else)
TOKEN_NAME_CONTAINS=Safe,Moon,Rocket

Note:

  • If TOKEN_NAME_CONTAINS is not set or empty, the bot will buy all detected tokens
  • Filtering is case-insensitive
  • Keywords are separated by commas (spaces around commas are automatically trimmed)
  • This is a blacklist filter - tokens matching the keywords are excluded

Liquidity Filtering (Optional - Available in index.ts)

You can filter tokens by minimum liquidity before buying. Add this to your .env file:

  • MIN_LIQUIDITY_BNB - Minimum total liquidity required in BNB (e.g., "1.0" for 1 BNB minimum)
    • Pools with less liquidity than this will be skipped
    • Total liquidity = 2 × WBNB reserve (since AMM pools maintain equal value on both sides)

Examples:

# Only buy tokens with at least 1 BNB total liquidity
MIN_LIQUIDITY_BNB=1.0

# Only buy tokens with at least 5 BNB total liquidity
MIN_LIQUIDITY_BNB=5.0

# Only buy tokens with at least 0.5 BNB total liquidity
MIN_LIQUIDITY_BNB=0.5

Note:

  • If MIN_LIQUIDITY_BNB is not set or 0, liquidity filtering is disabled
  • The bot calculates total liquidity as 2 × WBNB reserve
  • This helps avoid low-liquidity tokens that may be rug pulls or have high slippage

How It Works

  1. Event Monitoring: Bot listens to PairCreated events from PancakeSwap Factory contract via WebSocket
  2. Token Detection: When a new WBNB pair is created, the bot immediately identifies the new token
  3. Buy Execution: Bot executes a buy transaction with competitive gas pricing and multi-RPC broadcasting
  4. Price Monitoring: After buy confirmation, bot polls pair reserves every second to track price
  5. Take Profit: When price reaches the target percentage, bot automatically executes sell
  6. Emergency Exit: If target not reached within timeout, bot sells to prevent stuck positions
  7. State Management: Bot locks during active trades and unlocks after completion or failure

Trade Metrics

The bot tracks and logs:

  • Entry price
  • Exit price
  • Profit percentage
  • Trade duration
  • Buy and sell transaction hashes

Error Handling

  • Automatic nonce synchronization to prevent transaction failures
  • State unlock mechanism prevents bot from getting stuck
  • Retry logic for failed sell attempts (up to 3 attempts)
  • Graceful error recovery with proper state cleanup

Development Status

  • Monitoring (Completed)
  • Sniping (Completed)
  • Sniping as first buyer (Completed)
  • Selling logic (Completed)
  • Token filtering (Available in index.ts)
  • Liquidity filtering (Available in index.ts)
  • Trade metrics (Completed)
  • Emergency sell timeout (Completed)

Contact

For inquiries, custom integrations, or tailored solutions, reach out via:

Telegram: @trum3it

About

BNB (Pancakeswap Sniper Bot) - Sniper Bot with TPSL, trade on pancakeswap - monitoring new token launch, pool generation, allow advanced filter logic

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors