trading-operations
Trading Operations
Daily Startup Checklist
1. Start OpenAlgo Server
KiteConnect Instance (Port 5001 - NSE/MCX):
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
./QUICK_START.sh
Or manually:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
source /Users/mac/dyad-apps/openalgo/venv/bin/activate
bash start.sh
Dhan Instance (Port 5002 - Options):
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
bash scripts/start_dhan_port5002_final.sh
2. Verify Server Status
Quick Status Check:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
./CHECK_STATUS.sh
Detailed Health Check:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
source /Users/mac/dyad-apps/openalgo/venv/bin/activate
python3 scripts/authentication_health_check.py
3. Check Broker Authentication
KiteConnect (Port 5001):
- Open: http://127.0.0.1:5001/auth/broker
- If token expired, reconnect Zerodha
Dhan (Port 5002):
- Open: http://127.0.0.1:5002/auth/broker
- Verify login status
4. Verify Strategies
Strategy Dashboard:
- Open: http://127.0.0.1:5001/python (KiteConnect strategies)
- Open: http://127.0.0.1:5002/python (Dhan strategies)
- Verify all strategies are enabled
- Check schedules: 09:30-15:15 IST
5. Monitor Dashboard
Main Dashboard:
- Open: http://127.0.0.1:5001/dashboard
- Check positions, orders, PnL
Monitoring
Real-Time Monitoring
Check Strategy Logs:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
tail -f logs/strategy_*.log | grep -E "\[ENTRY\]|\[EXIT\]|\[REJECTED\]|\[ERROR\]"
Monitor All Strategy Logs:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
bash scripts/check_all_strategy_logs.sh
Check Positions:
curl http://127.0.0.1:5001/positions | jq
Check Orders:
curl http://127.0.0.1:5001/orderbook | jq
Key Endpoints
| Endpoint | Purpose | Port |
|---|---|---|
/dashboard |
Main dashboard | 5001/5002 |
/python |
Strategy management | 5001/5002 |
/positions |
Current positions | 5001/5002 |
/orderbook |
Order status | 5001/5002 |
/auth/broker |
Broker authentication | 5001/5002 |
/health |
System health | 5001/5002 |
Troubleshooting
Strategies Not Running
Check:
- Server is running:
lsof -i :5001orlsof -i :5002 - Strategies are enabled in
/pythondashboard - Market hours: 09:15-15:30 IST (weekdays only)
- API key is configured: Check
OPENALGO_APIKEYenv var
Fix:
# Restart specific strategy
curl -X POST http://127.0.0.1:5001/api/v1/strategy/restart \
-H "Content-Type: application/json" \
-d '{"strategy": "strategy_name"}'
No Orders Being Placed
Common Causes:
- Entry conditions too strict (check logs for
[REJECTED]) - Risk limits blocking entries (portfolio heat limit)
- API connectivity issues
- Market closed or outside trading hours
Diagnosis:
# Check strategy logs for rejection reasons
grep "\[REJECTED\]" logs/strategy_*.log
# Check risk limits
curl http://127.0.0.1:5001/risk | jq
403 Errors
Fix 403 errors:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
python3 scripts/fix_403_strategies.py
Restart affected strategies:
bash scripts/restart_403_strategies.sh
Authentication Issues
KiteConnect Token Expired:
- Go to http://127.0.0.1:5001/auth/broker
- Click "Reconnect Zerodha"
- Complete OAuth flow
Dhan Login Issues:
- Check:
openalgo/DHAN_LOGIN_TROUBLESHOOTING.md - Verify credentials in
.envfile - Check port 5002 is not blocked
Deployment
Deploy Ranked Strategies
After backtesting and ranking:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo/strategies
bash scripts/deploy_ranked_strategies.sh
This script:
- Reads backtest ranking results
- Enables top-ranked strategies
- Configures parameters from optimization
- Sets up monitoring
Manual Strategy Deployment
Enable Strategy:
curl -X POST http://127.0.0.1:5001/api/v1/strategy/enable \
-H "Content-Type: application/json" \
-d '{
"strategy": "strategy_name",
"symbol": "NIFTY",
"params": {
"risk_per_trade": 0.02,
"stop_loss_pct": 1.5
}
}'
Configure Schedule:
- Set trading hours: 09:30-15:15 IST
- Set check interval: 60 seconds (or as needed)
- Configure market hours filter
Emergency Procedures
Emergency Stop
Immediate Actions:
- Go to http://127.0.0.1:5001/python → Toggle OFF all strategies
- Go to http://127.0.0.1:5001/positions → Close all positions
- Stop server:
lsof -i :5001thenkill <PID>
Kill Switch API:
curl -X POST http://127.0.0.1:5001/api/v1/flatten
Position Flattening
Close All Positions:
curl -X POST http://127.0.0.1:5001/api/v1/positions/flatten \
-H "Content-Type: application/json" \
-d '{"exchange": "NSE"}'
Close Specific Symbol:
curl -X POST http://127.0.0.1:5001/api/v1/positions/close \
-H "Content-Type: application/json" \
-d '{"symbol": "NIFTY", "exchange": "NSE"}'
Daily Shutdown
Backup Settings
Save Settings:
cd /Users/mac/dyad-apps/probable-fiesta/openalgo
./QUICK_BACKUP.sh
Or manually:
python3 scripts/backup_settings.py
List Backups:
python3 scripts/list_backups.py
Restore Settings:
python3 scripts/restore_settings.py
End of Day Checklist
- ✅ All positions closed (or verified as intended)
- ✅ Settings backed up
- ✅ Logs reviewed for errors
- ✅ Strategy performance noted
- ✅ Server stopped (optional, can run 24/7)
Market Hours
NSE/MCX Trading Hours:
- Market Open: 09:15 IST
- Trading Window: 09:30-15:15 IST (strategies active)
- Market Close: 15:30 IST
- Token Expiry: 03:00 IST (daily)
MCX Trading Hours:
- Extended hours: 09:00-23:30 IST
- Check specific commodity trading hours
Port Configuration
Dual OpenAlgo Setup:
| Port | Broker | Purpose | Strategies |
|---|---|---|---|
| 5001 | KiteConnect | NSE/MCX | Equity, MCX strategies |
| 5002 | Dhan | Options | Options strategies, rankers |
Strategy Routing:
- NSE/MCX strategies →
http://127.0.0.1:5001 - Options strategies →
http://127.0.0.1:5002
Log Analysis
Key Log Patterns
Entry Signals:
grep "\[ENTRY\]" logs/strategy_*.log
Exit Signals:
grep "\[EXIT\]" logs/strategy_*.log
Rejections:
grep "\[REJECTED\]" logs/strategy_*.log
Errors:
grep -E "ERROR|Exception|Traceback" logs/strategy_*.log
Log Locations
- Strategy logs:
openalgo/logs/strategy_*.log - Server logs:
openalgo/logs/server.log - Error logs:
openalgo/logs/error.log
Additional Resources
- Quick start:
START_HERE.md - Setup guide:
OPENALGO_LIVE_TRADING_SETUP.md - Paper trading:
PAPER_TRADING_GUIDE.md - Troubleshooting:
openalgo/DHAN_LOGIN_TROUBLESHOOTING.md - Status scripts:
openalgo/scripts/check_all_strategy_logs.sh
More from sayujks0071/antidhan
trading-strategy-development
Create and modify trading strategies for OpenAlgo with proper structure, risk management, entry/exit logic, and position management. Use when developing new strategies, modifying existing ones, debugging strategy logic, or implementing trading signals.
12risk-management
Implement and review risk controls, position sizing, portfolio heat limits, stop losses, and risk monitoring. Use when implementing risk management, reviewing risk controls, calculating position sizes, or analyzing portfolio risk exposure.
7pr-49-review
Reviews pull request #49 for OpenAlgo observability changes, focusing on risks, security, and test coverage. Use when analyzing PR #49 or when the user asks about the local observability stack changes.
6log-monitoring
Monitor current logs in real-time, track log file sizes, watch for new entries, and check log health across system and strategy logs. Use when monitoring live logs, checking log status, watching for errors, or tracking log file growth.
6plan-based-skill-builder
Builds Cursor skills from plan documents by analyzing workflows, extracting key instructions, and creating structured skill files. Use when creating skills from restart plans, deployment plans, prioritization plans, retest plans, or any structured plan documents.
6backtesting-analysis
Run backtests, analyze strategy performance, compare strategies, and generate ranking reports. Use when backtesting strategies, analyzing performance metrics, comparing strategy variants, or generating backtest reports.
6