8000 GitHub - t0linixer/arbitrage-bot · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Arbitrage Bot

A TypeScript-based arbitrage bot that monitors price differences between DEX exchanges and executes profitable trades automatically.

Features

  • Real-time price monitoring via WebSocket feeds
  • Automatic arbitrage opportunity detection
  • Transaction building and submission
  • Configurable profit thresholds and risk parameters
  • Dry-run mode for testing

Project Structure

arb-bot/
├── src/
│   ├── index.ts              # Entry point
│   ├── config/
│   │   └── env.ts            # Constants, thresholds
│   ├── state/
│   │   └── market.ts         # In-memory prices/liquidity
│   ├── feeds/
│   │   └── dexWs.ts          # DEX websocket feed
│   ├── strategy/
│   │   └── arbitrage.ts      # Arbitrage opportunity detection logic
│   ├── tx/
│   │   ├── builder.ts        # Prebuilt tx calldata
│   │   └── submit.ts         # Tx submission
│   ├── utils/
│   │   └── math.ts           # Tiny math helpers
│   └── types.ts
├── package.json
├── tsconfig.json
└── README.md

Setup

  1. Install dependencies:
npm install
  1. Configure environment variables (create a .env file or set them in your environment):
# Required
PRIVATE_KEY=your_private_key_here
RPC_URL=https://eth.llamarpc.com
DEX_WS_URL=wss://your-dex-websocket-url
DEX_ROUTER_ADDRESS=0x...

# Optional
CHAIN_ID=1
MIN_PROFIT_THRESHOLD_WEI=1000000000000000  # 0.001 ETH
MIN_PROFIT_PERCENT=0.5                      # 0.5%
MAX_SLIPPAGE_PERCENT=1.0                    # 1%
MAX_GAS_PRICE_GWEI=100
ENABLE_DRY_RUN=true                         # Set to false for live trading

# Supported tokens (comma-separated addresses)
SUPPORTED_TOKENS=0x...,0x...
  1. Build the project:
npm run build
  1. Run the bot:
npm start

Or run in development mode:

npm run dev

Configuration

Key configuration parameters in src/config/env.ts:

  • MIN_PROFIT_THRESHOLD_WEI: Minimum absolute profit in wei to execute a trade
  • MIN_PROFIT_PERCENT: Minimum profit percentage threshold
  • MAX_SLIPPAGE_PERCENT: Maximum acceptable slippage
  • MAX_GAS_PRICE_GWEI: Maximum gas price to pay for transactions
  • ENABLE_DRY_RUN: If true, simulates trades without submitting them

Customization

DEX WebSocket Feed

Modify src/feeds/dexWs.ts to match your DEX's WebSocket API:

  • Update subscribe() method with your subscription format
  • Update handleMessage() to parse your DEX's message format

Arbitrage Strategy

Implement arbitrage detection in src/strategy/arbitrage.ts:

  • Price difference detection between DEX pools
  • Profit calculation
  • Opportunity validation

Transaction Building

Update src/tx/builder.ts to match your DEX router's interface:

  • Adjust the ABI in encodeSwapCall() for your router contract
  • Modify swap function parameters as needed

Security Considerations

  • Never commit your private key - use environment variables
  • Start with ENABLE_DRY_RUN=true to test without real transactions
  • Test thoroughly on testnets before mainnet deployment
  • Monitor gas prices and set appropriate limits
  • Consider implementing additional safety checks (max trade size, cooldown periods, etc.)

Development

  • TypeScript strict mode enabled
  • Source maps for debugging
  • Watch mode: npm run watch

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

0