feat: Add container restart functionality from web UI

- Added restart button to settings page
- Created /api/restart endpoint (file-flag based)
- Implemented watch-restart.sh daemon
- Added systemd service for restart watcher
- Updated README with restart setup instructions
- Container automatically restarts when settings changed

Settings flow:
1. User edits settings in web UI
2. Click 'Save Settings' to persist to .env
3. Click 'Restart Bot' to apply changes
4. Watcher detects flag and restarts container
5. New settings loaded automatically
This commit is contained in:
mindesbunister
2025-10-24 15:06:26 +02:00
parent 9e0d9b88f9
commit 26864c10f2
7 changed files with 174 additions and 10 deletions

View File

@@ -178,6 +178,24 @@ POST /api/trading/check-risk
# Get current settings
GET /api/settings
# Update settings
POST /api/settings
{
"MAX_POSITION_SIZE_USD": 100,
"LEVERAGE": 10,
"STOP_LOSS_PERCENT": -1.5,
...
}
# Restart bot container (apply settings)
POST /api/restart
```
**Notes:**
- Settings changes require container restart to take effect
- Use the web UI's "Restart Bot" button or call `/api/restart`
- Restart watcher must be running (see setup below)
# Update settings
POST /api/settings
{
@@ -223,6 +241,26 @@ docker compose restart trading-bot
docker compose down
```
### Restart Watcher (Required for Web UI Restart Button)
The restart watcher monitors for restart requests from the web UI:
```bash
# Start watcher manually
cd /home/icke/traderv4
nohup ./watch-restart.sh > logs/restart-watcher.log 2>&1 &
# OR install as systemd service (recommended)
sudo cp trading-bot-restart-watcher.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable trading-bot-restart-watcher
sudo systemctl start trading-bot-restart-watcher
# Check watcher status
sudo systemctl status trading-bot-restart-watcher
```
The watcher enables the "Restart Bot" button in the web UI to automatically restart the container when settings are changed.
### Environment Variables
All settings are configured via `.env` file:
- Drift wallet credentials