Real-time market depth visualization and trading signal generation for Interactive Brokers
A comprehensive Level 2 order book analysis system that:
- 📈 Visualizes real-time bid/ask depth from IBKR
- 🎯 Generates BUY/SELL/NEUTRAL trading signals
- 🔍 Detects hidden buyers, sellers, and iceberg orders
- 🗺️ Shows liquidity heatmaps and support/resistance
- ⏰ Works during premarket, regular hours, and afterhours
- 🌐 Web-based dashboard accessible from any browser
Perfect for: Day traders, scalpers, swing traders analyzing order flow and institutional activity.
- ✅ Interactive Brokers account (paper or live)
- ✅ Level 2 market data subscription (~$10/month)
- ✅ Python 3.8+
- ✅ TWS or IB Gateway
pip install ib_insync pandas numpy pytz dash plotly- Launch TWS/Gateway
- Enable API: File → Global Configuration → API → Settings
- Check "Enable ActiveX and Socket Clients"
- Note port: 7497 (paper) or 7496 (live)
python unified_dashboard.py AAPLOpen browser to: http://127.0.0.1:8050
That's it! 🚀
- Quick Start Guide - Get running in 10 minutes
- Full Setup Guide - Complete walkthrough
- Troubleshooting - Fix common issues
- Configuration Examples - Customize for your style
- System Files:
level2_unified_system.py- Core engineunified_dashboard.py- Web interfaceRUN_DASHBOARD.bat- Windows launcher
✅ Real-time Order Book
- Live bid/ask depth (up to 20 levels)
- Aggregated across exchanges
- Best bid/ask highlighting
- Volume at each price level
✅ Trading Signals
- BUY/SELL/NEUTRAL with confidence scores
- Multiple factor analysis
- Queue imbalance calculation
- Microprice-based signals
✅ Hidden Order Detection
- Hidden buyers (absorbing sells)
- Hidden sellers (absorbing buys)
- Iceberg order identification
- Accumulation/distribution alerts
✅ Visual Analytics
- Liquidity heatmap
- Support/resistance levels
- Price movement charts
- Spread and imbalance tracking
- Volume pressure gauges
✅ Extended Hours Support
- Premarket (4:00 AM - 9:30 AM ET)
- Regular hours (9:30 AM - 4:00 PM ET)
- Afterhours (4:00 PM - 8:00 PM ET)
- Session indicator and warnings
- Order Book - Visual bid/ask depth
- Signal Panel - Current trading recommendation
- Hidden Orders - Alert box for unusual activity
- Heatmap - Liquidity visualization
- Charts - Price, spread, imbalance over time
- Stats - Spread (bps), microprice, session info
- Python 3.8+
- 2GB RAM
- IBKR account with Level 2 data
- Internet connection (5+ Mbps)
- Python 3.10+
- 4GB+ RAM
- Dual monitors
- Fast internet (10+ Mbps)
- Liquid stocks (SPY, AAPL, TSLA, QQQ)
- Software: Free
- IBKR Account: Free (with minimum balance)
- Level 2 Data: ~$10-15/month
- Total: ~$10-15/month
The system analyzes multiple factors:
-
Queue Position Imbalance
- Weighted bid vs ask volume
- Distance-adjusted pressure
- Top-level size comparison
-
Hidden Order Detection
- Volume vs price movement divergence
- Order book refresh patterns
- Absorption analysis
-
Spread Analysis
- Tight spread = confidence
- Wide spread = uncertainty
- BPS calculation for standardization
-
Confluence Scoring
- Multiple factors agreeing = higher confidence
- Contradicting factors = lower confidence
| Score | Meaning | Reliability |
|---|---|---|
| 80%+ | Very Strong | High - consider entry |
| 60-79% | Strong | Good - verify with analysis |
| 40-59% | Moderate | Weak - wait for confirmation |
| <40% | Weak | Low - likely ignore |
🟢 BUY (75% confidence)
Reasons:
• Strong queue imbalance: +0.45
• Hidden buyer detected at $150.25
• Volume surge at best bid
• Tight spread (5 bps)
What this means:
- More buyers than sellers in queue
- Large player absorbing sells
- Bullish pressure building
What to do:
- Verify with your strategy
- Check higher timeframe trend
- Look for confirmation (volume, momentum)
- Enter with stop loss if appropriate
🔴 SELL (68% confidence)
Reasons:
• Heavy selling pressure
• Queue imbalance: -0.52
• Breaking support level
• Hidden seller at $150.30
What this means:
- More sellers than buyers in queue
- Large player distributing
- Bearish pressure building
What to do:
- Consider exiting longs
- Wait for better entry if planning to buy
- Or short if that fits your strategy
⚪ NEUTRAL (35% confidence)
Reasons:
• Balanced order book
• Low volume
• No clear direction
What this means:
- Market is balanced
- Wait for clearer setup
What to do:
- Don't force trades
- Wait for BUY or SELL signal
Hidden Order Detection
Hidden Buyers
Pattern: Heavy selling, but price stable or rising
Interpretation:
- Large buyer absorbing all sells
- Not showing full size on order book
- Accumulation happening
Trading Action:
- Bullish signal
- Good time to buy
- Big player building position
Hidden Sellers
Pattern: Heavy buying, but price stable or falling
Interpretation:
- Large seller absorbing all buys
- Distribution happening
- Supply overwhelming demand
Trading Action:
- Bearish signal
- Avoid buying
- Consider selling
Pattern: Order at price level keeps refreshing
Example:
10:30:00 → 500 shares at $150.00
10:30:05 → Filled
10:30:06 → 500 shares at $150.00 (refreshed!)
10:30:11 → Filled
10:30:12 → 500 shares at $150.00 (refreshed again!)
Interpretation:
- Large order hiding true size
- Shows only small piece at a time
- Strong support (if bid) or resistance (if ask)
Trading Action:
- Hard to move through that price
- If bid iceberg = support level
- If ask iceberg = resistance level
- Start with paper trading (port 7497)
- Use liquid stocks (SPY, AAPL, TSLA, QQQ, MSFT)
- Trade regular hours initially (9:30 AM - 4:00 PM ET)
- Wait for 60%+ confidence signals
- Verify with other analysis (charts, indicators, news)
- Always use stop losses
- Track your results over time
- Start small and scale gradually
- Don't blindly follow signals - verify first
- Don't trade illiquid stocks (<1M daily volume)
- Don't overtrade on low confidence signals
- Don't ignore spreads - wide spreads = risky
- Don't fight the trend - check higher timeframe
- Don't use without stops - always protect capital
- Don't expect perfection - no system is 100%
- Fast entries/exits based on order flow
- Scalp spreads and imbalances
- Catch momentum shifts early
- Find optimal entry points
- Identify accumulation/distribution
- Confirm support/resistance levels
- Spot hedging activity in underlying
- Detect pin risk near strikes
- Time entries around order flow
- Monitor spread dynamics
- Track queue position
- Identify liquidity gaps
Can't connect? → Start TWS/Gateway, enable API, check port
No data? → Subscribe to Level 2, wait 24hrs activation
Dashboard won't open? → Check terminal for URL, copy to browser
Only see 2-3 levels? → Normal for low liquidity or extended hours
Signals seem wrong? → Remember: suggestions not facts. Always verify.
See Troubleshooting Guide for detailed solutions
level2_system/
├── level2_unified_system.py # Core engine
├── unified_dashboard.py # Web dashboard
├── RUN_DASHBOARD.bat # Windows launcher
│
├── LEVEL2_SETUP_GUIDE.md # Full setup guide
├── LEVEL2_QUICK_START.md # 10-minute quickstart
├── LEVEL2_TROUBLESHOOTING.md # Problem solutions
├── LEVEL2_CONFIG_EXAMPLES.md # Configuration examples
└── README.md # This file
# SPY (very liquid, tight spreads)
python unified_dashboard.py SPY
# TSLA (volatile, good for signals)
python unified_dashboard.py TSLA
# QQQ (tech ETF, consistent)
python unified_dashboard.py QQQ
# Custom symbol
python unified_dashboard.py YOUR_SYMBOL# Regular hours only (default)
system = UnifiedLevel2System(
symbol='AAPL',
use_extended_hours=False
)
# Include premarket/afterhours
system = UnifiedLevel2System(
symbol='AAPL',
use_extended_hours=True
)# Paper trading (safe for testing)
port=7497
# Live trading (use with caution!)
port=7496IBKR TWS/Gateway
↓
Level 2 API
↓
level2_unified_system.py
↓
Signal Generation & Detection
↓
unified_dashboard.py
↓
Web Browser Dashboard
- Market Data: Real-time (milliseconds)
- Dashboard: Configurable (default 1 second)
- Signals: Generated on every update
- Hidden Orders: Analyzed every update
- Order Book: Current state only
- Price History: 200 points (configurable)
- Signals: 200 historical (configurable)
- Imbalances: 200 points (configurable)
In unified_dashboard.py:
dcc.Interval(
interval=1000, # Change to 500 for faster, 2000 for slower
n_intervals=0
)Change Hidden Order Sensitivity
In level2_unified_system.py:
detector = HiddenOrderDetector(
lookback_seconds=60, # How far back to look
sensitivity='medium' # low, medium, or high
)In level2_unified_system.py:
self.ib.reqMktDepth(
contract,
numRows=20, # Max 20, try 10 for faster updates
isSmartDepth=True
)See Configuration Examples for more
-
Educational Software
- This is for learning and analysis
- Not financial advice
- Not guaranteed to be profitable
-
Market Risks
- Trading involves substantial risk
- You can lose more than you invest
- Past performance ≠ future results
-
System Limitations
- Signals are suggestions, not facts
- Hidden orders can disappear instantly
- Large players can spoof the book
- No system is 100% accurate
-
Your Responsibility
- Test thoroughly in paper first
- Understand what you're trading
- Use proper risk management
- Never risk more than you can afford to lose
- Comply with all regulations (PDT rules, etc.)
- Month 1: Paper trade only - learn the system
- Month 2: Paper trade - develop strategy
- Month 3: Paper trade - verify consistency
- Month 4: If profitable, start live with 1-share positions
- Month 5+: Gradually increase size based on results
- 📖 Quick Start: Fast setup in 10 minutes
- 📚 Full Guide: Complete walkthrough
- 🔧 Troubleshooting: Fix common problems
- ⚙️ Configuration: Customize for your needs
- IBKR API: https://interactivebrokers.github.io/tws-api/
- ib_insync: https://ib-insync.readthedocs.io/
- Dash: https://dash.plotly.com/
- Check Troubleshooting Guide
- Enable debug logging (see guide)
- Check TWS logs for errors
- Verify Level 2 subscription is active
- Contact IBKR support for account issues
Found a bug? Have a suggestion? Want to improve the docs?
Feel free to:
- Report issues you encounter
- Suggest feature improvements
- Share configuration optimizations
- Contribute code enhancements
This software is provided as-is for educational purposes.
No warranty of any kind. Use at your own risk.
Not affiliated with Interactive Brokers or any financial institution.
Current Version: 1.0
Features:
- ✅ Real-time Level 2 data
- ✅ Signal generation
- ✅ Hidden order detection
- ✅ Web dashboard
- ✅ Extended hours support
- ✅ Support/resistance detection
- ✅ Comprehensive documentation
Built with:
- ib_insync - IBKR API wrapper
- Dash/Plotly - Web dashboard
- Python - Core language
Thanks to the open-source community!
Remember:
- 🎯 Signals are tools, not guarantees
- 📊 Always verify with your own analysis
- 💰 Use proper risk management
- 📈 Start small and scale gradually
- 🧠 Keep learning and improving
⚠️ Never risk more than you can afford to lose
Trade safe. Trade smart. Good luck! 🚀
For detailed setup instructions, see LEVEL2_SETUP_GUIDE.md
For quick start, see LEVEL2_QUICK_START.md