Skip to content

LordVibeCoding/PancakeSwap-Prediction-Betting-bot

Repository files navigation

PancakeSwap Prediction Betting bot

When this program was developed, ** did not leave any backdoors** and tip programs, just so that users can try better. If you have a better money-making plan, you can contact me to eat meat together ✈️ @lever

An automated follow-trading bot for PancakeSwap Prediction V2 (contract 0x18B2A687610328590Bc8F2e5fEdDe3b582A49cdA). It listens to on-chain events, derives EMA-based signals from external markets, applies martingale progression with loss-follow rules, and can automatically claim winnings while persisting full history. The codebase is TypeScript-first and supports both dry-run and full simulation modes.


Highlights

  • Live on-chain monitoring – Subscribes to StartRound, LockRound, and CloseRound via WebSocket/HTTP providers and schedules trades with a configurable lead time before round lock.
  • EMA strategy with optional reversal filter – Pulls EMA12/EMA144/EMA169 from Binance or OKX candles. The 12 EMA must be clearly above/below the long EMAs to open a position. An optional “break & pullback” reversal check (EMA_REVERSAL_ENABLED) flips the signal when price sharply reverts after a breakout.
  • Martingale & forced follow-up – Adjustable multiplier and maximum steps. After three consecutive losses on the same side, the next round will be forced to follow that side once.
  • Persistent history – Every bet (epoch, side, amount, EMA snapshot, forced flag, result, claim status, tx hashes) is stored in bet-history.json. On restart the bot rebuilds martingale level, unresolved rounds, and pending claims.
  • Automatic claiming – Scans historic epochs after each new round, cross-checks ledger, claimable, and refundable, batches eligible epochs, and marks them as claimed (with tx hash) when the transaction succeeds.
  • Rate-limit aware retries – All RPC calls used for claiming are wrapped in exponential backoff to tolerate QuickNode’s 15 req/s limit.
  • Simulation / dry-runSIMULATION_MODE=true runs the full pipeline without private key or network IO. DRY_RUN=true constructs real transactions but skips broadcasting.
  • Manual claim scriptnpm run claim reuses the same detection logic to list or claim epochs on demand.

Requirements

  • Node.js 18+
  • npm 9+
  • BSC endpoints (both WebSocket and HTTP). A free QuickNode plan works if you respect rate limits.

Quick Start

  1. Install dependencies

    npm install
  2. Create configuration

    cp .env.example .env

    Fill at least:

    • BSC_WSS / BSC_HTTP
    • PRIVATE_KEY (only when sending real bets/claims)
    • TG_BOT_TOKEN + TG_USER_ID if you need Telegram alerts
  3. Run the bot

    npm run start
    • SIMULATION_MODE=true: full simulation (default) – no private key required
    • DRY_RUN=true: build transactions but do not broadcast
  4. Manual claim (optional)

    npm run claim -- --dry-run          # show pending epochs
    npm run claim                       # send claim transactions
    npm run claim -- 419820 419821      # claim selected epochs only

Strategy & Logging

Key log prefixes:

  • [EMA] – current EMA readings
  • [策略] (strategy) – decision results (bull/bear/neutral, forced follow, reversal triggers)
  • [下单] / [模拟] / [交易] – order scheduling, simulation notice, and transaction lifecycle
  • [领取] – claim workflow, including rate-limit retries
  • [历史] – history persistence and reconciliation notices

Telegram messages mirror these details, including last ten results, win-rate, forced flags, and simulation markers.


Configuration Reference

Category Variable Description
RPC BSC_WSS / BSC_HTTP Required BSC endpoints
PRIVATE_KEY Wallet private key (omit for simulation)
Betting BET_AMOUNT Initial stake (BNB)
DECISION_OFFSET Seconds before lock to submit the bet
Gas GAS_LIMIT Safety cap (default 300000)
GAS_PRICE Fixed gas price in Gwei (lower values reduce cost but increase pending risk)
GAS_PRICE_FACTOR Alternative dynamic pricing based on bet size
Strategy MARTINGALE_FACTOR Progression multiplier
MARTINGALE_MAX_STEPS Maximum martingale levels
FORCE_LOSS_STREAK Consecutive losses before forced follow (default 3)
EMA_REVERSAL_THRESHOLD Pullback distance used by reversal filter
EMA_REVERSAL_ENABLED Enable/disable reversal logic
Market MARKET_PROVIDER binance (default) or okx
BINANCE_*, OKX_* Candle symbol/interval/limit per provider
Claiming AUTO_CLAIM Enable auto-claim outside simulation
CLAIM_DELAY_SECONDS Delay after new round before scanning
CLAIM_LOOKBACK Extra epochs to scan as fallback
RATE_LIMIT_DELAY_MS Initial retry delay when throttled
RATE_LIMIT_MAX_RETRIES Retry attempts for throttled calls
Storage BET_HISTORY_FILE Path to history JSON
Runtime SIMULATION_MODE, DRY_RUN, NO_WAIT Execution modes
Alerts TG_BOT_TOKEN / TG_USER_ID Telegram notifications

History File

bet-history.json entry example:

{
  "epoch": "419820",
  "side": "betBear",
  "amount": "1000000000000000",
  "level": 0,
  "result": "win",
  "forcedFollow": false,
  "claimed": true,
  "claimTxHash": "0x…"
}

The bot reloads this file on startup, rebuilds open positions, martingale level, and pending claims, and updates the claimed flag whenever an on-chain claim succeeds.


Gas Cost Notes

  • Prediction bets/claims consume roughly 110k–130k gas. At 25 Gwei this is about 0.003 BNB. Dropping to 5 Gwei cuts cost to ~0.0006 BNB but increases the chance of pending transactions.
  • Reducing GAS_LIMIT does not lower fees; it only risks “out of gas”. Keep it generous (~300k) and tune GAS_PRICE instead.

Martingale Budget Example

With MARTINGALE_FACTOR=3 and starting stake 0.005 BNB, the first six levels require:

Level Stake (BNB)
1 0.005
2 0.015
3 0.045
4 0.135
5 0.405
6 1.215
Total ≈ 1.82 BNB

Plan bankroll accordingly and consider gas fees on top of the stake.


Troubleshooting

  • -32007 rate-limit errors – Increase RATE_LIMIT_DELAY_MS, reduce CLAIM_LOOKBACK, or upgrade the RPC plan. Retries are already built in and logged with the [限流] prefix.
  • EMA keeps logging “in the middle” – The conservative mode avoids trading when EMA12 sits between EMA144 and EMA169. Adjust thresholds or modify the strategy block in scheduleBet to follow prior direction instead.
  • Gas feels expensive – Lower GAS_PRICE (with caution), combine claim batches, or raise base stake to improve fee-to-profit ratio.
  • Want to re-test claim logic – Run npm run claim -- --dry-run with a history entry that has claimed=false for a known winning epoch.

Development & Testing

  • Type check: npx tsc --noEmit
  • Example unit test: npx ts-node tests/collect-claimable.test.ts
  • Manual claim dry-run: npm run claim -- --dry-run

Core files:

  • src/index.ts – event loop, strategy, martingale, claim handling
  • src/binance.ts – market data fetch & EMA calculations (covers both Binance & OKX)

Security & Compliance

  • Keep .env out of version control and secure private keys in production.
  • Automated betting carries financial risk; this project is provided as-is without investment advice.
  • Ensure compliance with local regulations, node provider ToS, and exchange API policies.

Good luck and happy trading! 🚀

About

Automated PancakeSwap Prediction follow-trading bot written in TypeScript. Streams EMA signals from Binance/OKX, apply martingale + forced-follow Logic, auto-claims winnings with rate-limit aware retries, and persists Full bet history for seamless restarts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors