High-frequency market making infrastructure for Lighter.xyz with advanced snipe protection and delta-neutral refund extraction capabilities.
This repository contains two trading strategies built on a shared Rust engine:
Production-ready market making bot with institutional-grade risk controls.
Features:
- Snipe Detection — Cross-exchange toxic flow detection using Binance price feeds (~50-100ms head start)
- Avellaneda-Stoikov — Inventory-aware pricing with dynamic skew
- Multi-Exchange — Unified WebSocket interface (Binance, Lighter, MEXC, Variational)
- Kill Switches — Position limits, max loss thresholds, adverse selection guards
- Real-time Monitoring — Telegram bot integration for remote PnL tracking
Best For: Running tight spreads on Lighter with protection from informed flow.
See docs/ for full Market Maker documentation
Delta-neutral strategy for extracting value from Variational's loss refund program.
What It Does:
- Opens leveraged positions on Variational via RFQ
- Immediately hedges delta on Lighter (perpetual futures)
- Accumulates 30-day rolling volume toward refund tiers
- Exits positions when refund EV exceeds combined basis cost
Why It's Cool:
- Extracts expected value from lottery-based refund mechanism (0.5-3% odds)
- Statistically-driven exit logic (EMA-based profit confirmation, EV thresholds)
- Supports all 7 tiers (Bronze $1M → Infinity $2.5B)
- Generates ~$0.03-0.10 profit per round-trip at 30x leverage (depends on the average loss per trade on variational)
Performance:
- Bronze tier: ~334 trades × $3,000 notional = $1M volume (30-day rolling)
- Typical hold time: 1-3 minutes per position
- Refund odds: 0.5% (Bronze) to 3% (Infinity)
See src/live/volume_farmer/README.md for strategy deep dive
┌──────────────────────────────────────────────────────────────────┐
│ Protector Engine │
├──────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Binance │───▶│ Snipe │───▶│ Order Manager │ │
│ │ (Signal) │ │ Detector │ │ (Lighter) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │ │
│ ┌─────────────┐ ┌─────────────┐ ▼ │
│ │ Variational │───▶│ Refund │ ┌─────────────────────┐ │
│ │ (RFQ) │ │ Farmer │ │ Position Tracker │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │ │
│ ┌─────────────┐ ┌─────────────┐ ▼ │
│ │ Lighter │───▶│ Hedge │ ┌─────────────────────┐ │
│ │ (Orderbook)│ │ Executor │ │ Risk Manager │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────┘
- Rust 1.70+ installed
- Lighter.xyz API key (for live trading)
- Variational wallet and session cookie (for Refund Farmer)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/protector_engine
cd protector_engine
# Build in release mode
cargo build --release# Simulation mode (no funds required)
cargo run --release
# With custom settings
cargo run --release -- --symbol ETH --orderbook# Set environment variables
export VARIATIONAL_COOKIE="your_session_cookie"
export VARIATIONAL_WALLET="0xYourWalletAddress"
export LIGHTER_PRIVATE_KEY="your_private_key"
# Run Refund Farmer
cargo run --release -- --farm# config.toml
[trading]
enabled = false # Set to true for live trading
private_key = "your_lighter_key"
[farming]
leverage = 30
collateral_usd = 100
target_volume = 1000000 # $1M for Bronze tier| Feature | Description |
|---|---|
| Kill Switch | Auto-halt on max loss ($1.00 default) |
| Position Limits | Max inventory (7 DOT / 0.5 ETH default) |
| Adverse Selection | Cancel on Binance move > 5 bps |
| Liquidation Guard | Warning at 2.2%, close at 2.8% (30x leverage) |
| Unhedged Guard | Auto-close Variational if hedge fails |
| Circuit Breaker | Shutdown if avg loss/trade > $0.08 |
| Stale Data Protection | Panic close if WebSocket lag > 1s |
| Doc | Description |
|---|---|
| Refund Farmer | Refund Farmer strategy guide |
| Architecture | System architecture and data flow |
| Multi-Exchange | Adding new exchange connectors |
| Live Trading | Live trading setup and safety |
| Simulation | Simulation mode for testing |
# Run tests
cargo test
# Test kill switch logic (no network/funds required)
cargo run --release -- --test-killswitch
# Test orders (requires private key + funds)
cargo run --release -- --test-orders| Command | Description |
|---|---|
cargo run -- --markets |
List available markets |
cargo run -- --orderbook DOT |
View order book for symbol |
cargo run -- --farm |
Run Refund Farmer |
cargo run -- --test-killswitch |
Test kill switch logic |
cargo run -- --test-orders |
Test order creation/cancellation |
This software is for educational purposes. Trading perpetual futures and DeFi derivatives involves substantial risk of loss.
- Test thoroughly in simulation mode before live trading
- Start with minimal capital
- The refund lottery is not guaranteed — odds range from 0.5% to 3% based on volume tier
- Never trade more than you can afford to lose
- Past performance does not indicate future results
MIT License — see LICENSE for details.
- Lighter.xyz for the exchange infrastructure
- Variational for the loss refund program
- Avellaneda & Stoikov for the market making framework