A modular paper-trading bot for BankNifty/Nifty using Angel One SmartAPI with deterministic mock data fallback.
- Paper Trading Only: Safe trading simulation with no real money at risk
- Angel One SmartAPI Integration: Real-time data feed with WebSocket support
- Mock Data Fallback: Deterministic seeded RNG for testing and development
- Breakout Strategy: EMA20 + Volume Spike + Price Breakout strategy
- Risk Management: Position sizing, stop losses, and capital protection
- IST Market Hours: Respects Indian market timing (09:30-14:30)
- Comprehensive Logging: JSON trade logs and daily summaries
- Unit Tests: Full test coverage for indicators and strategy logic
- Node.js 16+
- Angel One SmartAPI credentials (optional, for live data)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd hd_trade- Install dependencies:
npm install- Copy environment file:
cp env.sample .env- Configure your environment variables in
.env:
# Angel One SmartAPI Configuration (optional)
ANGEL_ONE_API_KEY=your_api_key_here
ANGEL_ONE_CLIENT_ID=your_client_id_here
ANGEL_ONE_PASSWORD=your_password_here
ANGEL_ONE_TOTP_SECRET=your_totp_secret_here
# Trading Configuration
PAPER_TRADING=true
STARTING_CAPITAL=1000
MAX_LOSS_PER_TRADE=100
MAX_CONSECUTIVE_SL=3
MIN_CAPITAL=500
# Strategy Configuration
EMA_PERIOD=20
ATR_PERIOD=14
ATR_SL_MULTIPLIER=1.5
ATR_TARGET_MULTIPLIER=3.0
VOLUME_SPIKE_THRESHOLD=1.5
# Mock Data (for testing)
MOCK_DATA_ENABLED=true
MOCK_DATA_SEED=12345npm run devnpm run papernpm run simulatenpm testnpm run lintnpm run formatThe bot implements a breakout strategy with the following conditions:
- Price Breakout: Current price breaks above previous 5-minute high
- EMA Filter: Price must be above EMA20
- Volume Spike: Current volume must be 1.5x above recent average
- Stop Loss: 1.5 Γ ATR(14) below entry price
- Target: 3.0 Γ ATR(14) above entry price
- Time Exit: Force exit at 14:30 IST
- Position Sizing: Based on max loss per trade (default βΉ100)
- Capital Protection: Minimum capital threshold (default βΉ500)
- Consecutive SL Limit: Stop trading after 3 consecutive stop losses
- One Position: Maximum one position at a time
βββ index.js # Main application entry point
βββ config.js # Configuration loader
βββ services/
β βββ priceFeed.js # Price data feed (SmartAPI/Mock)
β βββ smartApiClient.js # Angel One SmartAPI wrapper
β βββ strategyEngine.js # Trading strategy logic
β βββ tradeEngine.js # Position management
β βββ capitalManager.js # Risk and capital management
β βββ logger.js # Trade logging and summaries
βββ utils/
β βββ indicators.js # Technical indicators (EMA, ATR, etc.)
βββ data/
β βββ trades.json # Trade history log
β βββ daily-summary-*.json # Daily performance summaries
βββ tests/ # Unit tests
βββ scripts/
βββ simulate.js # Simulation runner
- EMA (Exponential Moving Average): Smooth price trend indicator
- ATR (Average True Range): Volatility-based stop loss and target calculation
- Average Volume: Volume spike detection for entry confirmation
- Paper Trading Default: All order execution is stubbed unless explicitly enabled
- Live Trading Lock: Requires
PAPER_TRADING=falseANDLIVE_TRADING_UNLOCK="I-know-what-I-am-doing" - Market Hours: Respects IST trading windows
- Capital Limits: Multiple safety checks prevent over-trading
All trades are logged to data/trades.json with:
- Entry/exit timestamps and prices
- Stop loss and target levels
- Trade result (TARGET HIT, SL HIT, TIME EXIT)
- P&L and capital updates
Optional daily summaries include:
- Win rate and total P&L
- Trade breakdown and statistics
- Drawdown analysis
- Consecutive loss tracking
Run the full test suite:
npm testRun specific test files:
npm test -- tests/indicators.test.js
npm test -- tests/strategyEngine.test.js
npm test -- tests/capitalManager.test.jsRun simulation:
npm run simulateThe simulation script generates:
- Mock trading day with 100+ candles
- Real-time strategy signal generation
- Position entry/exit simulation
- Capital tracking and P&L calculation
- JSON results file for analysis
- Paper Trading Only: This bot is designed for paper trading and learning purposes
- No Financial Advice: This software is not financial advice
- Risk Warning: Trading involves risk of loss
- IST Timezone: All times are in Indian Standard Time
- Market Hours: Bot only trades during market hours (09:30-14:30 IST)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Check the existing issues
- Create a new issue with detailed description
- Include logs and configuration details
Disclaimer: This software is for educational and paper trading purposes only. Trading involves risk of loss. Use at your own risk.