β οΈ IMPORTANT DISCLAIMER: This bot is for educational and research purposes. Automated trading involves substantial financial risk. Always test thoroughly with paper trading before considering any live implementation.
The NOTAM Trading Bot is an automated system that monitors aviation NOTAMs (Notice to Airmen) for critical airspace closures and automatically executes trading strategies when specific conditions are met. The bot integrates NOTAM monitoring, AI interpretation via ChatGPT, WhatsApp notifications, and automated trading through Interactive Brokers.
- Real-time NOTAM monitoring from FAA sources
- AI-powered interpretation using ChatGPT API for clear explanations
- Automatic trading execution with configurable portfolios
- WhatsApp notifications with detailed alerts and summaries
- Multiple trading modes (Paper/Live trading)
- Risk-based portfolios (Conservative/Moderate/Aggressive)
- Comprehensive logging and event tracking
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β NOTAM Sources βββββΆβ NOTAM Monitor βββββΆβ ChatGPT API β
β (FAA/ICAO) β β & Analysis β β (Interpretation)β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β WhatsApp API ββββββ Trading Bot βββββΆβ Interactive β
β (Notifications)β β Core System β β Brokers API β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
-
Python 3.8+ with required packages:
pip install ib_insync requests beautifulsoup4 lxml
-
Interactive Brokers Account and TWS/Gateway installed
-
OpenAI API Key for ChatGPT integration
-
WhatsApp Integration (TimelinesAI service)
-
Set OpenAI API Key:
export OPENAI_API_KEY="your-openai-api-key"
Or modify the
OPENAI_API_KEYvariable in the code. -
Configure Interactive Brokers:
- Install TWS or IB Gateway
- Enable API connections in settings
- Configure ports:
- Paper trading: 4002
- Live trading: 7496
-
WhatsApp Setup:
- Update
JIDandNINAvariables with target WhatsApp numbers - Configure TimelinesAI API credentials
- Update
- SPY (S&P 500 ETF) - 2 shares
- QQQ (NASDAQ ETF) - 2 shares
- GLD (Gold ETF) - 2 shares
- TLT (Treasury Bonds) - 1 share
- SPY - 3 shares
- QQQ - 2 shares
- GLD - 3 shares
- XOM (Exxon Mobil) - 5 shares
- CVX (Chevron) - 3 shares
- LMT (Lockheed Martin) - 1 share
- XLE (Energy ETF) - 10 shares
- XOP (Oil & Gas ETF) - 5 shares
- XOM - 10 shares
- CVX - 8 shares
- LMT - 3 shares
- GLD - 5 shares
python notam_trading_bot_complete.pypython notam_trading_bot_complete.py --portfolio Aggressivepython notam_trading_bot_complete.py --interval 15python notam_trading_bot_complete.py --live-trading --portfolio ModerateWarning: This uses real money! Requires explicit confirmation.
python notam_trading_bot_complete.py --paper-tradingpython notam_trading_bot_complete.py --simulate --portfolio Conservativepython notam_trading_bot_complete.py --test-chatgptpython notam_trading_bot_complete.py --test-ibpython notam_trading_bot_complete.py --show-portfoliospython notam_trading_bot_complete.py --create-samplepython notam_trading_bot_complete.py --remove-samplepython notam_trading_bot_complete.py --show-cachepython notam_trading_bot_complete.py --clear-cache| Parameter | Default | Description |
|---|---|---|
FIR |
"OIIX" | Flight Information Region (Iran) |
IB_HOST |
"127.0.0.1" | Interactive Brokers host |
IB_PORT |
4002 | IB port (4002=paper, 7496=live) |
CLIENT_ID |
1 | IB client identifier |
The system monitors for these critical keywords in NOTAMs:
- AIRSPACE CLOSED
- ALL FLIGHTS PROHIBITED
- NO FLIGHT PERMITTED
- AIRSPACE IS RESTRICTED
- MILITARY EXERCISE
- CONFLICT ZONE
- DANGER AREA
- RESTRICTED AREA
- NO OVERFLIGHT
- PROHIBITED AREA
A NOTAM triggers trading when:
- Contains trigger keywords (airspace closure indicators)
- Is recent (issued within last 5 minutes)
- Affects monitored FIR (OIIX - Iran region)
π¨ CRITICAL NOTAM ALERT - TRADING ACTIVATED π¨
π FIR: OIIX (Iran)
π ID: A1234/24
β° VALIDITY:
π
Start: 15 Jan 2025 - 14:30 UTC
π
End: 15 Jan 2025 - 18:30 UTC
β±οΈ Duration: 4h 0m
π ORIGINAL CONTENT:
AIRSPACE CLOSED DUE TO MILITARY EXERCISE...
π€ AUTOMATIC INTERPRETATION:
[ChatGPT explanation in clear language]
π€ AUTOMATIC ACTION:
β
Alert detected
π Starting automatic trading
π’ Portfolio: Conservative
π° Executing specialized orders
π AUTOMATIC TRADING SUMMARY π
π¨ Triggered by: CRITICAL NOTAM ALERT
π‘ MODERATE
β
SUCCESSFUL: 4
SPY, QQQ, GLD, XOM
β FAILED: 1
CVX
π° TOTAL INVESTED: $1,247.50
β‘ EXECUTION TIME: 3.45s
β° Completed: 14:32:15
π€ NOTAM-Trading Bot v5.0 COMPLETE
- Automatic interpretation of complex NOTAMs
- Plain language explanations for non-aviation experts
- Caching system to avoid duplicate API calls
- Structured analysis including severity assessment
- WHAT'S HAPPENING: Clear explanation
- WHERE: Specific location affected
- WHEN: Valid dates and times
- IMPACT: Effect on flights and operations
- SEVERITY: Risk level (Low/Medium/High/Critical)
- NOTAM Detection β Critical alert identified
- AI Interpretation β ChatGPT analyzes content
- WhatsApp Alert β Immediate notification sent
- Trading Delay β Strategic delay (5-10s based on portfolio)
- IB Connection β Connect to broker
- Order Execution β Buy orders for portfolio assets
- Monitoring β Track order status (30s timeout)
- Summary Report β Results sent via WhatsApp
- Paper trading default for safety
- Explicit confirmation required for live trading
- Position limits defined per portfolio
- Timeout protection on order execution
- Comprehensive logging of all activities
notam_trading_bot/
βββ notam_trading_bot_complete.py # Main bot script
βββ notam_trading_events.log # Trading events log
βββ notam_trading_bot.log # General application log
βββ sample_notam.txt # Optional test NOTAM file
βββ README.md # This documentation
Records all trading events:
[2025-01-15 14:30:25 UTC] NOTAM_CRITICAL | SUCCESS | Portfolio: Moderate | ID: A1234/24
[2025-01-15 14:30:45 UTC] TRADING_EXECUTED | SUCCESS | Portfolio: Moderate | Successful: 4, Failed: 1
Detailed application logs with timestamps and debug information.
Real-time status updates with emojis:
- βΉοΈ INFO: General information
- β OK: Successful operations
β οΈ WARNING: Important notices- β ERROR: Error conditions
- Store OpenAI API key in environment variables
- Never commit API keys to version control
- Use separate keys for development/production
- Always test with paper trading first
- Set appropriate position limits
- Monitor account balance and buying power
- Keep separate accounts for automated trading
- Use secure connections for all API calls
- Implement proper timeout handling
- Monitor for unusual activity patterns
- Ensure TWS or IB Gateway is running
- Check port configuration (4002/7496)
- Verify API settings are enabled
- Confirm client ID is unique
- Verify OpenAI API key is valid
- Check internet connection
- Monitor API usage limits
- Review error messages in logs
- Verify TimelinesAI credentials
- Check WhatsApp number format
- Test with simplified message
- Review API endpoint status
- Check internet connectivity
- Verify FAA website accessibility
- Review FIR configuration
- Test with sample NOTAM file
- NOTAM Detection: 1-3 seconds
- ChatGPT Interpretation: 2-5 seconds
- WhatsApp Notification: 1-2 seconds
- Trading Execution: 3-8 seconds
- Total Alert-to-Trade: 10-20 seconds
- Memory: ~50-100 MB
- CPU: Low (periodic checks)
- Network: Moderate (API calls)
- Storage: Minimal (logs only)
- Monitor log file sizes
- Clear interpretation cache periodically
- Update trigger keywords as needed
- Review and adjust portfolios
- Test API connections weekly
- Check for new NOTAM data sources
- Update trading strategies based on performance
- Enhance error handling based on logs
- Optimize ChatGPT prompts for better interpretations
- Financial Risk: Automated trading involves substantial risk of loss
- Testing Required: Always test thoroughly before live trading
- Market Volatility: Rapid market movements may affect execution
- API Limitations: External services may have rate limits or downtime
- Aviation Data: NOTAM interpretation may not be 100% accurate
For technical issues:
- Check logs for error details
- Test individual components (IB, ChatGPT, WhatsApp)
- Review configuration settings
- Use simulation mode for debugging
- Monitor system resources and connectivity
- Multiple FIR monitoring
- Advanced risk management rules
- Machine learning for NOTAM classification
- Real-time portfolio optimization
- Enhanced reporting and analytics
- Mobile app integration
Step 1: Prerequisites
- Python 3.8+ installed
- Interactive Brokers account (paper trading recommended)
- OpenAI API key for ChatGPT
- Basic understanding of trading risks
Step 2: Installation
pip install ib_insync requests beautifulsoup4 lxml
export OPENAI_API_KEY="your-key-here"Step 3: First Test
# Test everything works
python notam_trading_bot_complete.py --simulate --portfolio Conservative
# Test real monitoring (paper trading only)
python notam_trading_bot_complete.py --paper-trading --portfolio ConservativeStep 4: Understand the System
- Review the portfolios section
- Test with sample NOTAMs first
- Monitor logs carefully
- Never use live trading without extensive testing
To share this bot safely:
- Always emphasize the risks - this involves real money
- Recommend starting with simulation mode only
- Suggest paper trading for at least several weeks
- Provide this documentation in full
- Recommend independent testing and verification
- Stress the importance of understanding the code before use
For Questions:
- Review the documentation thoroughly
- Test each component individually
- Start with conservative settings
- Monitor all operations closely
- Never invest more than you can afford to lose
Generated: January 2025 - Version 5.0