Skip to content

SamYbarra/Meteora-Copytrading-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meteora Copy Trading Bot

A Solana copy trading bot that monitors a target wallet and automatically executes trades on Meteora DEX (DBC, DAMM v1, v2, DLMM) when the target wallet makes transactions.

Features

  • Real-time Transaction Monitoring: Uses Yellowstone gRPC to stream transactions from target wallet
  • Instant Copy Trading: Automatically buys/sells when target wallet executes trades
  • Meteora DEX Support: Supports all Meteora pool types (DBC, DAMM v1, DAMM v2, DLMM)
  • Stop Loss & Take Profit: Configurable stop loss and take profit logic (when own sell logic is enabled)
  • Fast Execution: Uses Helius RPC for blockhash retrieval and Jito for transaction confirmation
  • Position Management: Tracks positions and manages risk automatically

Prerequisites

  • Node.js 18+ and npm/yarn
  • Solana wallet with SOL for trading and fees
  • Yellowstone gRPC API access
  • Helius RPC API key
  • Jito access (optional but recommended for faster confirmations)

Installation

  1. Clone the repository:
git clone <repository-url>
cd Meteora-Copytrading-Bot
  1. Install dependencies:
npm install
  1. Copy .env.example to .env:
cp .env.example .env
  1. Configure your .env file with your credentials (see Configuration section)

  2. Build the project:

npm run build

Configuration

Edit the .env file with your configuration:

Required Configuration

  • PRIVATE_KEY: Your wallet's private key (base58 encoded)
  • TARGET_WALLET_ADDRESS: The wallet address you want to copy trades from
  • YELLOWSTONE_GRPC_URL: Your Yellowstone gRPC endpoint (e.g., grpc://your-endpoint:10000)
  • HELIUS_RPC_URL: Your Helius RPC URL with API key

Optional Configuration

  • YELLOWSTONE_API_KEY: API key for Yellowstone (if required)
  • OWN_SELL_LOGIC_ENABLED: Enable stop loss/take profit (default: true)
  • STOP_LOSS_PERCENTAGE: Stop loss percentage (default: 5.0)
  • TAKE_PROFIT_PERCENTAGE: Take profit percentage (default: 10.0)
  • MAX_POSITION_SIZE_SOL: Maximum position size in SOL (default: 1.0)
  • MIN_POSITION_SIZE_SOL: Minimum position size in SOL (default: 0.01)

See .env.example for all available configuration options.

Usage

Development Mode

npm run dev

Production Mode

npm run build
npm start

Watch Mode (for development)

npm run watch

How It Works

  1. Transaction Monitoring: The bot subscribes to Yellowstone gRPC stream for the target wallet
  2. Trade Detection: When a transaction is detected, it parses the transaction to identify Meteora trades
  3. Copy Execution:
    • On BUY: Executes a buy order for the same token/pool
    • On SELL: Executes a sell order if we have a position
  4. Position Management:
    • Tracks all open positions
    • Monitors prices for stop loss/take profit (if enabled)
    • Automatically sells when conditions are met

Architecture

src/
├── index.ts                 # Main entry point
├── config.ts               # Configuration loader
├── types.ts                # TypeScript type definitions
├── clients/
│   ├── yellowstone.ts     # Yellowstone gRPC client
│   ├── helius.ts          # Helius RPC client
│   └── jito.ts            # Jito transaction client
├── dex/
│   └── meteora.ts         # Meteora DEX integration
├── trading/
│   ├── copyTrader.ts      # Main copy trading logic
│   └── positionManager.ts # Position tracking and risk management
└── utils/
    └── logger.ts          # Logging utility

Stop Loss & Take Profit

When OWN_SELL_LOGIC_ENABLED=true:

  • Stop Loss: Automatically sells when price drops by the configured percentage from entry price
  • Take Profit: Automatically sells when price increases by the configured percentage from entry price

The bot checks positions every 5 seconds and executes sells when conditions are met.

Transaction Flow

  1. Get latest blockhash from Helius RPC
  2. Create and sign transaction
  3. Send transaction via Solana RPC
  4. Confirm transaction via Jito (for faster confirmation)
  5. Update position tracking

Security Considerations

  • Never commit your .env file - it contains sensitive private keys
  • Use a dedicated trading wallet with limited funds
  • Regularly monitor your positions and bot activity
  • Set appropriate stop loss levels to limit risk
  • Test on devnet first before using mainnet

Troubleshooting

Bot not detecting trades

  • Verify Yellowstone gRPC connection is working
  • Check that target wallet address is correct
  • Ensure target wallet is making Meteora trades

Transactions failing

  • Check wallet has sufficient SOL for fees
  • Verify RPC endpoints are accessible
  • Check network congestion (may need higher priority fees)

Stop loss/take profit not working

  • Ensure OWN_SELL_LOGIC_ENABLED=true
  • Verify price fetching is working
  • Check position tracking is correct

Development

Project Structure

The bot is built with TypeScript and follows a modular architecture:

  • Clients: External service integrations (Yellowstone, Helius, Jito)
  • DEX: Meteora DEX integration and trade parsing
  • Trading: Core trading logic and position management
  • Utils: Shared utilities (logging, etc.)

Important Notes

Meteora SDK Integration

The current implementation includes placeholder swap instructions in src/dex/meteora.ts. For production use, you need to:

  1. Install Meteora SDK: The package.json includes @meteora-ag/sdk and @meteora-ag/dlmm dependencies
  2. Implement Real Swaps: Replace the createSwapInstruction method with actual Meteora SDK calls:
    • For DLMM pools: Use @meteora-ag/dlmm SDK
    • For DAMM/DBC pools: Use @meteora-ag/sdk
    • Fetch pool state and construct proper swap instructions
  3. Transaction Parsing: Enhance parseTransactionForTrade to accurately parse Meteora swap transactions and extract:
    • Token mints
    • Swap amounts
    • Buy/sell direction
    • Pool addresses

Enhanced Transaction Parsing

The transaction parsing logic in MeteoraDEX.parseTransactionForTrade() is simplified. For production:

  • Analyze account balance changes to determine buy/sell
  • Parse instruction data to extract exact amounts
  • Validate pool addresses and program IDs
  • Handle different Meteora pool types correctly

Price Oracle

The getTokenPrice() method currently returns a placeholder. Implement:

  • Fetch pool reserves from on-chain data
  • Calculate price based on pool type (constant product, concentrated liquidity, etc.)
  • Use a reliable price oracle service for accurate stop loss/take profit

Adding New Features

  1. Meteora SDK Integration: Integrate official Meteora SDKs for proper swap execution
  2. Enhanced Transaction Parsing: Improve transaction parsing to accurately detect buy/sell signals
  3. Price Oracle: Add reliable price fetching for accurate stop loss/take profit
  4. Risk Management: Add position sizing, max drawdown limits, etc.
  5. Monitoring: Add webhook notifications, Telegram alerts, etc.

License

MIT

Disclaimer

This bot is for educational purposes. Trading cryptocurrencies involves risk. Use at your own risk and never invest more than you can afford to lose.

About

Solana meteora copy trading bot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors