Persistenza dati e logging avanzato con UI e Unraid

- Aggiunto TradeHistoryService per persistenza trade/posizioni attive su disco (JSON, auto-save/restore)
- Logging centralizzato (LoggingService) con livelli, categorie, simbolo e buffer circolare (500 log)
- Nuova pagina Logs: monitoraggio real-time, filtri avanzati, cancellazione log, colorazione livelli
- Sezione "Dati Persistenti" in Settings: conteggio trade, dimensione dati, reset con conferma modale
- Background service per salvataggio sicuro su shutdown/stop container
- Aggiornata sidebar, stili modali/bottoni danger, .gitignore e documentazione (README, CHANGELOG, UNRAID_INSTALL, checklist)
- Versione 1.3.0
This commit is contained in:
2025-12-22 11:24:17 +01:00
parent d7ae3e5d44
commit 92c8e57a8c
15 changed files with 1697 additions and 36 deletions

View File

@@ -0,0 +1,288 @@
# ?? TradingBot - Deployment Checklist
Checklist completa per deployment sicuro e corretto su Unraid.
---
## ? Pre-Deployment
### Environment
- [ ] Unraid 6.10+ installato e aggiornato
- [ ] Docker service attivo e funzionante
- [ ] Internet connesso e stabile
- [ ] SSH access configurato
- [ ] Backup Unraid recente disponibile
### Network
- [ ] Porta 8888 disponibile (o alternativa scelta)
- [ ] Test porta: `netstat -tulpn | grep :8888`
- [ ] Firewall configurato correttamente
- [ ] IP Unraid noto: `192.168.30.23`
### Gitea Registry
- [ ] Account Gitea attivo
- [ ] Personal Access Token generato
- [ ] Login test: `docker login gitea.encke-hake.ts.net`
- [ ] Immagine disponibile in Packages
---
## ?? Installation
### Template Setup
- [ ] Template XML scaricato
```bash
wget -O /boot/config/plugins/dockerMan/templates-user/TradingBot.xml \
https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/deployment/unraid-template.xml
```
- [ ] Template visibile in Unraid UI
- [ ] Dropdown "TradingBot" disponibile
### Container Configuration
- [ ] **Name**: `TradingBot`
- [ ] **Repository**: `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest`
- [ ] **Network**: Bridge
- [ ] **Port Mapping**: `8888:8080` (o custom)
- Host Port: `8888` (modificabile)
- Container Port: `8080` (FIXED)
- [ ] **Volume**: `/mnt/user/appdata/tradingbot:/app/data`
- Access: Read/Write
- [ ] **Environment Variables**:
- `ASPNETCORE_ENVIRONMENT=Production`
- `ASPNETCORE_URLS=http://+:8080`
- `TZ=Europe/Rome`
### First Start
- [ ] Click **Apply**
- [ ] Container pulls image successfully
- [ ] Container status: **running**
- [ ] No errors in logs: `docker logs TradingBot`
---
## ? Post-Installation Verification
### Container Health
- [ ] Container running: `docker ps | grep TradingBot`
- [ ] Port mapping correct: `docker port TradingBot`
- Expected: `8080/tcp -> 0.0.0.0:8888`
- [ ] Logs healthy: `docker logs TradingBot --tail 50`
- No errors or exceptions
- "Now listening on: http://[::]:8080"
### WebUI Access
- [ ] WebUI icon visible in Unraid Docker tab
- [ ] Click WebUI icon opens browser
- [ ] Manual access works: `http://192.168.30.23:8888`
- [ ] Dashboard loads completely
- [ ] No JavaScript errors in browser console
### Functionality Test
- [ ] Bot can be started from UI
- [ ] Market data updates (check Dashboard)
- [ ] Settings can be modified and saved
- [ ] Assets can be enabled/disabled
- [ ] Trade history visible (if any previous data)
---
## ?? Persistence Verification
### Data Directory
- [ ] Volume created: `ls -la /mnt/user/appdata/tradingbot/`
- [ ] Directory writable: `touch /mnt/user/appdata/tradingbot/test && rm /mnt/user/appdata/tradingbot/test`
### Persistence Test
1. [ ] Start bot and execute some trades
2. [ ] Stop bot
3. [ ] Verify files exist:
```bash
ls -lh /mnt/user/appdata/tradingbot/
# Should show:
# - trade-history.json
# - active-positions.json
# - settings.json
```
4. [ ] Stop container: `docker stop TradingBot`
5. [ ] Start container: `docker start TradingBot`
6. [ ] Verify data restored:
- Trade count same in History page
- Settings preserved
- Active positions restored
### Backup Test
- [ ] Create backup:
```bash
tar -czf tradingbot-backup-$(date +%Y%m%d).tar.gz \
/mnt/user/appdata/tradingbot/
```
- [ ] Backup file created successfully
- [ ] Test restore (optional):
```bash
tar -xzf tradingbot-backup-YYYYMMDD.tar.gz -C /tmp/
# Verify files intact
```
---
## ?? Update Test
### Update Procedure
- [ ] Stop container
- [ ] Force Update in Unraid UI
- [ ] Wait for pull completion
- [ ] Start container
- [ ] Verify data persisted:
- [ ] Trade history intact
- [ ] Settings intact
- [ ] Active positions intact
### Rollback Test (Optional)
- [ ] Tag current image before update
- [ ] Test update to new version
- [ ] If issues, rollback to previous tag
- [ ] Verify data still intact
---
## ?? Security Check
### Access Control
- [ ] Port 8888 not exposed to internet
- [ ] Only LAN/VPN access configured
- [ ] No default passwords used
### Data Protection
- [ ] AppData directory permissions correct
```bash
ls -la /mnt/user/appdata/ | grep tradingbot
# Should be owned by appropriate user
```
- [ ] Backup schedule configured (CA Backup plugin)
- [ ] Backup retention policy set
### Registry Security
- [ ] Gitea login required for pulls
- [ ] Personal Access Token secure
- [ ] No credentials in logs
---
## ?? Monitoring Setup
### Unraid Dashboard
- [ ] Container appears in Docker tab
- [ ] Auto-start enabled (optional)
- [ ] Resource limits configured (optional):
```
--cpus="2.0" --memory="1g"
```
### Logs
- [ ] Know how to access logs:
- Unraid UI: Docker tab ? TradingBot ? Logs icon
- CLI: `docker logs TradingBot -f`
- [ ] No error messages in logs
### Notifications
- [ ] Unraid notifications enabled
- [ ] Email/Telegram configured (optional)
---
## ?? Troubleshooting Checklist
### If WebUI Not Accessible
- [ ] Check container running: `docker ps | grep TradingBot`
- [ ] Check port mapping: `docker port TradingBot`
- [ ] Test localhost: `curl http://localhost:8888/`
- [ ] Check firewall: `iptables -L | grep 8888`
- [ ] Check logs for errors: `docker logs TradingBot`
- [ ] Try different port if 8888 occupied
### If Data Not Persisting
- [ ] Volume mapping correct: `docker inspect TradingBot | grep -A5 Mounts`
- [ ] Directory exists: `ls -la /mnt/user/appdata/tradingbot/`
- [ ] Files being created: Monitor during bot run
- [ ] Permissions correct: `ls -la /mnt/user/appdata/tradingbot/`
### If Container Won't Start
- [ ] Check image pulled: `docker images | grep tradingbot`
- [ ] Check port not in use: `netstat -tulpn | grep :8888`
- [ ] Check disk space: `df -h`
- [ ] Review logs: `docker logs TradingBot`
- [ ] Try manual start: `docker start TradingBot`
---
## ?? Post-Deployment Tasks
### Documentation
- [ ] Note custom port if not 8888
- [ ] Document backup location
- [ ] Save deployment date
- [ ] Note Gitea image tag deployed
### Monitoring
- [ ] Add to monitoring dashboard (if any)
- [ ] Set up health check alerts (optional)
- [ ] Configure update notifications
### User Training
- [ ] Show how to access WebUI
- [ ] Explain Settings page
- [ ] Demonstrate how to view trades
- [ ] Explain data management (clear data)
---
## ?? Success Criteria
All of the following must be true:
? Container running and healthy
? WebUI accessible and functional
? Bot can start/stop from UI
? Market data updates in real-time
? Trades can be executed
? Data persists across restarts
? Backup can be created
? No errors in logs
? Resource usage acceptable
? Update procedure tested
---
## ?? Support
If issues persist after completing this checklist:
1. **Check Documentation**:
- [UNRAID_INSTALL.md](UNRAID_INSTALL.md)
- [CHANGELOG.md](../CHANGELOG.md)
2. **Collect Diagnostic Info**:
```bash
# Container info
docker ps -a | grep TradingBot
docker logs TradingBot --tail 100 > /tmp/tradingbot-logs.txt
docker inspect TradingBot > /tmp/tradingbot-inspect.json
# System info
df -h
free -h
netstat -tulpn | grep 8888
```
3. **Open Issue**:
- Repository: https://gitea.encke-hake.ts.net/Alby96/Encelado/issues
- Include: Docker version, Unraid version, logs
---
**Last Updated**: 2024-12-21
**Version**: 1.2.0
**Status**: ? Production Ready

View File

@@ -59,9 +59,13 @@ wget -O /boot/config/plugins/dockerMan/templates-user/TradingBot.xml \
- La porta CONTAINER rimane sempre 8080 (non modificare)
- Alternative comuni se 8888 occupata: `8881`, `9999`, `7777`
**Volume Dati**:
**Volume Dati** (?? IMPORTANTE per persistenza!):
- **AppData**: `/mnt/user/appdata/tradingbot` (già impostato)
- Puoi cambiare se preferisci altra directory
- Questo volume salva:
- Trade history (`trade-history.json`)
- Posizioni attive (`active-positions.json`)
- Settings applicazione (`settings.json`)
- ? I dati sopravvivono a restart/update del container
**Variabili Ambiente** (Avanzate - espandi se necessario):
- **ASPNETCORE_ENVIRONMENT**: `Production` (non modificare)
@@ -74,7 +78,7 @@ Unraid far
- ? Pull immagine da Gitea Registry
- ? Crea container con nome "TradingBot"
- ? Configura porta WebUI (default 8888 ? host, 8080 ? container)
- ? Crea volume per persistenza dati
- ? **Crea volume persistente per dati**
- ? Start automatico
### Step 3: Accedi WebUI
@@ -99,6 +103,57 @@ Dovresti vedere la **Dashboard TradingBot**! ??
---
## ?? PERSISTENZA DATI
### Come Funziona
TradingBot salva automaticamente tutti i dati in `/app/data` dentro il container, che viene mappato sul volume host `/mnt/user/appdata/tradingbot`.
**File salvati automaticamente**:
```
/mnt/user/appdata/tradingbot/
??? trade-history.json # Storia completa trade
??? active-positions.json # Posizioni attualmente aperte
??? settings.json # Impostazioni applicazione
```
**Salvataggio automatico**:
- ? Ogni 30 secondi (mentre bot running)
- ?? Immediato dopo ogni trade eseguito
- ?? On-stop quando fermi il bot
- ?? Graceful shutdown su Docker stop/restart
### Benefici
? **Zero perdita dati** - Anche in caso di crash
? **Restore automatico** - Stato ripristinato al riavvio
? **Update sicuri** - Dati preservati durante aggiornamenti
? **Backup facile** - Basta copiare la cartella appdata
### Backup Dati
```bash
# Backup manuale
tar -czf tradingbot-backup-$(date +%Y%m%d).tar.gz \
/mnt/user/appdata/tradingbot
# Restore
tar -xzf tradingbot-backup-20241221.tar.gz \
-C /mnt/user/appdata/
```
### Gestione Dati (via WebUI)
Vai su **Settings** ? **Dati Persistenti**:
- Visualizza numero trade salvati
- Visualizza dimensione dati
- Visualizza posizioni attive
- **Cancella tutti i dati** (con conferma)
?? **Nota**: Puoi cancellare i dati solo se il bot è fermo.
---
## ?? METODO 2: Installazione Manuale
Se preferisci non usare template:
@@ -119,19 +174,21 @@ gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
**Console shell command**: `Shell`
### Step 3: Port Mapping
### Step 3: Port Mapping (?? CRITICO!)
Click **Add another Path, Port, Variable, Label or Device**
**Config Type**: `Port`
- **Name**: `WebUI`
- **Container Port**: `8080`
- **Host Port**: `8080` ? **Cambia questa se occupata!**
- **Host Port**: `8888` ? **Cambia questa se occupata!**
- **Connection Type**: `TCP`
### Step 4: Volume Mapping
?? **Se questo mapping non viene configurato, la WebUI non sarà accessibile!**
Click **Add another Path, Port, Variable, Label or Device**
### Step 4: Volume Mapping (?? IMPORTANTE per persistenza!)
Click **Add another Path, Port, Variable, Label o Device**
**Config Type**: `Path`
- **Name**: `AppData`
@@ -153,14 +210,7 @@ Click **Add another Path, Port, Variable, Label or Device**
- **Name**: `TZ`
- **Value**: `Europe/Rome` (o tuo timezone)
### Step 6: Health Check (Opzionale ma Consigliato)
**Extra Parameters**:
```
--health-cmd="wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1" --health-interval=30s --health-timeout=3s --health-retries=3 --health-start-period=40s
```
### Step 7: Apply
### Step 6: Apply
Click **Apply** in fondo alla pagina.
@@ -179,9 +229,11 @@ Click **Apply** in fondo alla pagina.
Unraid farà:
- ? Pull ultima immagine da Gitea
- ? Ricrea container con nuova immagine
- ? Mantiene dati persistenti (volume non viene toccato)
- ? **Mantiene dati persistenti** (volume non viene toccato)
- ? Mantiene configurazione (porta, variabili, etc.)
?? **I tuoi trade e impostazioni sono al sicuro durante gli update!**
### Automatico con User Scripts Plugin
Installa **User Scripts** plugin:
@@ -391,3 +443,124 @@ https://tradingbot.tuo-dominio.com
```
?? **Nota**: Il reverse proxy si connette alla porta HOST (8888), non container (8080)
---
## ?? SICUREZZA
### Best Practices
? **Porta non esposta pubblicamente** (solo LAN o VPN)
? **Volume dati protetto** (`/mnt/user/appdata/tradingbot/`)
? **Registry privato** (Gitea richiede login)
? **Certificati validi** (Tailscale)
? **User non-root** (già configurato nel Dockerfile)
? **Dati persistenti** backup-ready
---
## ?? CHECKLIST INSTALLAZIONE
### Pre-Install
- [ ] Unraid 6.10+ installato
- [ ] Docker service attivo
- [ ] Porta 8888 (o alternativa) disponibile
- [ ] `docker login gitea.encke-hake.ts.net` successful
- [ ] Internet attivo per pull immagine
### Install
- [ ] Template XML scaricato su Unraid
- [ ] Container creato da template
- [ ] Porta WebUI configurata (8888 host ? 8080 container)
- [ ] Volume AppData creato (`/mnt/user/appdata/tradingbot`)
- [ ] Container status: **running**
### Post-Install
- [ ] WebUI accessibile (http://IP:8888)
- [ ] Dashboard carica correttamente
- [ ] Settings modificabili e salvabili
- [ ] Bot avviabile dalla UI
- [ ] Trade vengono salvati automaticamente
- [ ] Dati persistono dopo restart
---
## ?? VANTAGGI UNRAID NATIVO
? **Zero dipendenze** (no Portainer, no docker-compose)
? **WebUI Unraid integrata** (gestione familiare)
? **Auto-start** (container parte con Unraid)
? **Backup integrato** (con plugin CA)
? **Update semplice** (2 click: Stop ? Update ? Start)
? **Template riutilizzabile** (reinstall in 1 minuto)
? **Dati persistenti** (trade e settings sopravvivono)
? **Logs accessibili** dalla UI
---
## ?? WORKFLOW COMPLETO
### Sviluppo (PC)
```
1. ?? Visual Studio ? Codice
2. ?? Build ? Publish (Docker profile)
3. ? Automatico: Push Gitea Registry
?? Tags: latest, 1.2.0, 1.2.0-YYYYMMDD
4. ?? git push origin main --tags
```
### Deploy (Unraid)
```
1. ?? Docker tab ? TradingBot
2. ?? Stop
3. ?? Force Update (pull latest)
4. ?? Start
5. ? Done! (~ 1 minuto)
?? Dati automaticamente ripristinati
```
**Tempo totale**: ~2 minuti dal commit al running!
---
## ?? RISORSE
### Links Utili
| Risorsa | URL |
|---------|-----|
| **Template XML** | `https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/deployment/unraid-template.xml` |
| **Repository Git** | `https://gitea.encke-hake.ts.net/Alby96/Encelado` |
| **Docker Image** | `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest` |
| **Packages** | `https://gitea.encke-hake.ts.net/Alby96/Encelado/-/packages` |
| **Support/Issues** | `https://gitea.encke-hake.ts.net/Alby96/Encelado/issues` |
### Comandi Utili
```bash
# Status container
docker ps -a | grep TradingBot
# Logs real-time
docker logs -f TradingBot
# Statistics
docker stats TradingBot --no-stream
# Restart
docker restart TradingBot
# Update
docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
# Remove (mantiene dati in /mnt/user/appdata/tradingbot)
docker rm -f TradingBot
# Inspect persistent data
ls -lh /mnt/user/appdata/tradingbot/
cat /mnt/user/appdata/tradingbot/trade-history.json | jq
```
---
**?? TradingBot v1.2.0 con persistenza completa pronto su Unraid!**