Automated cryptocurrency trading bots using Fear & Greed Index (FGI) signals. Supports both Drift Protocol (Solana) and Hyperliquid (EVM) perpetual futures DEXs.
- Multi-Exchange Support: Trade on Drift Protocol and Hyperliquid
- FGI-Based Strategy: Contrarian trading based on market sentiment
- Configurable Risk Management: Leverage, position sizing, stop losses
- PM2 Process Management: Production-ready deployment
- Backtesting Tools: Historical performance analysis
- Real-time Monitoring: Web dashboard for tracking positions
- Node.js 18+ or Bun runtime (recommended)
- Wallet with private key (Solana for Drift, Ethereum for Hyperliquid)
- Collateral funds (USDC on respective networks)
# Clone the repository
git clone https://github.com/yourusername/lifeguard-trading-core.git
cd lifeguard-trading-core
# Install dependencies with Bun (recommended)
bun install
# Or with npm
npm install- Copy the sample environment file:
cp .env.sample .env- Edit
.envwith your configuration:
# Solana wallet private key (base58 format)
SOLANA_PRIVATE_KEY=your_private_key_here
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
DRIFT_ENV=mainnet-beta # or 'devnet' for testing# Ethereum wallet private key (hex format with 0x prefix)
HYPERLIQUID_PRIVATE_KEY=0x...
HYPERLIQUID_TESTNET=true # Use testnet first!
HYPERLIQUID_ASSET=ETH
HYPERLIQUID_LEVERAGE=3# FGI check interval (ms)
FGI_CHECK_INTERVAL_MS=300000 # 5 minutes
# Risk management
LEVERAGE=3
MAX_POSITION_RATIO=1
MAX_DAILY_LOSS_PERCENT=50Both bots implement a contrarian FGI strategy:
- LONG when FGI < 30 (Extreme Fear) - "Buy when others are fearful"
- SHORT when FGI > 70 (Extreme Greed) - "Sell when others are greedy"
- HOLD when FGI is 30-70 (Neutral zone)
The strategy uses the 4-hour timeframe FGI data for ETH.
# Test Hyperliquid connection (no private key needed)
bun run src/test-hyperliquid-public.ts
# Test FGI data feed
bun run src/test-hyperliquid-fgi.ts# Start all bots
npm run pm2:start
# Start specific bot
npm run bot:hyperliquid:start # Hyperliquid only
pm2 start ecosystem.config.js --only drift-fgi-trader # Drift only
# Monitor logs
npm run bot:hyperliquid:logs
pm2 logs drift-fgi-trader
# Stop bots
npm run bot:hyperliquid:stop
pm2 stop all# Run Hyperliquid bot
bun run src/bots/hyperliquid-fgi-trader.ts
# Run Drift bot
bun run drift-fgi-trader-v2.tsHyperliquid Testnet:
- Set
HYPERLIQUID_TESTNET=truein.env - Get test funds: https://faucet.hyperliquid.xyz/
- Test with small positions first
Drift DevNet:
- Set
DRIFT_ENV=devnetin.env - Get devnet SOL:
solana airdrop 2 - Get devnet USDC:
npm run devnet:fund
Run historical simulations before live trading:
# Run backtest with current parameters
npm run backtest
# Monthly performance analysis
npm run backtest:monthly- Position Limits: Max position size caps
- Liquidation Buffer: Maintains 15% safety margin
- Daily Loss Limits: Stops trading after 50% daily loss
- Manual Override: Close positions anytime with:
# Force close all Drift positions npm run trade:close # Stop all bots immediately pm2 stop all
# Start web dashboard (port 3000)
cd web && npm run dev
# View at http://localhost:3000# View all processes
pm2 status
# Real-time logs
pm2 logs
# Process metrics
pm2 monitAll trades are logged to trading.db SQLite database:
# View recent trades
sqlite3 trading.db "SELECT * FROM trades ORDER BY timestamp DESC LIMIT 10;"lifeguard-trading-core/
βββ src/
β βββ bots/
β β βββ hyperliquid-fgi-trader.ts # Hyperliquid FGI bot
β βββ services/
β β βββ hyperliquid-client.ts # HL SDK initialization
β β βββ hyperliquid-account.ts # Account management
β β βββ hyperliquid-trade.ts # Order execution
β β βββ hyperliquid-market.ts # Market data
β βββ test-*.ts # Test scripts
βββ drift-fgi-trader-v2.ts # Drift FGI bot
βββ ecosystem.config.js # PM2 configuration
βββ web/ # Dashboard UI
βββ backtesting/ # Backtest tools
βββ docs/ # Documentation
β βββ plans/ # Implementation plans
β βββ todos/ # Task lists
βββ .env.sample # Configuration template
Edit the bot files to adjust thresholds:
// src/bots/hyperliquid-fgi-trader.ts
const CONFIG = {
longThreshold: 30, // Adjust fear threshold
shortThreshold: 70, // Adjust greed threshold
}To trade different assets, create separate PM2 processes:
// ecosystem.config.js
{
name: 'hyperliquid-btc-trader',
env: {
HYPERLIQUID_ASSET: 'BTC',
// ... other config
}
}-
"HYPERLIQUID_PRIVATE_KEY not set"
- Add your private key to
.envfile - Never commit
.envto git!
- Add your private key to
-
"Insufficient balance"
- Add collateral to your wallet
- For testnet: use faucets
- For mainnet: deposit USDC
-
"Market is closed"
- Check exchange status
- May occur during maintenance
-
Connection timeouts
- Check network connection
- Try alternative RPC endpoints
- Increase timeout in client config
Enable detailed logging:
# Run with debug output
DEBUG=* bun run src/bots/hyperliquid-fgi-trader.ts
# Check PM2 error logs
pm2 logs --err- NEVER share or commit private keys
- Use separate wallets for testing
- Start with small position sizes
- Monitor positions regularly
- Set up alerts for large drawdowns
Track your trading performance:
# View daily P&L
cat daily-performance.json
# Database analytics
sqlite3 trading.db "
SELECT
date(timestamp) as day,
count(*) as trades,
sum(case when action like '%CLOSE%' then price * size else 0 end) as volume
FROM trades
GROUP BY day
ORDER BY day DESC;
"- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file
This software is for educational purposes only.
- Trading cryptocurrencies involves substantial risk
- Past performance does not guarantee future results
- Never trade with funds you cannot afford to lose
- The authors are not responsible for any financial losses
- Issues: Open a GitHub issue
- Documentation: Check
/docsfolder - Hyperliquid Docs: https://hyperliquid.gitbook.io
- Drift Docs: https://docs.drift.trade
Built with β€οΈ using TypeScript, Bun, and the power of contrarian trading.