Skip to content

Testnet & Demo Account Setup Guide for Epic 6

This guide provides step-by-step instructions for setting up testnet and demo accounts required for Epic 6 (Live Trading Engine & Broker Integrations) development and testing.

Table of Contents


Overview

Epic 6 requires access to multiple broker testnet accounts and data API provider keys for comprehensive integration testing. This guide covers setup for:

Brokers: - Interactive Brokers (IB) Paper Trading - Binance Testnet - Bybit Testnet - Hyperliquid (Mainnet/Testnet) - CCXT-supported exchanges

Data Providers: - Polygon.io - Alpaca - Alpha Vantage


Broker Integrations

Interactive Brokers

Setup Steps:

  1. Create IB Account
  2. Visit: https://www.interactivebrokers.com
  3. Register for individual account
  4. Complete identity verification (may take 1-3 business days)

  5. Enable Paper Trading

  6. Log into Account Management
  7. Navigate to Settings → Paper Trading
  8. Enable paper trading account (instant activation)
  9. Note your paper trading account number

  10. Install TWS or IB Gateway

  11. Download TWS: https://www.interactivebrokers.com/en/trading/tws.php
  12. Alternative: IB Gateway (lighter, headless)
  13. Install and launch application

  14. Configure API Access

  15. In TWS: File → Global Configuration → API → Settings
  16. Enable ActiveX and Socket Clients: ✓
  17. Socket port: 7496 (paper) or 7497 (live)
  18. Master API client ID: Leave blank
  19. Read-Only API: ✗ (uncheck for trading)
  20. Trusted IP addresses: Add 127.0.0.1
  21. Click OK and restart TWS

  22. Test Connection

    # Create test script
    python -c "
    from ib_async import IB
    ib = IB()
    ib.connect('127.0.0.1', 7496, clientId=1)  # 7496 for paper trading
    print('Connected:', ib.isConnected())
    ib.disconnect()
    "
    

Configuration:

# .env
IB_HOST=127.0.0.1
IB_PORT=7496  # Paper trading
IB_CLIENT_ID=1

Ports: - TWS Paper: 7496 - TWS Live: 7497 - Gateway Paper: 4002 - Gateway Live: 4001


Binance Testnet

Setup Steps:

  1. Register for Testnet
  2. Visit: https://testnet.binance.vision
  3. Log in with GitHub account
  4. Generate API keys (no verification required)

  5. Create API Keys

  6. Click "Generate HMAC_SHA256 Key"
  7. Save API Key and Secret Key immediately
  8. Enable spot trading permissions

  9. Get Test Funds

  10. Use testnet faucet for test USDT/BTC
  11. Test funds refresh daily

Configuration:

# .env
BINANCE_TESTNET_API_KEY=your_testnet_api_key
BINANCE_TESTNET_API_SECRET=your_testnet_api_secret
BINANCE_TESTNET_URL=https://testnet.binance.vision

Endpoints: - REST API: https://testnet.binance.vision/api - WebSocket: wss://testnet.binance.vision/ws


Bybit Testnet

Setup Steps:

  1. Register for Testnet
  2. Visit: https://testnet.bybit.com
  3. Create account (email + password, no KYC)
  4. Verify email address

  5. Create API Keys

  6. Navigate to API Management
  7. Create new API key
  8. Enable: Read, Trade permissions
  9. Whitelist IP: 0.0.0.0/0 (testnet only!)
  10. Save API Key and Secret

  11. Get Test Funds

  12. Use testnet faucet in account page
  13. Request USDT for testing

Configuration:

# .env
BYBIT_TESTNET_API_KEY=your_bybit_testnet_key
BYBIT_TESTNET_API_SECRET=your_bybit_testnet_secret
BYBIT_TESTNET_URL=https://api-testnet.bybit.com


Hyperliquid

Setup Steps:

  1. Generate Ethereum Wallet
  2. Use MetaMask or generate keypair programmatically
  3. SECURITY: Use dedicated wallet for testnet only
  4. Never use mainnet wallet with significant funds

  5. Fund Wallet (if using mainnet)

  6. Transfer small amount of USDC to wallet
  7. Note: Hyperliquid testnet availability varies

  8. Store Private Key Securely

  9. Encrypt private key before storing
  10. Use environment variable or encrypted keystore

Configuration:

# .env
HYPERLIQUID_PRIVATE_KEY=encrypted:your_encrypted_private_key
HYPERLIQUID_NETWORK=mainnet  # or testnet if available

Security Warning: - Never commit private keys to version control - Use encrypted storage for private keys - Implement key rotation strategy


CCXT Exchanges

For CCXT-supported exchanges, register for testnet/demo accounts:

Recommended Exchanges for Testing: - Coinbase (sandbox): https://public.sandbox.pro.coinbase.com - Kraken (demo): Create demo account via support - OKX (demo): https://www.okx.com/demo-trading

Configuration:

# .env
CCXT_EXCHANGE_ID=binance  # or coinbase, kraken, okx
CCXT_API_KEY=your_api_key
CCXT_API_SECRET=your_api_secret
CCXT_TESTNET=true


Data API Providers

Polygon.io

Setup Steps:

  1. Register Account
  2. Visit: https://polygon.io
  3. Sign up for free tier (5 API calls/minute)
  4. Verify email address

  5. Get API Key

  6. Navigate to Dashboard → API Keys
  7. Copy your API key
  8. Note rate limits for your tier

Configuration:

# .env
POLYGON_API_KEY=your_polygon_api_key

Rate Limits: - Free: 5 requests/minute - Starter ($29/month): 10 requests/minute - Developer ($99/month): 100 requests/minute


Alpaca

Setup Steps:

  1. Register for Paper Trading
  2. Visit: https://alpaca.markets
  3. Sign up for free paper trading account
  4. No KYC required for paper trading

  5. Get API Keys

  6. Navigate to Paper Trading → API Keys
  7. Generate new API key pair
  8. Save Key ID and Secret Key

Configuration:

# .env
ALPACA_API_KEY=your_alpaca_key_id
ALPACA_API_SECRET=your_alpaca_secret_key
ALPACA_BASE_URL=https://paper-api.alpaca.markets  # Paper trading

Endpoints: - Paper Trading API: https://paper-api.alpaca.markets - Paper Data API: https://data.alpaca.markets - Live Trading API: https://api.alpaca.markets


Alpha Vantage

Setup Steps:

  1. Get Free API Key
  2. Visit: https://www.alphavantage.co/support/#api-key
  3. Enter email address
  4. Receive API key instantly (no verification)

  5. Note Rate Limits

  6. Free tier: 5 requests/minute, 500 requests/day
  7. Premium tiers available for higher limits

Configuration:

# .env
ALPHAVANTAGE_API_KEY=your_alphavantage_api_key


Environment Configuration

Complete .env Template

Create .env file in project root:

# Interactive Brokers
IB_HOST=127.0.0.1
IB_PORT=7496  # Paper: 7496, Live: 7497
IB_CLIENT_ID=1

# Binance
BINANCE_TESTNET_API_KEY=your_binance_testnet_key
BINANCE_TESTNET_API_SECRET=your_binance_testnet_secret
BINANCE_TESTNET_URL=https://testnet.binance.vision

# Bybit
BYBIT_TESTNET_API_KEY=your_bybit_testnet_key
BYBIT_TESTNET_API_SECRET=your_bybit_testnet_secret
BYBIT_TESTNET_URL=https://api-testnet.bybit.com

# Hyperliquid
HYPERLIQUID_PRIVATE_KEY=encrypted:your_encrypted_key
HYPERLIQUID_NETWORK=mainnet

# CCXT
CCXT_EXCHANGE_ID=binance
CCXT_API_KEY=your_ccxt_api_key
CCXT_API_SECRET=your_ccxt_api_secret
CCXT_TESTNET=true

# Data Providers
POLYGON_API_KEY=your_polygon_api_key
ALPACA_API_KEY=your_alpaca_key_id
ALPACA_API_SECRET=your_alpaca_secret_key
ALPACA_BASE_URL=https://paper-api.alpaca.markets
ALPHAVANTAGE_API_KEY=your_alphavantage_key

.gitignore Configuration

Ensure .env and sensitive files are excluded:

# Add to .gitignore
.env
.env.*
*.env
api_keys.ini
~/.rustybt/api_keys.ini
credentials.json
*.pem
*.key

Security Best Practices

API Key Management

  1. Never Commit Credentials
  2. Always use .env files (excluded from version control)
  3. Use environment variables in CI/CD
  4. Implement pre-commit hooks to detect secrets

  5. Encryption

  6. Encrypt private keys (Hyperliquid) using cryptography library
  7. Store encrypted keys in environment variables
  8. Use secure key derivation (PBKDF2, scrypt, or Argon2)

  9. Key Rotation

  10. Rotate API keys every 90 days
  11. Implement automated rotation for production
  12. Track key usage and expiration

  13. IP Whitelisting

  14. Whitelist development machine IPs for API access
  15. Use VPN for remote development
  16. Restrict production keys to specific IP ranges

Testnet Isolation

  1. Separate Credentials
  2. Use different API keys for testnet vs production
  3. Never reuse production credentials in testnet

  4. Labeling

  5. Clearly label testnet vs production in configs
  6. Use naming conventions (e.g., _TESTNET_ suffix)

  7. Monitoring

  8. Monitor API usage to detect unauthorized access
  9. Set up alerts for unusual activity

Troubleshooting

Interactive Brokers

Issue: "Cannot connect to TWS" - Solution: Verify TWS is running and API is enabled - Check port number (7496 for paper, 7497 for live) - Ensure 127.0.0.1 is whitelisted in TWS settings

Issue: "Socket connection refused" - Solution: Restart TWS and wait 30 seconds - Check firewall settings (allow port 7496/7497)

Binance/Bybit

Issue: "Invalid API key" - Solution: Regenerate API keys from testnet dashboard - Verify testnet URL is used (not production) - Check API key permissions are enabled

Issue: "Rate limit exceeded" - Solution: Implement exponential backoff - Reduce request frequency - Upgrade to paid tier if needed

Data Providers

Issue: "Quota exceeded" - Solution: Monitor API usage dashboard - Implement request caching - Upgrade to higher tier if needed

Issue: "Invalid symbol" - Solution: Check symbol format (provider-specific) - Use provider's symbol lookup API - Verify asset is supported by provider


Running Integration Tests

Once all accounts are configured:

# Run broker integration tests
pytest tests/integration/live/test_ib_integration.py --run-ib-integration
pytest tests/integration/live/test_exchange_integrations.py --run-exchange-integration

# Run data provider integration tests
pytest tests/integration/data/test_api_providers.py --run-api-integration

# Skip integration tests (default)
pytest tests/  # Integration tests skipped without flags

Test Markers: - @pytest.mark.ib_integration - Requires IB paper account - @pytest.mark.exchange_integration - Requires exchange testnet accounts - @pytest.mark.api_integration - Requires data API keys


Support & Resources

Documentation

  • Interactive Brokers: https://interactivebrokers.github.io/tws-api/
  • Binance Testnet: https://testnet.binance.vision/
  • Bybit Testnet: https://testnet.bybit.com/
  • Polygon: https://polygon.io/docs
  • Alpaca: https://alpaca.markets/docs
  • Alpha Vantage: https://www.alphavantage.co/documentation/

Community

  • CCXT: https://github.com/ccxt/ccxt
  • ib_async: https://github.com/erdewit/ib_insync

Last Updated: 2025-10-02