NadirAliOfficial
ninabot
JavaScriptโœจ New

๐Ÿค– IBKR Algorithmic Trading Bot โ€” Auto trading with EMA, RSI, MACD, Bollinger Bands | FastAPI + React dashboard | 6 trading modes | Real-time WebSocket

Last updated Jul 4, 2026
13
Stars
1
Forks
0
Issues
0
Stars/day
Attention Score
48
Language breakdown
JavaScript 76.7%
Python 22.7%
Batchfile 0.4%
HTML 0.2%
โ–ธ Files click to expand
README

๐Ÿค– NINABOT v3

IBKR Algorithmic Trading Bot

Python FastAPI React IBKR License

Fully automated trading bot for Interactive Brokers with a live React dashboard. Supports stocks, crypto, futures, forex, and CFDs โ€” with built-in risk management and 6 trading modes.

Features โ€ข Setup โ€ข Trading Modes โ€ข Architecture โ€ข Risk Management


โœจ Features

| | Feature | |---|---| | ๐Ÿ“ก | Live TWS connection via ibapi 9.81.1 with auto-reconnect every 15s | | ๐Ÿง  | Signal engine โ€” EMA, RSI, MACD, Bollinger Bands, ATR combined into a 0-100 score | | โšก | 6 trading modes โ€” scalp, daytrade, swing, trend, crypto night, safe | | ๐Ÿ“ | Auto position sizing using Kelly criterion based on NAV + conviction score | | ๐Ÿ›ก๏ธ | Risk management โ€” kill switch, circuit breakers, drawdown limits | | ๐Ÿ’น | Multi-asset โ€” stocks, crypto, futures, forex, CFDs, options | | ๐Ÿ“Š | React dashboard with real-time WebSocket updates (P&L, positions, logs) | | ๐Ÿฆ | Social sentiment โ€” optional Twitter/X scoring per instrument | | ๐Ÿ” | Yahoo Finance fallback when IBKR live data is unavailable | | ๐Ÿ”’ | Bracket orders โ€” automatic Stop Loss & Take Profit on every trade |


๐Ÿš€ Setup

Prerequisites


Step 1 โ€” Configure TWS API

In TWS: Edit โ†’ Global Configuration โ†’ API โ†’ Settings

  • โœ… Enable ActiveX and Socket Clients
  • โœ… Port: 7496 (live) or 7497 (paper trading)
  • โœ… Enable Allow connections from localhost only

Step 2 โ€” Configure .env

Open backend/.env and fill in your account number:

IBKR_ACCOUNT=UXXXXXXXX    # Your IBKR account number (starts with U)
TWS_PORT=7496              # 7496 = live | 7497 = paper trading

Step 3 โ€” Install dependencies (first time only)

# Backend
cd backend
py -3.12 -m venv venv
venv\Scripts\activate          # Windows

source venv/bin/activate # Mac/Linux

pip install -r requirements.txt

Frontend

cd ../frontend npm install

Step 4 โ€” Run

Windows โ€” double-click:

LANCER_BOT.bat    โ† Start ARRETER_BOT.bat   โ† Stop

Manual:

# Terminal 1 โ€” Backend cd backend && venv\Scripts\activate && python main.py

Terminal 2 โ€” Frontend

cd frontend && npm run dev

Live URLs

| Service | URL | |---|---| | ๐Ÿ–ฅ๏ธ Dashboard | http://localhost:5173 | | ๐Ÿ”Œ API Health | http://localhost:8000/health | | ๐Ÿ“ก Scan Status | http://localhost:8000/scan/status |


๐Ÿ“Š Trading Modes

| Mode | EMA | RSI Band | Risk % | Max Trades | Scan | Description | |---|---|---|---|---|---|---| | scalp | 9/21 | 35โ€“65 | 0.5% | 20 | 5s | Flash profit, max reactivity | | daytrade | 21/50 | 35โ€“65 | 1.0% | 8 | 30s | Short sessions, regular profits | | swing | 50/200 | 30โ€“70 | 1.5% | 3 | 120s | Max profit, high TP | | trend | 50/200 | 35โ€“65 | 1.0% | 5 | 60s | Pure trend following | | crypto_night | 20/100 | 28โ€“72 | 0.8% | 6 | 20s | BTC/ETH 24/7, high volatility | | safe | 34/150 | 40โ€“60 | 0.3% | 2 | 120s | Capital preservation, minimal risk |


๐Ÿง  Signal Engine

Each instrument is scored 0โ€“100 by combining:

EMA crossover   โ†’  25 pts   (trend direction)
RSI             โ†’  20 pts   (overbought / oversold)
MACD            โ†’  15 pts   (momentum)
Bollinger Bands โ†’  15 pts   (volatility squeeze)
ATR             โ†’  10 pts   (volatility filter)
Sentiment       โ†’   5 pts   (Twitter/X โ€” optional)
Signal fires when score โ‰ฅ min_conviction threshold (configurable per mode)

๐Ÿ›ก๏ธ Risk Management

  • Kill switch โ€” auto-stops bot if drawdown exceeds threshold
  • Max drawdown: 5% of NAV (configurable)
  • Max position size: 2% of NAV per trade
  • Daily loss limit: $10,000 (configurable)
  • Consecutive losses: position size halved after every 2 losses (anti-martingale)
  • Retry queue: failed orders retried up to 3x with backoff (2s โ†’ 5s โ†’ 15s)

๐Ÿ—๏ธ Architecture

ninabot/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI server + WebSocket hub
โ”‚   โ”œโ”€โ”€ ibkr_client.py       # TWS connection, orders, positions, prices
โ”‚   โ”œโ”€โ”€ auto_trader.py       # Trading loop, signal engine, position manager
โ”‚   โ”œโ”€โ”€ price_feed.py        # IBKR live + Yahoo Finance fallback
โ”‚   โ”œโ”€โ”€ risk_manager.py      # Circuit breakers, kill switch, drawdown
โ”‚   โ”œโ”€โ”€ social_monitor.py    # Twitter/X sentiment scoring
โ”‚   โ”œโ”€โ”€ config.py            # Pydantic settings from .env
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ””โ”€โ”€ .env                 # โ† configure this
โ”œโ”€โ”€ frontend/
โ”‚   โ””โ”€โ”€ src/App.jsx          # React real-time dashboard
โ”œโ”€โ”€ LANCER_BOT.bat           # One-click start (Windows)
โ””โ”€โ”€ ARRETER_BOT.bat          # One-click stop (Windows)

โš™๏ธ Environment Variables

| Variable | Default | Description | |---|---|---| | IBKR_ACCOUNT | (required) | IBKR account number (starts with U) | | TWS_HOST | 127.0.0.1 | TWS host | | TWS_PORT | 7496 | 7496 = live ยท 7497 = paper | | TWSCLIENTID | 1 | API client ID | | MAXDRAWDOWNPCT | 5.0 | Kill switch threshold (% of NAV) | | MAXPOSITIONPCT | 2.0 | Max trade size (% of NAV) | | DAILYLOSSLIMIT | 10000.0 | Daily loss cap | | TWITTERBEARERTOKEN | (optional) | Twitter/X API for sentiment | | API_HOST | 0.0.0.0 | Backend bind address | | API_PORT | 8000 | Backend port |


๐Ÿ“ก API Endpoints

| Method | Endpoint | Description | |---|---|---| | GET | /health | Bot status + IBKR connection | | GET | /snapshot | Full account snapshot | | POST | /order | Place an order | | DELETE | /order/{id} | Cancel an order | | POST | /position/close | Close a position | | POST | /positions/close_all | Close all positions | | POST | /auto/start | Start auto trader | | POST | /auto/stop | Stop auto trader | | GET | /auto/status | Auto trader status | | GET | /performance | P&L + win rate | | GET | /risk/status | Risk manager state | | POST | /risk/kill | Emergency kill switch | | WS | /ws | Real-time WebSocket stream |


Built with โค๏ธ for algorithmic traders ยท Interactive Brokers TWS API

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท NadirAliOfficial/ninabot ยท Updated daily from GitHub