NIJA includes a global emergency exit switch that immediately liquidates ALL positions across ALL accounts when activated. This is a safety mechanism for extreme market conditions or critical system issues.
Create a file named LIQUIDATE_ALL_NOW.conf in the repository root:
# From repository root
touch LIQUIDATE_ALL_NOW.conf
When the bot detects this file during its trading cycle:
run_cycle() (every 2.5 minutes)LIQUIDATE_ALL_NOW.conf after liquidationFile: bot/trading_strategy.py
Method: run_cycle()
Lines: ~2926-3008
# π¨ EMERGENCY: Check if LIQUIDATE_ALL mode is active
liquidate_all_file = os.path.join(os.path.dirname(__file__), '..', 'LIQUIDATE_ALL_NOW.conf')
if os.path.exists(liquidate_all_file):
logger.error("π¨ EMERGENCY LIQUIDATION MODE ACTIVE")
logger.error(" SELLING ALL POSITIONS IMMEDIATELY")
# ... liquidation logic ...
β ALL open positions on the active broker β Works for ANY broker (Kraken, Coinbase, etc.) β Works for ALL accounts (Platform + Users) β Positions opened by NIJA or manually β Positions adopted from exchange
β Positions on disconnected brokers β Positions on brokers not configured β Pending orders (not executed positions)
β Normal profit-taking: Use regular exit logic instead β Single position exit: Use manual sell via exchange UI β Strategy adjustment: Modify strategy parameters instead β Testing: Use dry-run mode or smaller position sizes
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TIME: 14:30:00 - Normal Trading Cycle
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Scanning markets for opportunities
β
Managing 5 open positions
β
Monitoring stop-losses and profit targets
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[USER CREATES EMERGENCY FILE]
$ touch LIQUIDATE_ALL_NOW.conf
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TIME: 14:32:30 - Next Trading Cycle (2.5 min later)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π¨ EMERGENCY LIQUIDATION MODE ACTIVE
SELLING ALL POSITIONS IMMEDIATELY
Found 5 positions to liquidate
[1/5] FORCE SELLING 0.02 BTC...
β
SOLD BTC
[2/5] FORCE SELLING 0.5 ETH...
β
SOLD ETH
[3/5] FORCE SELLING 10 SOL...
β
SOLD SOL
[4/5] FORCE SELLING 100 ADA...
β
SOLD ADA
[5/5] FORCE SELLING 5000 XLM...
β
SOLD XLM
Liquidation round complete: 5/5 sold
β
Emergency liquidation cycle complete - removed LIQUIDATE_ALL_NOW.conf
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TIME: 14:35:00 - Normal Trading Resumes
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Emergency file removed
β
Trading operations restored
β
No open positions (all liquidated)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Each accountβs trading thread independently checks for the emergency file:
β
Guaranteed removal: File is deleted even if liquidation fails
β
Try-finally block: Cleanup happens in finally block
β
No infinite loops: File wonβt cause repeated liquidations
β
Individual position errors: One failure doesnβt stop others
β
Logging: Each sell attempt logged with success/failure
β
Graceful degradation: Partial liquidation still useful
β
1-second delay: Between each sell to avoid API rate limits
β
Sequential processing: One position at a time
β
Timeout protection: Uses call_with_timeout() for API calls
Create STOP_ALL_ENTRIES.conf to:
Use when: You want to exit positions naturally but avoid new trades
Via exchange UI:
Use when: Exiting specific positions, not urgent
Use built-in safety modes:
Use when: Testing or learning
def run_cycle(self, broker=None, user_mode=False):
"""Execute trading cycle with emergency exit check"""
# 1. FIRST check emergency file (before any other logic)
liquidate_all_file = os.path.join(
os.path.dirname(__file__),
'..',
'LIQUIDATE_ALL_NOW.conf'
)
if os.path.exists(liquidate_all_file):
# 2. Enter emergency mode
logger.error("π¨ EMERGENCY LIQUIDATION MODE ACTIVE")
try:
# 3. Get all positions
positions = broker.get_positions()
# 4. Sell each position
for pos in positions:
broker.place_market_order(
symbol=pos['symbol'],
side='sell',
quantity=pos['quantity']
)
time.sleep(1) # Rate limit protection
finally:
# 5. ALWAYS remove file (guaranteed cleanup)
if os.path.exists(liquidate_all_file):
os.remove(liquidate_all_file)
return # Exit cycle, skip normal trading
# 6. Normal trading continues if no emergency file
# ... rest of trading logic ...
/home/runner/work/Nija/Nija/LIQUIDATE_ALL_NOW.conf
Must be in the repository root (parent directory of bot/).
DO NOT test in production with real money. Use:
DRY_RUN_MODE=truesimulate_restart_adoption_sell.py# 1. Enable dry-run mode
export DRY_RUN_MODE=true
# 2. Start bot with test positions
python3 start.sh
# 3. Create emergency file
touch LIQUIDATE_ALL_NOW.conf
# 4. Watch logs for next cycle (within 2.5 min)
tail -f logs/nija.log
# 5. Verify:
# - Emergency mode detected
# - Positions listed for liquidation
# - Mock sells executed
# - File automatically removed
Emergency activated:
π¨ EMERGENCY LIQUIDATION MODE ACTIVE
SELLING ALL POSITIONS IMMEDIATELY
Liquidation progress:
[1/5] FORCE SELLING 0.02 BTC...
β
SOLD BTC
Completion:
β
Emergency liquidation cycle complete - removed LIQUIDATE_ALL_NOW.conf
β
Automatic: Trading resumes next cycle after file removal
β
No restart needed: Bot continues running
β
Clean slate: No positions means fresh start
Create STOP_ALL_ENTRIES.conf after emergency:
The emergency exit system has built-in safety:
π Idempotent: Can be triggered multiple times safely
π Self-cleaning: Always removes trigger file
π Logged: Full audit trail of every action
π Isolated: One accountβs emergency doesnβt affect others
π Throttled: Rate-limited to avoid API bans
The global emergency exit switch is a last resort safety mechanism that:
Remember: This is for emergencies only. Use regular exit logic for normal profit-taking and risk management.