This guide explains how to safely restore trading operations after an emergency stop or system restart without risking capital.
Use this guide if:
EMERGENCY_STOPThe recovery process ensures:
safe_restore_trading.py# 1. Check current status (always run this first)
python safe_restore_trading.py status
# 2. Restore to safe DRY_RUN mode (recommended)
python safe_restore_trading.py restore
# 3. Reset to OFF state only (if needed)
python safe_restore_trading.py reset
status)Purpose: Diagnose current trading state and detect any inconsistencies.
python safe_restore_trading.py status
What it shows:
Example Output:
π CURRENT STATUS
--------------------------------------------------------------------------------
Trading State Machine: EMERGENCY_STOP
Kill Switch Active: β
NO
Kill File Exists: False
Can Trade: β NO
--------------------------------------------------------------------------------
β οΈ STATE INCONSISTENCY DETECTED:
β’ State machine is in EMERGENCY_STOP
β’ But kill switch is DEACTIVATED
β’ Trading is blocked unnecessarily
π‘ Solution: Run 'python safe_restore_trading.py restore'
restore)Purpose: Safely restore trading to simulation mode (no capital risk).
python safe_restore_trading.py restore
What it does:
EMERGENCY_STOP β OFF β DRY_RUNSafety Features:
After Restoration:
reset)Purpose: Disable all trading operations completely.
python safe_restore_trading.py reset
What it does:
When to use:
Problem: Kill switch was activated, then deactivated, but trading wonβt resume.
Symptoms:
EMERGENCY_STOPSolution:
# 1. Check status
python safe_restore_trading.py status
# 2. Restore to safe mode
python safe_restore_trading.py restore
# 3. Verify restoration
python safe_restore_trading.py status
Result: Bot is now in DRY_RUN mode, ready for safe testing.
Problem: Bot was restarted and trading needs to be safely enabled.
Symptoms:
OFF or EMERGENCY_STOPSolution:
# 1. Always check status first
python safe_restore_trading.py status
# 2. If state is inconsistent or you want safe mode
python safe_restore_trading.py restore
# 3. Test in DRY_RUN mode
# Monitor logs, verify strategies, check positions
# 4. When ready for live (via UI/API, not this tool)
# Manually transition to LIVE mode with proper risk acknowledgment
Important: This tool never enables LIVE trading automatically.
Problem: Kill switch is active and needs to be deactivated first.
Symptoms:
safe_restore_trading.py status shows kill switch activeSolution:
# 1. Investigate WHY kill switch was activated
# Review logs and .nija_kill_switch_state.json
# 2. Resolve the underlying issue
# Fix the problem that triggered the kill switch
# 3. Deactivate kill switch
python emergency_kill_switch.py deactivate "Issue resolved: [describe fix]"
# 4. Restore trading safely
python safe_restore_trading.py restore
Problem: Need to ensure everything is working before risking capital.
Symptoms:
Solution:
# 1. Check current state
python safe_restore_trading.py status
# 2. Restore to DRY_RUN if not already
python safe_restore_trading.py restore
# 3. Run bot in DRY_RUN mode for testing period
# Recommended: At least 1 hour of monitoring
# 4. Verify:
# - Strategies execute correctly
# - No errors in logs
# - Risk management working
# - Position management correct
# - API connections stable
# 5. Only then manually enable LIVE trading
# Via UI/API with proper risk acknowledgment
The safe recovery process follows these state transitions:
EMERGENCY_STOP β OFF β DRY_RUN β [Manual] β LIVE_PENDING_CONFIRMATION β [Confirm] β LIVE_ACTIVE
β β
| |
+---- This tool ----+ +---- Manual only ----+
Key Points:
EMERGENCY_STOP β OFF β DRY_RUN.nija_trading_state.json.nija_trading_state.jsonContains trading state machine status:
{
"current_state": "DRY_RUN",
"history": [
{
"from": "OFF",
"to": "DRY_RUN",
"reason": "Safe recovery: Enabling simulation mode",
"timestamp": "2026-02-17T22:01:15.133111"
}
],
"last_updated": "2026-02-17T22:01:15.133120"
}
.nija_kill_switch_state.jsonContains kill switch activation history:
{
"is_active": false,
"history": [
{
"reason": "Manual deactivation",
"timestamp": "2026-02-17T21:00:00.000000"
}
],
"last_updated": "2026-02-17T21:00:00.000000"
}
Cause: Kill switch must be deactivated before restoration.
Solution:
# Check why kill switch was activated
cat .nija_kill_switch_state.json
# Deactivate after resolving issue
python emergency_kill_switch.py deactivate "Reason for resume"
# Then restore
python safe_restore_trading.py restore
Cause: Invalid state transition or file permissions.
Solution:
# Check file permissions
ls -la .nija_trading_state.json
# Verify file is writable
chmod 644 .nija_trading_state.json
# Try again
python safe_restore_trading.py restore
Cause: Kill switch and state machine are out of sync (typically after kill switch deactivation).
Solution: This is the exact problem this tool solves!
python safe_restore_trading.py restore
emergency_kill_switch.py - Activate/deactivate kill switchnija_control_center.py - Monitor trading operationsbot/trading_state_machine.pybot/kill_switch.pystatus before any recovery actionSafe Recovery Workflow:
# 1. Diagnose
python safe_restore_trading.py status
# 2. Recover (safe mode)
python safe_restore_trading.py restore
# 3. Test & Verify
# Monitor DRY_RUN mode operation
# 4. Enable LIVE (manual only)
# Via UI/API with risk acknowledgment
Remember: This tool ensures you can NEVER accidentally risk capital during recovery!