Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,566 @@
|
||||
# ?? TradingBot - Installazione su Unraid (Senza Portainer)
|
||||
|
||||
## ? Installazione Diretta da Gitea Registry
|
||||
|
||||
Puoi installare TradingBot direttamente dall'Unraid Docker Manager usando il tuo Gitea Registry!
|
||||
|
||||
---
|
||||
|
||||
## ?? PREREQUISITI
|
||||
|
||||
### 1. Login Gitea Registry su Unraid
|
||||
|
||||
SSH su Unraid:
|
||||
|
||||
```bash
|
||||
ssh root@192.168.30.23 # O IP Tailscale
|
||||
|
||||
# Login al Gitea Registry
|
||||
docker login gitea.encke-hake.ts.net
|
||||
|
||||
# Username: Alby96
|
||||
# Password: [Personal Access Token Gitea]
|
||||
```
|
||||
|
||||
**Output atteso**:
|
||||
```
|
||||
Login Succeeded ?
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ?? METODO 1: Template XML (Consigliato)
|
||||
|
||||
### Step 1: Copia Template su Unraid
|
||||
|
||||
```bash
|
||||
# Su Unraid
|
||||
mkdir -p /boot/config/plugins/dockerMan/templates-user
|
||||
|
||||
# Scarica template
|
||||
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
|
||||
```
|
||||
|
||||
### Step 2: Installa Container
|
||||
|
||||
1. Unraid WebUI ? **Docker** tab
|
||||
2. Click **Add Container** (in fondo)
|
||||
3. **Template**: Dropdown ? Seleziona **TradingBot**
|
||||
4. Configura parametri:
|
||||
|
||||
**Parametri Base**:
|
||||
- **Name**: `TradingBot` (già impostato)
|
||||
- **Repository**: `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest` (già impostato)
|
||||
|
||||
**Porta WebUI** (Visibile e Configurabile!):
|
||||
- **WebUI HTTP Port**: `8888` (porta default - cambia se occupata)
|
||||
- Questa è la porta HOST per accedere all'interfaccia web
|
||||
- La porta CONTAINER rimane sempre 8080 (non modificare)
|
||||
- Alternative comuni se 8888 occupata: `8881`, `9999`, `7777`
|
||||
|
||||
**Volume Dati** (?? IMPORTANTE per persistenza!):
|
||||
- **AppData**: `/mnt/user/appdata/tradingbot` (già impostato)
|
||||
- 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)
|
||||
- **ASPNETCORE_URLS**: `http://+:8080` (non modificare - porta interna container)
|
||||
- **TZ**: `Europe/Rome` (cambia per altro timezone)
|
||||
|
||||
5. Click **Apply**
|
||||
|
||||
Unraid farà:
|
||||
- ? Pull immagine da Gitea Registry
|
||||
- ? Crea container con nome "TradingBot"
|
||||
- ? Configura porta WebUI (default 8888 ? host, 8080 ? container)
|
||||
- ? **Crea volume persistente per dati**
|
||||
- ? Start automatico
|
||||
|
||||
### Step 3: Accedi WebUI
|
||||
|
||||
**Metodo A: Click su WebUI Icon** ??
|
||||
|
||||
1. **Docker tab** ? Trova container **TradingBot**
|
||||
2. Nella riga del container, a destra, vedrai l'**icona globe** ??
|
||||
3. Click sull'icona ? Si apre automaticamente `http://192.168.30.23:8888`
|
||||
|
||||
**Metodo B: URL Manuale**
|
||||
|
||||
```
|
||||
http://192.168.30.23:8888
|
||||
```
|
||||
|
||||
(Sostituisci `8888` con la porta HOST che hai configurato)
|
||||
|
||||
?? **IMPORTANTE**: La porta nel browser deve essere quella HOST (8888 default), NON la porta container (8080)
|
||||
|
||||
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:
|
||||
|
||||
### Step 1: Unraid Docker Tab
|
||||
|
||||
1. **Docker** ? **Add Container**
|
||||
2. **Name**: `TradingBot`
|
||||
|
||||
### Step 2: Configurazione Base
|
||||
|
||||
**Repository**:
|
||||
```
|
||||
gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
|
||||
```
|
||||
|
||||
**Network Type**: `Bridge`
|
||||
|
||||
**Console shell command**: `Shell`
|
||||
|
||||
### Step 3: Port Mapping (?? CRITICO!)
|
||||
|
||||
Click **Add another Path, Port, Variable, Label or Device**
|
||||
|
||||
**Config Type**: `Port`
|
||||
- **Name**: `WebUI`
|
||||
- **Container Port**: `8080`
|
||||
- **Host Port**: `8888` ? **Cambia questa se occupata!**
|
||||
- **Connection Type**: `TCP`
|
||||
|
||||
?? **Se questo mapping non viene configurato, la WebUI non sarà accessibile!**
|
||||
|
||||
### Step 4: Volume Mapping (?? IMPORTANTE per persistenza!)
|
||||
|
||||
Click **Add another Path, Port, Variable, Label o Device**
|
||||
|
||||
**Config Type**: `Path`
|
||||
- **Name**: `AppData`
|
||||
- **Container Path**: `/app/data`
|
||||
- **Host Path**: `/mnt/user/appdata/tradingbot`
|
||||
- **Access Mode**: `Read/Write`
|
||||
|
||||
### Step 5: Environment Variables
|
||||
|
||||
**ASPNETCORE_ENVIRONMENT**:
|
||||
- **Name**: `ASPNETCORE_ENVIRONMENT`
|
||||
- **Value**: `Production`
|
||||
|
||||
**ASPNETCORE_URLS**:
|
||||
- **Name**: `ASPNETCORE_URLS`
|
||||
- **Value**: `http://+:8080`
|
||||
|
||||
**TZ** (Opzionale):
|
||||
- **Name**: `TZ`
|
||||
- **Value**: `Europe/Rome` (o tuo timezone)
|
||||
|
||||
### Step 6: Apply
|
||||
|
||||
Click **Apply** in fondo alla pagina.
|
||||
|
||||
---
|
||||
|
||||
## ?? AGGIORNAMENTO CONTAINER
|
||||
|
||||
### Via Unraid Docker Tab
|
||||
|
||||
1. **Docker** ? Trova **TradingBot**
|
||||
2. Click **icona Stop** (ferma container)
|
||||
3. Click **Force Update** (icona update con freccia circolare)
|
||||
4. Attendi pull dell'immagine aggiornata
|
||||
5. Click **icona Start** (avvia container)
|
||||
|
||||
Unraid farà:
|
||||
- ? Pull ultima immagine da Gitea
|
||||
- ? Ricrea container con nuova immagine
|
||||
- ? **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:
|
||||
|
||||
1. **Apps** ? Cerca "User Scripts"
|
||||
2. Installa
|
||||
|
||||
Crea script update:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Nome: Update TradingBot
|
||||
# Schedula: Weekly (ogni domenica alle 3:00 AM)
|
||||
|
||||
# Stop container
|
||||
docker stop TradingBot
|
||||
|
||||
# Pull latest image
|
||||
docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest
|
||||
|
||||
# Start container (Unraid ricrea automaticamente)
|
||||
docker start TradingBot
|
||||
|
||||
# Notifica
|
||||
/usr/local/emhttp/webGui/scripts/notify -s "TradingBot Update" -d "Container aggiornato con successo!" -i "normal"
|
||||
|
||||
echo "Update completato alle $(date)"
|
||||
```
|
||||
|
||||
Schedula: Settimanale o manualmente quando serve.
|
||||
|
||||
---
|
||||
|
||||
## ??? CONFIGURAZIONE PORTA
|
||||
|
||||
### Cambiare Porta WebUI
|
||||
|
||||
La porta **default è 8888** (host) ? **8080** (container).
|
||||
|
||||
Se la porta 8888 è occupata o vuoi usarne un'altra:
|
||||
|
||||
#### **Via Template (Prima Installazione)**
|
||||
|
||||
Durante Step 2 dell'installazione:
|
||||
- **WebUI HTTP Port**: Cambia da `8888` a porta desiderata (es. `8881`, `9999`, `7777`)
|
||||
- ?? Modifica SOLO la porta HOST (a sinistra)
|
||||
- NON modificare la porta Container (deve restare 8080)
|
||||
|
||||
#### **Via Edit (Container Esistente)**
|
||||
|
||||
1. **Docker tab** ? Container **TradingBot**
|
||||
2. Click **Edit** (icona matita/wrench)
|
||||
3. Trova sezione **Port Mappings**
|
||||
4. Vedrai: **Host Port** `8888` ? **Container Port** `8080`
|
||||
5. Modifica **Host Port** (es. da `8888` a `8881`)
|
||||
6. **IMPORTANTE**: NON modificare **Container Port** (deve restare `8080`)
|
||||
7. Click **Apply** in fondo
|
||||
8. Container si riavvierà automaticamente
|
||||
|
||||
#### **Accesso con Nuova Porta**
|
||||
|
||||
```
|
||||
http://192.168.30.23:NUOVA_PORTA_HOST
|
||||
```
|
||||
|
||||
Esempio con porta `8881`:
|
||||
```
|
||||
http://192.168.30.23:8881
|
||||
```
|
||||
|
||||
### Porte Comuni Disponibili
|
||||
|
||||
Se `8888` è occupata, prova queste alternative:
|
||||
|
||||
| Porta | Uso Comune | Probabilità Libera |
|
||||
|-------|------------|-------------------|
|
||||
| `8881` | Alternative port | ????? Alta |
|
||||
| `9999` | Generic services | ???? Alta |
|
||||
| `7777` | Custom apps | ???? Alta |
|
||||
| `8889` | Next to 8888 | ??? Media |
|
||||
| `3000` | Dev servers | ?? Bassa (spesso occupata) |
|
||||
| `8080` | ? NON usare | Troppo comune, quasi sempre occupata |
|
||||
|
||||
**Check porta disponibile**:
|
||||
```bash
|
||||
# Su Unraid via SSH
|
||||
netstat -tulpn | grep :8888
|
||||
# Se restituisce risultato ? porta occupata
|
||||
# Se vuoto ? porta libera ?
|
||||
```
|
||||
|
||||
### Differenza HOST vs CONTAINER Port
|
||||
|
||||
?? **IMPORTANTE da capire**:
|
||||
|
||||
```
|
||||
HOST Port (8888) ? CONTAINER Port (8080)
|
||||
?? Porta su Unraid ?? Porta interna Docker
|
||||
?? Quella nel BROWSER ?? Fissa, NON modificare
|
||||
?? Configurabile ?? Hardcoded nell'app
|
||||
?? Esempio: 8888 ?? Sempre 8080
|
||||
```
|
||||
|
||||
**Esempio configurazione corretta**:
|
||||
```
|
||||
Browser: http://192.168.30.23:8888
|
||||
?? Usa porta HOST
|
||||
|
||||
Docker: 8888 (host) ? 8080 (container)
|
||||
?? Mapping ?? App interna
|
||||
```
|
||||
|
||||
**Cosa NON fare**:
|
||||
- ? Cambiare porta Container da 8080 a altro
|
||||
- ? Modificare `ASPNETCORE_URLS` (deve restare `http://+:8080`)
|
||||
- ? Usare porta Host 8080 (conflitto con container)
|
||||
|
||||
**Cosa puoi fare**:
|
||||
- ? Cambiare porta Host da 8888 a qualsiasi altra libera
|
||||
- ? Usare porta Host diversa per ogni app
|
||||
- ? Accedere con `http://IP:PORTA_HOST`
|
||||
|
||||
---
|
||||
|
||||
## ?? QUICK START COMPLETO
|
||||
|
||||
**Setup in 3 minuti**:
|
||||
|
||||
```bash
|
||||
# 1. Login (una volta)
|
||||
docker login gitea.encke-hake.ts.net
|
||||
|
||||
# 2. Download template
|
||||
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
|
||||
|
||||
# 3. Install via UI
|
||||
# Docker tab ? Add Container ? TradingBot template ? Apply
|
||||
|
||||
# 4. Access WebUI
|
||||
# Metodo A: Click icona ?? nella Docker tab
|
||||
# Metodo B: http://192.168.30.23:8888
|
||||
```
|
||||
|
||||
**?? TradingBot pronto su Unraid!**
|
||||
|
||||
---
|
||||
|
||||
## ?? Nota sulla Porta
|
||||
|
||||
**Default**: Porta HOST `8888` (invece di 8080)
|
||||
|
||||
**Perché 8888?**
|
||||
- Porta 8080 è troppo comune e spesso occupata
|
||||
- 8888 è quasi sempre libera su Unraid
|
||||
- Facile da ricordare (quattro 8)
|
||||
- WebUI icon funziona automaticamente
|
||||
|
||||
**Se 8888 è occupata**: Cambia in fase di installazione o dopo via Edit
|
||||
|
||||
---
|
||||
|
||||
## ?? ACCESSO WEBUI
|
||||
|
||||
### Locale (Unraid LAN)
|
||||
|
||||
```
|
||||
http://192.168.30.23:8888
|
||||
```
|
||||
|
||||
Sostituisci:
|
||||
- `192.168.30.23` con IP del tuo Unraid
|
||||
- `8888` con porta HOST configurata (se diversa)
|
||||
|
||||
### Via Tailscale
|
||||
|
||||
Se hai configurato Tailscale su Unraid:
|
||||
|
||||
```
|
||||
http://unraid.encke-hake.ts.net:8888
|
||||
```
|
||||
|
||||
### Via Hostname Unraid
|
||||
|
||||
Se hai configurato hostname:
|
||||
|
||||
```
|
||||
http://tower:8888
|
||||
```
|
||||
|
||||
(Sostituisci `tower` con hostname del tuo Unraid e `8888` con porta configurata)
|
||||
|
||||
### Reverse Proxy (Accesso HTTPS)
|
||||
|
||||
Se usi **Nginx Proxy Manager** o **Swag**:
|
||||
|
||||
```nginx
|
||||
# Nginx Proxy Manager
|
||||
Upstream: http://192.168.30.23:8888
|
||||
Domain: tradingbot.tuo-dominio.com
|
||||
SSL: Let's Encrypt
|
||||
```
|
||||
|
||||
Poi accedi via:
|
||||
```
|
||||
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!**
|
||||
Reference in New Issue
Block a user