Newer
Older
scalping-bot / testnet.md

Bybit Testnet Setup Guide - 2025

Important Notes

⚠️ DO NOT deposit real funds to testnet - Any real money deposited to testnet will be permanently lost
⚠️ Testnet ≠ Mainnet - They are completely separate environments
Testnet funds have no real value - You can test risk-free indefinitely


STEP 1: Register Testnet Account

  1. Open testnet in your browser: https://testnet.bybit.com
  2. Click "Sign Up" in the top right corner
  3. Choose registration method:
    • Email address (recommended for bot automation)
    • Phone number
  4. Enter your email/phone and create a password
  5. Complete 2FA security verification - enter the code sent to your email/SMS (expires in 5 minutes)
  6. ✅ Account created! You now have a testnet account separate from mainnet

STEP 2: Request Test Coins (Free Virtual Funds)

Once logged in to testnet:

  1. Click "Assets" in the top navigation
  2. Click "Assets Overview"
  3. Click "Request Test Coins" button
  4. Confirm the request in the popup
  5. ✅ You'll receive:
    • 50,000 USDT (stablecoin)
    • 50,000 USDC
    • 1 BTC (Bitcoin)
    • 1 ETH (Ethereum)

Can request once every 24 hours - Funds will replenish if equity drops below 10,000 USDT


STEP 3: Create API Key for Bot Integration

Access API Management

  1. Go to: https://testnet.bybit.com/app/user/api-management
    • OR click your account icon (top right) → API
  2. Click "Create New Key" on the right side

Configure API Key Permissions

In the popup, set the following permissions:

Required for Scalping Bot:

  • Account Transfer - to check balance
  • Order - to place/cancel orders (Place order, Cancel order, Modify order)
  • Position - to monitor positions
  • Market - read-only market data

Optional (for advanced features):

  • Wallet - if you need deposit/withdrawal tracking

IP Whitelist (Security)

  • Option 1: Add your server IP (recommended for production)
  • Option 2: Leave empty for testing (⚠️ less secure)
  • For local development: Use your current public IP (find it at https://ifconfig.me)

Complete Setup

  1. Enter your Google Authenticator 2FA code
  2. Click "Submit"
  3. Copy and save:
    • API Key
    • API Secret
    • ⚠️ Store these securely - never share them

STEP 4: Configure Your Java Bot for Testnet

Option A: Using Environment Variables (Recommended)

# Linux/Mac
export BYBIT_TESTNET_API_KEY="your_api_key_here"
export BYBIT_TESTNET_API_SECRET="your_api_secret_here"

# Windows (Command Prompt)
set BYBIT_TESTNET_API_KEY=your_api_key_here
set BYBIT_TESTNET_API_SECRET=your_api_secret_here

# Windows (PowerShell)
$env:BYBIT_TESTNET_API_KEY="your_api_key_here"
$env:BYBIT_TESTNET_API_SECRET="your_api_secret_here"

Option B: Using application.yml

# application-testnet.yml
spring:
  application:
    name: scalping-bot

trading:
  environment: testnet
  apiKey: ${BYBIT_TESTNET_API_KEY}
  apiSecret: ${BYBIT_TESTNET_API_SECRET}
  baseUrl: https://api-testnet.bybit.com
  wsUrl: wss://stream-testnet.bybit.com
  
  # Risk settings - can be aggressive in testnet
  maxConcurrentTrades: 10
  maxLossPerSession: 500.0  # $500 virtual loss limit
  volatilityThreshold: 0.10  # 10% volatility emergency stop
  
  useMockApi: false
  useTestnet: true

Option C: Using Properties File

# application-testnet.properties
trading.environment=testnet
trading.apiKey=${BYBIT_TESTNET_API_KEY}
trading.apiSecret=${BYBIT_TESTNET_API_SECRET}
trading.baseUrl=https://api-testnet.bybit.com
trading.wsUrl=wss://stream-testnet.bybit.com
trading.maxConcurrentTrades=10
trading.maxLossPerSession=500.0
trading.useTestnet=true
trading.useMockApi=false

STEP 5: Run Your Bot on Testnet

Start with correct Spring Profile

# Using Maven
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=testnet"

# Using Java directly
java -jar scalping-bot.jar --spring.profiles.active=testnet

# Using Gradle
gradle bootRun --args='--spring.profiles.active=testnet'

Verify Connection

Your application logs should show:

[INFO] Environment set to: testnet
[INFO] Testnet client initialized
[INFO] Connecting to: https://api-testnet.bybit.com
[INFO] WebSocket connection to testnet established
[INFO] Account balance: 50000.00 USDT, 1.00 BTC

STEP 6: Test Your Bot

Testing Workflow

  1. Place test orders (small amounts)

    POST /api/bot/place-order?symbol=BTCUSDT&quantity=0.001&price=43000
  2. Monitor order status

    GET /api/bot/status
  3. Check market data

    GET /api/bot/market/BTCUSDT
  4. View analytics & PnL

    GET /api/bot/analytics

Common Test Scenarios

✅ Test order placement with various symbols:

  • BTCUSDT (Bitcoin)
  • ETHUSDT (Ethereum)
  • SOLUSDT (Solana)
  • XRPUSDT (Ripple)

✅ Test order cancellation

✅ Test risk management triggers

✅ Test crash recovery (kill app, restart, check recovered trades)

✅ Test extreme volatility emergency stop

✅ Test API connection failures (simulate with mock failures)


STEP 7: Monitor Your Bot

Real-time Dashboard

Watch your bot trading on testnet dashboard: https://testnet.bybit.com

Check Order History

  1. Navigate to Trading tab
  2. View Open Orders and Order History
  3. Verify bot-placed orders appear here

API Response Monitoring

View logs from your Java bot:

2025-11-26 14:32:15 [INFO] Market data - BTCUSDT: price=43250.50, volume=1000.0
2025-11-26 14:32:16 [INFO] Order placed: abc-123 - Symbol: BTCUSDT, Qty: 0.001, Price: 43000
2025-11-26 14:32:17 [INFO] Order cancelled: abc-123
2025-11-26 14:32:18 [INFO] Session loss updated: -10.50

STEP 8: Transition to Production (When Ready)

Before Going Live

⚠️ Checklist:

  • All unit tests passing
  • 100+ successful testnet trades completed
  • Emergency stop tested and working
  • Recovery mechanism verified after crashes
  • Risk management tested with edge cases
  • API key permissions minimized (order placement only)
  • Code reviewed for security vulnerabilities

Switch to Mainnet

  1. Create API keys on mainnet: https://www.bybit.com/app/user/api-management
  2. Change Spring profile to production
  3. Update environment variables:
    export BYBIT_MAINNET_API_KEY="your_mainnet_key"
    export BYBIT_MAINNET_API_SECRET="your_mainnet_secret"
  4. Start with minimal position sizes ($50-100 first trades)

API Endpoints Reference

Testnet URLs

REST API:     https://api-testnet.bybit.com
WebSocket:    wss://stream-testnet.bybit.com
Web Dashboard: https://testnet.bybit.com

Mainnet URLs (Production)

REST API:     https://api.bybit.com
WebSocket:    wss://stream.bybit.com
Web Dashboard: https://www.bybit.com

Troubleshooting

Issue: "API key not found"

  • Wait 48 hours after account creation (new user restriction)
  • Check API key has correct permissions
  • Verify IP whitelist (if configured)

Issue: "Invalid API key signature"

  • Verify API secret is copied correctly
  • Check server time sync (must be within 5 seconds of Bybit server)
  • Ensure you're using HMAC SHA256 signature

Issue: "No test coins received"

  • Refresh the page (might take 1-2 seconds)
  • Clear browser cache
  • Try requesting again (24-hour cooldown)

Issue: "Connection refused"

  • Verify you're using testnet URLs (not mainnet)
  • Check firewall/VPN isn't blocking WebSocket
  • Confirm internet connection

Issue: "Insufficient balance"

  • Request more test coins (available every 24 hours)
  • Reduce position size
  • Verify you're using USDT pairs (not other assets)

Best Practices for Testnet Trading

  1. Test all edge cases - Push your bot to extremes
  2. Use small sizes - Verify logic before larger trades
  3. Run 24/7 if possible - Test overnight behavior
  4. Test network failures - Disconnect internet, resume connection
  5. Document trades - Note what worked, what didn't
  6. Keep logs - Archive for historical analysis
  7. Never automate production - Requires explicit confirmation
  8. Reset regularly - Request new test coins to keep balance high

Security Notes

🔐 Testnet API Key Security:

  • Testnet funds are worthless, so it's less critical than mainnet
  • Still practice good security habits (not in version control)
  • Still enable IP whitelist if possible

🔐 Before Mainnet:

  • Use encrypted credential storage (JCE Keystore recommended)
  • Implement rate limiting on your bot
  • Add monitoring/alerts for suspicious activity
  • Test with read-only API key first
  • Use IP whitelist on all API keys

Next Steps

  1. ✅ Register testnet account (Step 1)
  2. ✅ Request test coins (Step 2)
  3. ✅ Create API key (Step 3)
  4. ✅ Configure bot (Step 4)
  5. ✅ Run bot (Step 5)
  6. ✅ Test scenarios (Step 6)
  7. ✅ Monitor & iterate (Step 7)
  8. ⏱️ Go live when confident (Step 8)

Good luck with your scalping bot! 🚀