From cc34d2b57ff15c0875fa98d5012b469e7c3cd361 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Wed, 17 Dec 2025 23:15:46 +0100 Subject: [PATCH] Riorganizzazione deployment, doc e publish automatico MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Spostata tutta la configurazione di deployment in /deployment (docker-compose, unraid-template, guide) - Aggiunte e aggiornate guide dettagliate: publishing su Gitea, installazione Unraid, struttura progetto - Migliorato target MSBuild: publish automatico su Gitea Registry da Visual Studio, log dettagliati, condizioni più robuste - Aggiornato e ampliato .gitignore per escludere build, dati e file locali - Rimossi file obsoleti dalla root (ora tutto in /deployment) - Struttura più chiara, zero script esterni, documentazione completa e workflow di deploy semplificato --- TradingBot/.gitignore | 102 +++ TradingBot/README.md | 418 +++++++++++ TradingBot/TradingBot.csproj | 84 ++- TradingBot/deployment/PUBLISHING_GUIDE.md | 413 +++++++++++ TradingBot/deployment/README.md | 168 +++++ TradingBot/deployment/UNRAID_INSTALL.md | 647 ++++++++++++++++++ .../{ => deployment}/docker-compose.yml | 0 TradingBot/deployment/unraid-template.xml | 38 + TradingBot/docs/PROJECT_STRUCTURE.md | 274 ++++++++ .../docs/deployment/UNRAID_NATIVE_INSTALL.md | 427 ------------ TradingBot/unraid-template.xml | 29 - 11 files changed, 2125 insertions(+), 475 deletions(-) create mode 100644 TradingBot/.gitignore create mode 100644 TradingBot/README.md create mode 100644 TradingBot/deployment/PUBLISHING_GUIDE.md create mode 100644 TradingBot/deployment/README.md create mode 100644 TradingBot/deployment/UNRAID_INSTALL.md rename TradingBot/{ => deployment}/docker-compose.yml (100%) create mode 100644 TradingBot/deployment/unraid-template.xml create mode 100644 TradingBot/docs/PROJECT_STRUCTURE.md delete mode 100644 TradingBot/docs/deployment/UNRAID_NATIVE_INSTALL.md delete mode 100644 TradingBot/unraid-template.xml diff --git a/TradingBot/.gitignore b/TradingBot/.gitignore new file mode 100644 index 0000000..3c1c0dc --- /dev/null +++ b/TradingBot/.gitignore @@ -0,0 +1,102 @@ +# Visual Studio +.vs/ +*.user +*.suo +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Docker +obj/Docker/ + +# NuGet +*.nupkg +*.snupkg +**/packages/* +!**/packages/build/ + +# Files generated by publishing +[Pp]ublish/ +PublishOutput/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# ReSharper +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JetBrains Rider +.idea/ +*.sln.iml + +# Visual Studio cache files +*.[Cc]ache +!?*.[Cc]ache/ + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# Mono Auto Generated Files +mono_crash.* + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac files +.DS_Store + +# Application data +**/data/ +*.db +*.db-shm +*.db-wal + +# Logs +*.log + +# Temporary files +*.tmp +*.temp diff --git a/TradingBot/README.md b/TradingBot/README.md new file mode 100644 index 0000000..4ce9539 --- /dev/null +++ b/TradingBot/README.md @@ -0,0 +1,418 @@ +# ?? TradingBot + +**Automated Crypto Trading Bot** con interfaccia Blazor Server per trading algoritmico simulato. + +[![.NET 10](https://img.shields.io/badge/.NET-10.0-512BD4)](https://dotnet.microsoft.com/) +[![Blazor](https://img.shields.io/badge/Blazor-Server-512BD4)](https://blazor.net/) +[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED)](https://www.docker.com/) +[![License](https://img.shields.io/badge/License-MIT-green)](LICENSE) + +--- + +## ?? Indice + +- [Caratteristiche](#-caratteristiche) +- [Architettura](#-architettura) +- [Quick Start](#-quick-start) +- [Deployment](#-deployment) +- [Sviluppo](#-sviluppo) +- [Documentazione](#-documentazione) + +--- + +## ? Caratteristiche + +### ?? Trading Algoritmico +- **Simple Moving Average (SMA)** strategy integrata +- **Analisi tecnica** in tempo reale +- **Gestione portfolio** automatizzata +- **Simulazione trading** senza rischi reali + +### ?? Dashboard Interattiva +- **Blazor Server UI** reattiva e moderna +- **Real-time updates** ogni 3 secondi +- **Grafici** statistiche di performance +- **Gestione asset** con configurazione granulare + +### ?? Gestione Completa +- **15 Criptovalute** supportate (BTC, ETH, BNB, etc.) +- **Configurazione per asset** (importo, strategia) +- **History completa** delle operazioni +- **Settings centralizzate** e persistenti + +### ?? Docker-Ready +- **Container ottimizzato** per produzione +- **Health checks** integrati +- **Volume persistente** per dati +- **Gitea Registry** integration + +--- + +## ??? Architettura + +``` +TradingBot/ +??? Components/ # Blazor Components +? ??? Pages/ # Pagine (Dashboard, Market, etc.) +? ??? Layout/ # Layout e ReconnectModal +? ??? Shared/ # Componenti condivisi +??? Services/ # Business Logic +? ??? TradingBotService.cs # Core service +? ??? SimulatedMarketDataService.cs # Market data +? ??? SimpleMovingAverageStrategy.cs # Trading strategy +? ??? SettingsService.cs # Persistenza settings +? ??? TechnicalAnalysis.cs # Indicatori tecnici +??? Models/ # Data Models +? ??? Trade.cs +? ??? MarketPrice.cs +? ??? TradingSignal.cs +? ??? ... +??? wwwroot/ # Static assets +? ??? css/ +? ??? lib/ +??? Properties/ # Configuration +? ??? PublishProfiles/ # Docker publish profiles +? ??? launchSettings.json +??? docs/ # Documentation +? ??? deployment/ # Deployment guides +??? Dockerfile # Docker multi-stage build +??? docker-compose.yml # Compose configuration +??? Program.cs # App entry point +``` + +### ?? Data Flow + +``` +Market Data ? Analysis ? Signal ? Execution ? Portfolio Update ? UI Refresh + ? ? ? ? ? ? +Simulated SMA Buy/Sell Simulated Statistics Dashboard + Prices Strategy Hold Trade Update Update +``` + +--- + +## ?? Quick Start + +### Prerequisiti + +- [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) +- [Docker Desktop](https://www.docker.com/products/docker-desktop) (per deployment) +- [Visual Studio 2022](https://visualstudio.microsoft.com/) (consigliato) o VS Code + +### Esecuzione Locale + +```bash +# Clone repository +git clone https://gitea.encke-hake.ts.net/Alby96/Encelado +cd Encelado/TradingBot + +# Restore dependencies +dotnet restore + +# Run +dotnet run + +# Oppure da Visual Studio: +# F5 (Debug) o Ctrl+F5 (senza debug) +``` + +**Accedi a**: `http://localhost:5243` + +--- + +## ?? Deployment + +### ?? Docker + +#### Build & Run Locale + +```bash +# Build image +docker build -t tradingbot:latest . + +# Run container +docker run -d \ + --name tradingbot \ + -p 8080:8080 \ + -v tradingbot-data:/app/data \ + tradingbot:latest +``` + +**Accedi a**: `http://localhost:8080` + +#### Con Docker Compose + +```bash +docker-compose up -d +``` + +### ?? Unraid + +Guida completa: [docs/deployment/UNRAID_NATIVE_INSTALL.md](docs/deployment/UNRAID_NATIVE_INSTALL.md) + +**Quick Install**: + +```bash +# Login Gitea Registry +docker login gitea.encke-hake.ts.net + +# 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 + +# Install via Unraid Docker UI +``` + +### ?? Gitea Container Registry + +#### Publish da Visual Studio + +1. **Build** ? **Configuration Manager** ? **Release** +2. **Build** ? **Publish TradingBot** +3. Seleziona profilo **"Docker"** +4. Click **"Publish"** + +Visual Studio automaticamente: +- ? Build immagine Docker +- ? Tag per Gitea Registry +- ? Push su `gitea.encke-hake.ts.net/alby96/encelado/tradingbot` + +#### Pull & Deploy + +```bash +docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest +docker run -d -p 8080:8080 gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest +``` + +--- + +## ?? Sviluppo + +### Struttura Progetto + +- **`.NET 10`** - Latest .NET version +- **`Blazor Server`** - Interactive server-side rendering +- **`C# 14`** - Latest language features +- **`Bootstrap 5`** - Responsive UI framework + +### Debug + +#### Visual Studio + +``` +1. Set startup profile: "TradingBot" (HTTP) o "Docker" +2. F5 per debug con breakpoints +3. Hot Reload abilitato per UI changes +``` + +#### VS Code + +```bash +# Install C# Dev Kit extension +# Open folder in VS Code +code . + +# F5 per debug +``` + +### Test Locale + +```bash +# Run senza debug +dotnet run --no-build + +# Watch mode (auto-rebuild on changes) +dotnet watch run +``` + +### Build Configuration + +- **Debug**: Development, verbose logging, no optimizations +- **Release**: Production-ready, optimized, Docker-compatible + +--- + +## ?? Documentazione + +### Guide Deployment + +- [**Unraid Native Install**](docs/deployment/UNRAID_NATIVE_INSTALL.md) - Installazione su Unraid senza Portainer +- [**Docker Compose**](docker-compose.yml) - Configurazione Docker Compose +- [**Template Unraid**](deployment/unraid-template.xml) - Template XML per Unraid + +### API & Architettura + +#### Services + +- **TradingBotService**: Core trading logic e portfolio management +- **SimulatedMarketDataService**: Generazione dati di mercato simulati +- **SimpleMovingAverageStrategy**: Strategia SMA per segnali trading +- **SettingsService**: Persistenza configurazioni utente +- **TechnicalAnalysis**: Calcolo indicatori tecnici (SMA, EMA, RSI, MACD) + +#### Models + +- **Trade**: Rappresenta un'operazione di trading +- **MarketPrice**: Snapshot prezzo e volume di un asset +- **TradingSignal**: Segnale generato dalla strategia (Buy/Sell/Hold) +- **PortfolioStatistics**: Statistiche aggregate del portfolio +- **AssetConfiguration**: Configurazione per singolo asset + +### Configurazione + +#### Environment Variables + +```bash +ASPNETCORE_ENVIRONMENT=Production # Development|Production +ASPNETCORE_URLS=http://+:8080 # Bind URL +EXTERNAL_PORT=8080 # External port (docker-compose) +``` + +#### Ports + +- **5243**: HTTP (Development) +- **7241**: HTTPS (Development) +- **8080**: HTTP (Production/Docker) + +#### Volumes + +- **`/app/data`**: Persistenza dati (settings, trade history) + +--- + +## ?? Configurazione Avanzata + +### Custom Strategy + +Implementa `ITradingStrategy` per creare strategie personalizzate: + +```csharp +public class MyCustomStrategy : ITradingStrategy +{ + public string Name => "My Custom Strategy"; + + public Task AnalyzeAsync(string symbol, List prices) + { + // Your strategy logic here + return Task.FromResult(new TradingSignal { ... }); + } +} +``` + +Registra nel `Program.cs`: + +```csharp +builder.Services.AddSingleton(); +``` + +### Asset Configuration + +Modifica asset supportati in `TradingBotService.cs`: + +```csharp +private void InitializeAssetConfigurations() +{ + AssetConfigurations.Add("MYNEWCOIN", new AssetConfiguration + { + Symbol = "MYNEWCOIN", + Name = "My New Coin", + TradingAmount = 1000, + IsEnabled = true + }); +} +``` + +--- + +## ?? Features Roadmap + +### ? Implementato + +- [x] Dashboard con statistiche real-time +- [x] Simulazione trading multi-asset +- [x] Simple Moving Average strategy +- [x] Portfolio management +- [x] Trade history +- [x] Settings persistenti +- [x] Docker support +- [x] Unraid template +- [x] Gitea Registry integration + +### ?? In Sviluppo + +- [ ] Autenticazione utenti +- [ ] Strategie avanzate (RSI, MACD, Bollinger Bands) +- [ ] Backtesting su dati storici +- [ ] API REST per integrazione esterna +- [ ] Notifiche (email, Telegram) +- [ ] Grafici interattivi (ChartJS/ApexCharts) + +### ?? Pianificato + +- [ ] Integrazione exchange reali (Binance, Coinbase) +- [ ] Machine Learning per prediction +- [ ] Multi-utente con isolation +- [ ] Mobile app (MAUI) +- [ ] Advanced analytics dashboard + +--- + +## ??? Tecnologie Utilizzate + +### Backend +- **.NET 10** - Framework applicativo +- **ASP.NET Core** - Web server +- **C# 14** - Linguaggio programmazione + +### Frontend +- **Blazor Server** - UI framework +- **Bootstrap 5.3** - CSS framework +- **Bootstrap Icons** - Iconografia + +### Infrastructure +- **Docker** - Containerization +- **Gitea** - Git repository & Container Registry +- **Unraid** - Home server platform + +--- + +## ?? License + +Questo progetto rilasciato sotto licenza MIT. Vedi [LICENSE](LICENSE) per dettagli. + +--- + +## ?? Contributi + +Contributi, issues e feature requests sono benvenuti! + +1. Fork il progetto +2. Crea un feature branch (`git checkout -b feature/AmazingFeature`) +3. Commit le modifiche (`git commit -m 'Add AmazingFeature'`) +4. Push al branch (`git push origin feature/AmazingFeature`) +5. Apri una Pull Request + +--- + +## ?? Autore + +**Alberto** (Alby96) + +- Gitea: [@Alby96](https://gitea.encke-hake.ts.net/Alby96) +- Repository: [Encelado/TradingBot](https://gitea.encke-hake.ts.net/Alby96/Encelado) + +--- + +## ?? Acknowledgments + +- [Microsoft .NET](https://dotnet.microsoft.com/) - Amazing framework +- [Blazor](https://blazor.net/) - Modern web UI +- [Bootstrap](https://getbootstrap.com/) - Responsive design +- [Docker](https://www.docker.com/) - Containerization +- [Gitea](https://gitea.io/) - Self-hosted Git service + +--- + +**Made with ?? for algorithmic trading enthusiasts** + +?? **Happy Trading!** diff --git a/TradingBot/TradingBot.csproj b/TradingBot/TradingBot.csproj index 7b3f8c1..664b17b 100644 --- a/TradingBot/TradingBot.csproj +++ b/TradingBot/TradingBot.csproj @@ -1,4 +1,4 @@ - + net10.0 @@ -14,35 +14,81 @@ 1.0.0 1.0.0.0 1.0.0.0 + + + gitea.encke-hake.ts.net + alby96/encelado/tradingbot - - - + + + + + + + + + + + $(ContainerRegistry)/$(ContainerRepository) + + + + + + + + - + - + + + + + - + - + - - - + + + + + + + + + + + + + + + + diff --git a/TradingBot/deployment/PUBLISHING_GUIDE.md b/TradingBot/deployment/PUBLISHING_GUIDE.md new file mode 100644 index 0000000..6f4d977 --- /dev/null +++ b/TradingBot/deployment/PUBLISHING_GUIDE.md @@ -0,0 +1,413 @@ +# ?? Publishing Guide - TradingBot + +Guida completa per pubblicare TradingBot su Gitea Container Registry usando **SOLO** Visual Studio e MSBuild integrato. + +--- + +## ? Setup Prerequisiti (Una Volta) + +### 1. Login Gitea Registry + +Apri PowerShell/Terminal: + +```powershell +docker login gitea.encke-hake.ts.net +# Username: Alby96 +# Password: [Personal Access Token Gitea] +``` + +Output: +``` +Login Succeeded ? +``` + +### 2. Verifica Docker Desktop + +Assicurati che Docker Desktop sia in running: + +```powershell +docker --version +# Docker version 24.x.x o superiore +``` + +--- + +## ?? Publishing Workflow + +### Metodo Unico: Visual Studio + MSBuild Automatico + +#### Step 1: Seleziona Release Configuration + +1. **Build menu** ? **Configuration Manager** +2. **Active solution configuration**: Seleziona **Release** +3. Click **Close** + +#### Step 2: Publish con Profilo Docker + +1. **Solution Explorer** ? Right-click **TradingBot** +2. Click **Publish...** +3. Seleziona profilo **"Docker"** +4. Click sul pulsante **"Publish"** + +#### Step 3: Automatico! ? + +Visual Studio esegue automaticamente: + +``` +1. ? Compila progetto in Release mode +2. ? Build immagine Docker (tradingbot:latest) +3. ? Post-build MSBuild target (AUTOMATICO): + - Verifica condizioni (Release + Docker profile) + - Tag gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest + - Tag gitea.encke-hake.ts.net/alby96/encelado/tradingbot:1.0.0 + - Push entrambi i tag su Gitea Registry +4. ? Mostra conferma nell'Output Window +``` + +?? **Tempo**: 3-5 minuti (prima volta), 1-2 minuti (successive) + +--- + +## ?? Verifica Output + +### Output Window + +Durante il publish, monitora l'**Output Window**: + +``` +View ? Output (Ctrl+Alt+O) +Dropdown: "Build" +``` + +**Dovresti vedere**: + +``` +========== Build started ========== +1> Building Docker image... +... +1> Successfully built abc123def456 +1> Successfully tagged tradingbot:latest + +======================================== +?? Gitea Container Registry Push +======================================== + +??? Tagging images... +? Tagged successfully + +?? Pushing to gitea.encke-hake.ts.net... +The push refers to repository [gitea.encke-hake.ts.net/alby96/encelado/tradingbot] +latest: digest: sha256:... size: 1234 + +======================================== +? Successfully pushed to Gitea Registry! +======================================== + +?? Published images: + - gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest + - gitea.encke-hake.ts.net/alby96/encelado/tradingbot:1.0.0 + +?? Verify at: + https://gitea.encke-hake.ts.net/Alby96/Encelado/-/packages + +========== Publish: 1 succeeded ========== +``` + +--- + +## ?? Verifica su Gitea + +Dopo il publish, apri browser: + +``` +https://gitea.encke-hake.ts.net/Alby96/Encelado/-/packages +``` + +Dovresti vedere: + +``` +?? tradingbot + ??? latest (280 MB) + ? ??? Pushed 2 minutes ago + ??? 1.0.0 (280 MB) + ??? Pushed 2 minutes ago +``` + +--- + +## ?? Aggiornamento Versione + +### Incrementa Versione + +Modifica `TradingBot.csproj`: + +```xml + + 1.0.1 + 1.0.1.0 + 1.0.1.0 + +``` + +### Publish Nuova Versione + +Esegui di nuovo il workflow di publish. Verranno creati: +- `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest` (aggiornato) +- `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:1.0.1` (nuovo) + +--- + +## ?? Come Funziona (Dettagli Tecnici) + +### Post-Build MSBuild Target + +Il file `TradingBot.csproj` contiene un target MSBuild che si attiva automaticamente: + +```xml + + + +``` + +**Condizioni di attivazione**: +1. ? Configuration = **Release** +2. ? Non siamo dentro un container Docker +3. ? Profilo Docker in uso (`DockerPublish='true'`) + +**Cosa fa**: +1. Tag immagine locale `tradingbot:latest` +2. Tag con `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest` +3. Tag con `gitea.encke-hake.ts.net/alby96/encelado/tradingbot:{Version}` +4. Push entrambi i tag su Gitea Registry +5. Mostra messaggi nell'Output Window + +--- + +## ?? Troubleshooting + +### Errore: "docker: command not found" + +**Causa**: Docker non in PATH o non installato + +**Fix**: +1. Verifica Docker Desktop sia installato e running +2. Restart Visual Studio +3. Verifica in PowerShell: `docker --version` + +### Errore: "unauthorized: authentication required" + +**Causa**: Non loggato a Gitea Registry + +**Fix**: +```powershell +docker logout gitea.encke-hake.ts.net +docker login gitea.encke-hake.ts.net +# Inserisci credenziali +``` + +### Errore: "denied: requested access to the resource is denied" + +**Causa**: Permessi insufficienti o repository non esiste + +**Fix**: +1. Verifica che il repository packages esista su Gitea +2. Verifica che il token abbia scope `write:packages` +3. Verifica username corretto nel `.csproj` (`ContainerRepository`) + +### Post-Build Non Si Attiva + +**Causa**: Condizioni non soddisfatte + +**Fix - Verifica**: +1. ? **Configuration Manager** ? **Release** attivo +2. ? Profilo **"Docker"** selezionato (non altri profili) +3. ? Docker Desktop running +4. ? `docker login` eseguito + +**Diagnosi**: +```powershell +# Verifica immagine locale esista dopo publish +docker images | findstr tradingbot + +# Dovresti vedere: tradingbot latest ... +``` + +Se l'immagine locale esiste ma il push non parte: +- Controlla Output Window per messaggi di errore +- Verifica che `DockerPublish='true'` sia nel profilo Docker.pubxml + +### Errore: "La ricompilazione non riuscita" + +**Causa**: Errore durante build o post-build + +**Fix**: +1. **View** ? **Output** ? Dropdown: **Build** +2. Cerca errori specifici (linea rossa) +3. Se errore docker: verifica Docker Desktop running +4. Se errore MSBuild: verifica sintassi `.csproj` + +**Clean & Rebuild**: +``` +Build ? Clean Solution +Build ? Rebuild Solution +Build ? Publish (retry) +``` + +--- + +## ?? Checklist Publish + +### Pre-Publish +- [ ] Docker Desktop running +- [ ] `docker login gitea.encke-hake.ts.net` successful +- [ ] Configuration Manager ? Release +- [ ] Codice committato su Git (opzionale ma consigliato) + +### During Publish +- [ ] Visual Studio ? Build ? Publish +- [ ] Profilo "Docker" selezionato +- [ ] Build completa senza errori +- [ ] Output mostra "Successfully pushed to Gitea Registry!" + +### Post-Publish +- [ ] Verifica su Gitea Packages +- [ ] Tag `latest` e versione presenti +- [ ] (Opzionale) Deploy su Unraid + +--- + +## ?? Best Practices + +### Versioning + +Usa [Semantic Versioning](https://semver.org/): +- **MAJOR**: Breaking changes (2.0.0) +- **MINOR**: New features (1.1.0) +- **PATCH**: Bug fixes (1.0.1) + +### Git Workflow + +```bash +# 1. Sviluppo feature +git checkout -b feature/new-feature + +# 2. Commit changes +git add . +git commit -m "feat: Add new feature" + +# 3. Merge in main +git checkout main +git merge feature/new-feature + +# 4. Tag release +git tag -a v1.0.1 -m "Release 1.0.1" +git push origin main --tags + +# 5. Publish Docker image (Visual Studio) +``` + +### Testing + +Prima di ogni publish: +1. Test locale (F5 in Debug) +2. Test in Docker locale (profilo Docker, F5) +3. Verifica funzionalit critiche +4. Publish su Gitea (Release mode) +5. Deploy su Unraid per test finale + +--- + +## ?? Workflow Completo: Dev ? Production + +``` +1. ?? Sviluppo in Visual Studio + ?? F5 per test locale (HTTP profile) + ?? F5 con Docker profile per test container + ?? Commit su Git + +2. ?? Build & Publish + ?? Configuration ? Release + ?? Build ? Publish (Docker profile) + ?? MSBuild automatico: tag & push Gitea ? + +3. ?? Verifica Gitea Packages + ?? Browser: packages disponibili + +4. ?? Deploy su Unraid + ?? Docker tab ? Stop + ?? Force Update (pull latest) + ?? Start + +5. ? Test in Production + ?? http://192.168.30.23:8080 +``` + +**Tempo totale**: ~10 minuti (compresi test) + +--- + +## ?? Risorse + +### File di Configurazione + +- **`TradingBot.csproj`**: Contiene il post-build target `PushToGiteaRegistry` +- **`Properties/PublishProfiles/Docker.pubxml`**: Profilo publish Docker +- **`Dockerfile`**: Multi-stage build configuration + +### Links Utili + +- [MSBuild Targets](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-targets) +- [Docker CLI Reference](https://docs.docker.com/engine/reference/commandline/cli/) +- [Gitea Packages](https://docs.gitea.com/usage/packages/container) + +--- + +## ?? Tips & Tricks + +### Debug Post-Build Target + +Per vedere cosa sta facendo il post-build: + +1. **Output Window** ? Dropdown: **Build** +2. Cerca sezione: +``` +======================================== +?? Gitea Container Registry Push +======================================== +``` + +### Build Solo Docker (Senza Push) + +Se vuoi solo buildare l'immagine senza push: + +**Opzione 1**: Usa Debug mode +``` +Configuration Manager ? Debug +Build ? Publish (Docker) +# Post-build NON si attiva (serve Release) +``` + +**Opzione 2**: Build manuale +```powershell +docker build -t tradingbot:latest . +# Crea solo immagine locale +``` + +### Push Manuale (Se Serve) + +Se hai gi l'immagine locale e vuoi solo push: + +```powershell +docker tag tradingbot:latest gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest +docker push gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest +``` + +--- + +**?? Publish integrato completamente in Visual Studio!** + +**Zero script esterni, tutto automatico con MSBuild!** ? diff --git a/TradingBot/deployment/README.md b/TradingBot/deployment/README.md new file mode 100644 index 0000000..363e492 --- /dev/null +++ b/TradingBot/deployment/README.md @@ -0,0 +1,168 @@ +# ?? Deployment Resources + +Questa cartella contiene tutti i file e le guide necessarie per il deployment di TradingBot. + +--- + +## ?? Contenuto + +### ?? Guide + +- **[PUBLISHING_GUIDE.md](PUBLISHING_GUIDE.md)** - Guida completa per pubblicare su Gitea Registry da Visual Studio +- **[UNRAID_INSTALL.md](UNRAID_INSTALL.md)** - Installazione nativa su Unraid senza Portainer + +### ?? Docker Files + +- **[docker-compose.yml](docker-compose.yml)** - Configurazione Docker Compose per deploy rapido +- **[unraid-template.xml](unraid-template.xml)** - Template XML per installazione 1-click su Unraid + +### ?? Dockerfile + +Il `Dockerfile` principale si trova nella **root del progetto** per compatibilit con Visual Studio Container Tools. + +--- + +## ?? Quick Start + +### Publish da Visual Studio + +``` +1. Build ? Configuration Manager ? Release +2. Build ? Publish TradingBot +3. Seleziona profilo "Docker" +4. Click "Publish" +5. ? Automatico: Build + Push su Gitea Registry +``` + +**Guida dettagliata**: [PUBLISHING_GUIDE.md](PUBLISHING_GUIDE.md) + +### Deploy su Unraid + +```bash +# 1. Login Gitea Registry +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 Docker tab +``` + +**Guida dettagliata**: [UNRAID_INSTALL.md](UNRAID_INSTALL.md) + +### Deploy con Docker Compose + +```bash +# Clone repository +git clone https://gitea.encke-hake.ts.net/Alby96/Encelado +cd Encelado/TradingBot/deployment + +# Deploy +docker-compose up -d + +# Accedi: http://localhost:8080 +``` + +--- + +## ?? Workflow Consigliato + +``` +Sviluppo (PC) Publish Deploy (Unraid) +????????????? ??????? ??????????????? + +Visual Studio ? Gitea Registry ? Unraid Docker + - Codice - Container - Pull image + - Test F5 - Versioning - Start + - Commit - Latest + v1.0.0 - WebUI ready +``` + +--- + +## ?? Gestione Versioni + +### File di Configurazione + +La versione definita in `TradingBot.csproj`: + +```xml + + 1.0.0 + +``` + +### Tag Generati Automaticamente + +Ogni publish crea 2 tag: +- `latest` - Sempre ultima versione +- `1.0.0` - Versione specifica + +### Rollback + +Per tornare a una versione precedente: + +```bash +# Su Unraid +docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:1.0.0 +docker stop TradingBot +docker rm TradingBot +# Ricrea container con versione specifica +``` + +--- + +## ?? Registry Access + +### Gitea Container Registry + +- **URL**: `gitea.encke-hake.ts.net` +- **Repository**: `alby96/encelado/tradingbot` +- **Auth**: Personal Access Token con scope `write:packages` + +### Login + +```bash +docker login gitea.encke-hake.ts.net +# Username: Alby96 +# Password: [token] +``` + +--- + +## ?? Risorse Aggiuntive + +### Documentation + +- [Dockerfile](../Dockerfile) - Multi-stage build configuration +- [README.md](../README.md) - Documentazione principale progetto +- [.dockerignore](../.dockerignore) - File esclusi dal build context + +### Repository + +- **Git**: `https://gitea.encke-hake.ts.net/Alby96/Encelado` +- **Packages**: `https://gitea.encke-hake.ts.net/Alby96/Encelado/-/packages` +- **Issues**: `https://gitea.encke-hake.ts.net/Alby96/Encelado/issues` + +--- + +## ? Checklist Deployment + +### Setup Iniziale +- [ ] Docker Desktop installato e running +- [ ] Login Gitea Registry successful +- [ ] Unraid Docker service attivo (se deploy su Unraid) + +### Ogni Deploy +- [ ] Codice committato su Git +- [ ] Versione incrementata (se necessario) +- [ ] Publish da Visual Studio successful +- [ ] Verifica packages su Gitea +- [ ] Pull & deploy su target environment +- [ ] Test funzionalit in production + +--- + +**?? Deployment semplificato e automatizzato!** + +**No script esterni, tutto integrato in Visual Studio e MSBuild!** ? diff --git a/TradingBot/deployment/UNRAID_INSTALL.md b/TradingBot/deployment/UNRAID_INSTALL.md new file mode 100644 index 0000000..bb63530 --- /dev/null +++ b/TradingBot/deployment/UNRAID_INSTALL.md @@ -0,0 +1,647 @@ +# ?? 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** (Importante!): + - **WebUI Port**: `8080` (cambia se occupata, es. `8081`, `9000`, etc.) + - Questa la porta per accedere all'interfaccia web + + **Volume Dati**: + - **AppData**: `/mnt/user/appdata/tradingbot` (gi impostato) + - Puoi cambiare se preferisci altra directory + + **Variabili Ambiente** (Avanzate - opzionali): + - **ASPNETCORE_ENVIRONMENT**: `Production` (non modificare) + - **ASPNETCORE_URLS**: `http://+:8080` (non modificare) + - **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 8080) +- ? Crea volume per persistenza dati +- ? Start automatico + +### Step 3: Accedi WebUI + +**Metodo A: Click su WebUI Icon** + +1. **Docker tab** ? Trova container **TradingBot** +2. Nella colonna "WebUI", click sull'**icona globe** ?? +3. Si aprir la dashboard nel browser + +**Metodo B: URL Manuale** + +``` +http://192.168.30.23:8080 +``` + +(Sostituisci `8080` con la porta che hai configurato) + +Dovresti vedere la **Dashboard TradingBot**! ?? + +--- + +## ?? 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 + +Click **Add another Path, Port, Variable, Label or Device** + +**Config Type**: `Port` +- **Name**: `WebUI` +- **Container Port**: `8080` +- **Host Port**: `8080` ? **Cambia questa se occupata!** +- **Connection Type**: `TCP` + +### Step 4: Volume Mapping + +Click **Add another Path, Port, Variable, Label or 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: 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 + +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.) + +### 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 + +Se la porta `8080` gi occupata o vuoi usarne un'altra: + +#### **Via Template (Prima Installazione)** + +Durante Step 2 dell'installazione: +- **WebUI Port**: Cambia da `8080` a porta desiderata (es. `8081`, `9000`, `8888`) + +#### **Via Edit (Container Esistente)** + +1. **Docker tab** ? Container **TradingBot** +2. Click **Edit** (icona matita) +3. Trova sezione **Port Mappings** +4. Modifica **Host Port** (es. da `8080` a `8081`) +5. **IMPORTANTE**: Non modificare **Container Port** (deve restare `8080`) +6. Click **Apply** +7. Container si riavvier automaticamente + +#### **Accesso con Nuova Porta** + +``` +http://192.168.30.23:NUOVA_PORTA +``` + +Esempio con porta `8081`: +``` +http://192.168.30.23:8081 +``` + +### Porte Comuni Disponibili + +Se `8080` occupata, prova queste: +- `8081` - Spesso libera +- `9000` - Usata da Portainer ma se non hai Portainer libera +- `8888` - Buona alternativa +- `7070` - Altra opzione +- `3000` - Se libera + +**Check porta disponibile**: +```bash +netstat -tulpn | grep :8080 +# Se restituisce risultato, porta occupata +# Se vuoto, porta libera +``` + +--- + +## ?? GESTIONE CONTAINER + +### Start/Stop/Restart + +**Docker tab** ? Container **TradingBot**: +- ?? **Start**: Avvia container +- ?? **Pause**: Pausa (mantiene in memoria) +- ?? **Stop**: Ferma completamente +- ?? **Restart**: Riavvia +- ??? **Remove**: Elimina container (dati persistenti restano) + +### View Logs + +**Docker tab** ? Container **TradingBot** ? Click **icona logs** (terminale) + +Oppure via SSH: +```bash +docker logs TradingBot -f +# -f = follow (real-time) +# Ctrl+C per uscire +``` + +### Console Access + +**Docker tab** ? Container **TradingBot** ? Click **icona console** (bash) + +Oppure via SSH: +```bash +docker exec -it TradingBot sh +# sh invece di bash (Alpine Linux base) +``` + +### Statistics + +**Docker tab** ? Container **TradingBot** ? Click **icona stats** (grafico) + +Mostra: +- **CPU**: Utilizzo percentuale +- **Memory**: RAM utilizzata/disponibile +- **Network I/O**: Traffico in/out +- **Block I/O**: Lettura/scrittura disco + +--- + +## ?? ACCESSO WEBUI + +### Locale (Unraid LAN) + +``` +http://192.168.30.23:8080 +``` + +Sostituisci: +- `192.168.30.23` con IP del tuo Unraid +- `8080` con porta configurata + +### Via Tailscale + +Se hai configurato Tailscale su Unraid: + +``` +http://unraid.encke-hake.ts.net:8080 +``` + +### Via Hostname Unraid + +Se hai configurato hostname: + +``` +http://tower:8080 +``` + +(Sostituisci `tower` con hostname del tuo Unraid) + +### Reverse Proxy (Accesso HTTPS) + +Se usi **Nginx Proxy Manager** o **Swag**: + +```nginx +# Nginx Proxy Manager +Upstream: http://192.168.30.23:8080 +Domain: tradingbot.tuo-dominio.com +SSL: Let's Encrypt +``` + +Poi accedi via: +``` +https://tradingbot.tuo-dominio.com +``` + +--- + +## ?? 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) +? **Health checks** attivi per monitoring + +### Backup Dati + +#### **Manuale** + +```bash +# Backup +tar -czf /mnt/user/backups/tradingbot-$(date +%Y%m%d).tar.gz \ + /mnt/user/appdata/tradingbot + +# Restore +tar -xzf /mnt/user/backups/tradingbot-20241217.tar.gz -C /mnt/user/appdata/ +``` + +#### **Con CA Backup Plugin** + +1. **Apps** ? Installa "**CA Backup / Restore Appdata**" +2. **Settings** ? **CA Backup/Restore** +3. Aggiungi `/mnt/user/appdata/tradingbot` alla lista +4. Configura schedule automatico (es. giornaliero alle 2:00 AM) + +--- + +## ?? TROUBLESHOOTING + +### WebUI Non Accessibile + +**Checklist Diagnostica**: + +1. ? **Container Running?** + ```bash + docker ps | grep TradingBot + # Deve mostrare: Up X minutes (healthy) + ``` + +2. ? **Porta Corretta?** + ```bash + docker port TradingBot + # Output: 8080/tcp -> 0.0.0.0:8080 + ``` + +3. ? **Health Check?** + ```bash + docker inspect TradingBot | grep -A5 Health + # Status deve essere "healthy" + ``` + +4. ? **Test Locale**: + ```bash + curl http://localhost:8080/ + # Deve restituire HTML + ``` + +5. ? **Check Logs**: + ```bash + docker logs TradingBot --tail 50 + # Cerca errori + ``` + +**Soluzioni Comuni**: + +#### Errore: "Cannot access WebUI" + +**Causa**: Porta host occupata o container non started + +**Fix**: +```bash +# 1. Verifica porta libera +netstat -tulpn | grep :8080 + +# 2. Se occupata, edit container e cambia porta +# Docker tab ? Edit ? Port 8080 ? 8081 ? Apply + +# 3. Restart container +docker restart TradingBot +``` + +#### Errore: "Connection refused" + +**Causa**: Container started ma app non ready + +**Fix**: +```bash +# Attendi 40 secondi (start period) +sleep 40 + +# Poi testa +curl http://192.168.30.23:8080/ +``` + +#### Errore: "Unhealthy" status + +**Causa**: Health check fallisce + +**Fix**: +```bash +# Check logs per errori app +docker logs TradingBot + +# Possibili cause: +# - Porta interna sbagliata in ASPNETCORE_URLS +# - App crashed al startup +# - Manca volume /app/data + +# Ricrea container: +docker stop TradingBot +docker rm TradingBot +# Reinstalla da template +``` + +### Container Non Si Avvia + +**Check logs**: +```bash +docker logs TradingBot +``` + +**Problemi comuni**: + +#### Porta occupata +``` +Error: address already in use +``` +**Fix**: Cambia **Host Port** in configurazione container (Edit ? Port Mappings) + +#### Pull failed +``` +Error: unauthorized: authentication required +``` +**Fix**: +```bash +docker login gitea.encke-hake.ts.net +# Inserisci credenziali +``` + +#### Image not found +``` +Error: manifest not found +``` +**Fix**: Verifica immagine esista su Gitea Packages: +``` +https://gitea.encke-hake.ts.net/Alby96/Encelado/-/packages +``` + +### Performance Issues + +**Check risorse**: +```bash +docker stats TradingBot +``` + +**Limiti raccomandati**: +- **CPU**: 1-2 cores +- **Memory**: 512MB - 1GB + +**Configura limiti** (Edit ? Extra Parameters): +``` +--cpus="1.5" --memory="768m" +``` + +--- + +## ?? CHECKLIST INSTALLAZIONE + +### Pre-Install +- [ ] Unraid 6.10+ installato +- [ ] Docker service attivo +- [ ] Porta 8080 (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 +- [ ] Volume AppData creato +- [ ] Container status: **running** + +### Post-Install +- [ ] Health check: **healthy** (dopo 40 sec) +- [ ] WebUI accessibile (http://IP:PORT) +- [ ] Dashboard carica correttamente +- [ ] Settings modificabili e salvabili +- [ ] Bot avviabile dalla UI + +--- + +## ?? 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) +? **Health monitoring** integrato +? **Logs accessibili** dalla UI + +--- + +## ?? WORKFLOW COMPLETO + +### Sviluppo (PC) +``` +1. ?? Visual Studio ? Codice +2. ?? Build ? Publish (Docker profile) +3. ? Automatico: Push Gitea Registry +4. ?? git push origin main +``` + +### Deploy (Unraid) +``` +1. ?? Docker tab ? TradingBot +2. ?? Stop +3. ?? Force Update (pull latest) +4. ?? Start +5. ? Done! (~ 1 minuto) +``` + +**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 + +# Health check +docker inspect TradingBot --format='{{.State.Health.Status}}' + +# Restart +docker restart TradingBot + +# Update +docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest + +# Remove (mantiene dati) +docker rm -f TradingBot +``` + +--- + +## ?? 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 +# Click WebUI icon or http://192.168.30.23:8080 +``` + +**?? TradingBot pronto su Unraid!** diff --git a/TradingBot/docker-compose.yml b/TradingBot/deployment/docker-compose.yml similarity index 100% rename from TradingBot/docker-compose.yml rename to TradingBot/deployment/docker-compose.yml diff --git a/TradingBot/deployment/unraid-template.xml b/TradingBot/deployment/unraid-template.xml new file mode 100644 index 0000000..c3be5c7 --- /dev/null +++ b/TradingBot/deployment/unraid-template.xml @@ -0,0 +1,38 @@ + + + TradingBot + gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest + https://gitea.encke-hake.ts.net + bridge + + sh + false + https://gitea.encke-hake.ts.net/Alby96/Encelado + https://gitea.encke-hake.ts.net/Alby96/Encelado + Automated Crypto Trading Bot con Blazor UI. Analisi tecnica, simulazione trading e gestione portfolio automatizzata. + Tools:Productivity Status:Stable + http://[IP]:[PORT:8080]/ + https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/deployment/unraid-template.xml + https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/png/dotnet.png + --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 + + + + Se trovi utile questo progetto, considera di supportare lo sviluppo! + + + + + + 8080 + + + /mnt/user/appdata/tradingbot + + + Production + + http://+:8080 + + Europe/Rome + diff --git a/TradingBot/docs/PROJECT_STRUCTURE.md b/TradingBot/docs/PROJECT_STRUCTURE.md new file mode 100644 index 0000000..f782713 --- /dev/null +++ b/TradingBot/docs/PROJECT_STRUCTURE.md @@ -0,0 +1,274 @@ +# ??? Project Structure - TradingBot + +Struttura organizzata del progetto TradingBot con separazione chiara tra codice, configurazione e deployment. + +--- + +## ?? Root Directory + +``` +TradingBot/ +??? ?? Components/ # Blazor Components +? ??? ?? Layout/ # Layout components +? ??? ?? Pages/ # Page components +? ??? ?? Shared/ # Shared components +??? ?? deployment/ # ?? Deployment resources +? ??? docker-compose.yml # Docker Compose configuration +? ??? unraid-template.xml # Unraid template +? ??? PUBLISHING_GUIDE.md # Publishing guide +? ??? UNRAID_INSTALL.md # Unraid installation guide +? ??? README.md # Deployment index +??? ?? Models/ # Data models +??? ?? Properties/ # Project properties +? ??? ?? PublishProfiles/ # Visual Studio publish profiles +? ? ??? Docker.pubxml # Docker publish profile +? ? ??? FolderProfile.pubxml # Folder publish profile +? ??? launchSettings.json # Launch configurations +??? ?? Services/ # Business logic services +??? ?? wwwroot/ # Static web assets +? ??? ?? css/ # Stylesheets +? ??? ?? lib/ # Client libraries +??? .dockerignore # Docker ignore patterns +??? .gitignore # Git ignore patterns +??? appsettings.json # Application settings +??? appsettings.Development.json # Development settings +??? Dockerfile # Docker multi-stage build +??? Program.cs # Application entry point +??? README.md # Project documentation +??? TradingBot.csproj # Project file with MSBuild targets +``` + +--- + +## ?? Key Directories + +### `/Components` + +Blazor Server components organizzati per funzionalit: + +- **Layout**: `MainLayout.razor`, `NavMenu.razor`, `ReconnectModal.razor` +- **Pages**: `Dashboard.razor`, `Market.razor`, `Portfolio.razor`, `Settings.razor`, `Strategies.razor` +- **Shared**: Componenti riutilizzabili + +### `/Services` + +Business logic e servizi core: + +- `TradingBotService.cs` - Core trading service +- `SimulatedMarketDataService.cs` - Market data provider +- `SimpleMovingAverageStrategy.cs` - Trading strategy +- `SettingsService.cs` - Settings persistence +- `TechnicalAnalysis.cs` - Technical indicators +- Interface definitions + +### `/Models` + +Data models e DTOs: + +- `Trade.cs` - Trade execution model +- `MarketPrice.cs` - Market data snapshot +- `TradingSignal.cs` - Strategy signal +- `PortfolioStatistics.cs` - Portfolio metrics +- `AssetConfiguration.cs` - Asset settings +- Enums (SignalType, TradeType, etc.) + +### `/deployment` ?? + +**Nuova cartella organizzata** con tutti i file di deployment: + +#### Guide +- `PUBLISHING_GUIDE.md` - Come pubblicare da Visual Studio +- `UNRAID_INSTALL.md` - Installazione su Unraid +- `README.md` - Indice deployment + +#### Configuration +- `docker-compose.yml` - Docker Compose setup +- `unraid-template.xml` - Unraid 1-click install template + +### `/Properties` + +Visual Studio configuration: + +#### PublishProfiles/ +- `Docker.pubxml` - Docker container publish profile +- `FolderProfile.pubxml` - Folder-based publish profile + +#### Other +- `launchSettings.json` - Debug/run configurations (HTTP, HTTPS, Docker) + +### `/wwwroot` + +Static web assets: + +- `/css` - Custom stylesheets +- `/lib` - Client libraries (Bootstrap, etc.) +- Static files (favicon, etc.) + +--- + +## ?? Configuration Files + +### Root Level + +| File | Purpose | +|------|---------| +| `TradingBot.csproj` | Project file with MSBuild post-build targets | +| `Dockerfile` | Multi-stage Docker build configuration | +| `Program.cs` | Application startup and service registration | +| `appsettings.json` | Production configuration | +| `appsettings.Development.json` | Development overrides | +| `.dockerignore` | Files excluded from Docker build | +| `.gitignore` | Files excluded from Git | +| `README.md` | Main project documentation | + +--- + +## ?? Deployment Flow + +``` +Source Code (/) ? Build ? Docker Image ? Gitea Registry ? Unraid + ? + Post-Build MSBuild Target + (TradingBot.csproj) +``` + +### Files Involved + +1. **`TradingBot.csproj`** + - Contains `PushToGiteaRegistry` MSBuild target + - Hooks into `AfterTargets="DockerBuildImage"` + - Automatically tags and pushes to Gitea + +2. **`Properties/PublishProfiles/Docker.pubxml`** + - Visual Studio publish profile + - Triggers Docker build + - Integrated with MSBuild post-build + +3. **`Dockerfile`** + - Multi-stage build (build ? publish ? final) + - Optimized for .NET 10 and Blazor Server + - Creates minimal production image + +4. **`deployment/docker-compose.yml`** + - Production deployment configuration + - Uses image from Gitea Registry + - Health checks and resource limits + +5. **`deployment/unraid-template.xml`** + - Unraid Docker Manager template + - 1-click installation + - Pre-configured settings + +--- + +## ?? Documentation Structure + +``` +/ +??? README.md # Main project docs +??? deployment/ + ??? README.md # Deployment index + ??? PUBLISHING_GUIDE.md # Publishing workflow + ??? UNRAID_INSTALL.md # Unraid installation +``` + +### Reading Order + +1. **[/README.md](../README.md)** - Start here for project overview +2. **[/deployment/PUBLISHING_GUIDE.md](../deployment/PUBLISHING_GUIDE.md)** - Learn how to publish +3. **[/deployment/UNRAID_INSTALL.md](../deployment/UNRAID_INSTALL.md)** - Deploy to Unraid + +--- + +## ?? Development Workflow + +### Local Development + +``` +1. Open solution in Visual Studio +2. F5 to run (uses launchSettings.json ? "TradingBot" profile) +3. Edit code with Hot Reload enabled +4. Test changes at http://localhost:5243 +``` + +### Docker Local Testing + +``` +1. Switch to "Docker" profile in toolbar dropdown +2. F5 to run in container +3. Test changes at http://localhost:8080 +4. Debug with breakpoints (works in container!) +``` + +### Publishing + +``` +1. Build ? Configuration Manager ? Release +2. Build ? Publish TradingBot +3. Select "Docker" profile +4. Click "Publish" +5. MSBuild post-build automatically pushes to Gitea +``` + +--- + +## ?? Sensitive Files (Not in Git) + +These files are in `.gitignore`: + +- `obj/` - Build intermediate files +- `bin/` - Build output +- `*.user` - User-specific VS settings +- `data/` - Runtime data (settings, trades) +- `.vs/` - Visual Studio cache + +--- + +## ? Organization Benefits + +### Before + +``` +TradingBot/ +??? build-push-dockerhub.sh ? Script esterno +??? push-to-gitea.ps1 ? Script esterno +??? publish-all.ps1 ? Script esterno +??? full-workflow.bat ? Script esterno +??? docker-compose.yml ? Disordinato in root +??? unraid-template.xml ? Disordinato in root +??? ... (altri file misti) +``` + +### After ? + +``` +TradingBot/ +??? deployment/ ? Tutto organizzato +? ??? docker-compose.yml ? Deployment configs +? ??? unraid-template.xml ? Templates +? ??? PUBLISHING_GUIDE.md ? Documentation +? ??? UNRAID_INSTALL.md ? Documentation +? ??? README.md ? Index +??? TradingBot.csproj ? Post-build integrato +??? (codice sorgente organizzato) ? Struttura chiara +``` + +**Vantaggi**: +- ? **Zero script esterni** - Tutto in MSBuild +- ? **Organizzazione chiara** - Deployment separato +- ? **Facile navigazione** - Struttura logica +- ? **Manutenibilit** - File raggruppati per scopo +- ? **Visual Studio friendly** - Tutto integrato nell'IDE + +--- + +## ?? Summary + +**Struttura pulita e professionale con:** +- ?? Codice organizzato per funzionalit +- ?? Deployment resources in cartella dedicata +- ?? Documentazione completa e accessibile +- ?? MSBuild integration per publishing automatico +- ? Zero dipendenze da script esterni + +**Tutto gestibile da Visual Studio!** ?? diff --git a/TradingBot/docs/deployment/UNRAID_NATIVE_INSTALL.md b/TradingBot/docs/deployment/UNRAID_NATIVE_INSTALL.md deleted file mode 100644 index abe1968..0000000 --- a/TradingBot/docs/deployment/UNRAID_NATIVE_INSTALL.md +++ /dev/null @@ -1,427 +0,0 @@ -# ?? 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/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 (opzionale): - - **Port**: `8080` (o cambia se occupata) - - **Data Path**: `/mnt/user/appdata/tradingbot/data` -5. Click **Apply** - -Unraid far: -- ? Pull immagine da Gitea Registry -- ? Crea container -- ? Crea volume per dati -- ? Start automatico - -### Step 3: Accedi WebUI - -``` -http://192.168.30.23:8080 -``` - -Dovresti vedere la Dashboard TradingBot! ?? - ---- - -## ?? 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 - -Click **Add another Path, Port, Variable, Label or Device** - -**Config Type**: `Port` -- **Name**: WebUI -- **Container Port**: `8080` -- **Host Port**: `8080` (o altra porta libera) -- **Connection Type**: `TCP` - -### Step 4: Volume Mapping - -Click **Add another Path, Port, Variable, Label or Device** - -**Config Type**: `Path` -- **Name**: AppData -- **Container Path**: `/app/data` -- **Host Path**: `/mnt/user/appdata/tradingbot/data` -- **Access Mode**: `Read/Write` - -### Step 5: Environment Variables - -**ASPNETCORE_ENVIRONMENT**: -- **Name**: `ASPNETCORE_ENVIRONMENT` -- **Value**: `Production` - -**ASPNETCORE_URLS**: -- **Name**: `ASPNETCORE_URLS` -- **Value**: `http://+:8080` - -### Step 6: Health Check (Opzionale) - -**Extra Parameters**: -``` ---health-cmd="wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1" --health-interval=30s --health-timeout=3s --health-retries=3 --health-start-period=10s -``` - -### Step 7: Apply - -Click **Apply** in fondo alla pagina. - ---- - -## ?? AGGIORNAMENTO CONTAINER - -### Via Unraid Docker Tab - -1. **Docker** ? Trova **TradingBot** -2. Click **icona ferma** (stop container) -3. Click **Force Update** (icona update) -4. Click **icona play** (start container) - -Unraid far: -- ? Pull ultima immagine da Gitea -- ? Ricrea container -- ? Mantiene dati (volume persistente) - -### 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 - -# Stop container -docker stop TradingBot - -# Remove container -docker rm TradingBot - -# Pull latest image -docker pull gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest - -# Recreate container (Unraid fa automaticamente) -# O riavvia manualmente dalla WebUI - -echo "Update completato! Riavvia TradingBot dalla Docker tab." -``` - -Schedula: Ogni settimana o manualmente. - ---- - -## ?? GESTIONE CONTAINER - -### Start/Stop/Restart - -**Docker tab** ? Container **TradingBot**: -- ?? **Play**: Start -- ?? **Pause**: Pausa (mantiene in memoria) -- ?? **Stop**: Ferma -- ?? **Restart**: Riavvia - -### View Logs - -**Docker tab** ? Container **TradingBot** ? Click **icona logs** - -O via terminal: -```bash -docker logs TradingBot -f -``` - -### Console Access - -**Docker tab** ? Container **TradingBot** ? Click **icona console** - -O via terminal: -```bash -docker exec -it TradingBot bash -``` - -### Statistics - -**Docker tab** ? Container **TradingBot** ? Click **icona stats** - -Mostra: -- CPU usage -- Memory usage -- Network I/O -- Block I/O - ---- - -## ?? ACCESSO WEBUI - -### Locale (Unraid LAN) - -``` -http://192.168.30.23:8080 -``` - -### Via Tailscale - -``` -http://unraid.encke-hake.ts.net:8080 -``` - -(Se hai configurato Tailscale su Unraid) - -### Reverse Proxy (Opzionale) - -Se vuoi accesso HTTPS: - -**Nginx Proxy Manager** (tramite Unraid): -``` -https://tradingbot.encke-hake.ts.net ? http://192.168.30.23:8080 -``` - ---- - -## ?? SICUREZZA - -### Best Practices - -? **Porta non esposta pubblicamente** (solo LAN o Tailscale) -? **Volume dati protetto** (`/mnt/user/appdata/tradingbot/`) -? **Registry privato** (Gitea richiede login) -? **Certificati validi** (Tailscale) -? **User non-root** (gi configurato nel Dockerfile) - -### Backup Dati - -```bash -# Backup manuale -tar -czf tradingbot-backup-$(date +%Y%m%d).tar.gz \ - /mnt/user/appdata/tradingbot/data - -# Restore -tar -xzf tradingbot-backup-20241212.tar.gz -C / -``` - -O usa **CA Backup / Restore Appdata** plugin. - ---- - -## ?? TROUBLESHOOTING - -### Container Non Si Avvia - -**Check logs**: -```bash -docker logs TradingBot -``` - -**Problemi comuni**: - -#### Porta occupata -``` -Error: address already in use -``` -**Fix**: Cambia porta in configurazione container - -#### Pull failed -``` -Error: unauthorized: authentication required -``` -**Fix**: `docker login gitea.encke-hake.ts.net` - -#### Image not found -``` -Error: manifest not found -``` -**Fix**: Verifica che l'immagine esista su Gitea Packages - -### WebUI Non Accessibile - -**Checklist**: -- [ ] Container status: **running** (verde) -- [ ] Health check: **healthy** -- [ ] Porta corretta (8080 o custom) -- [ ] Firewall Unraid non blocca -- [ ] Browser su `http://` non `https://` - -**Test**: -```bash -curl http://localhost:8080/health -# Deve rispondere: Healthy -``` - -### Performance Issues - -**Check risorse**: -```bash -docker stats TradingBot -``` - -**Limiti raccomandati**: -- **CPU**: 2 cores max, 0.5 reserved -- **Memory**: 1GB max, 256MB reserved - -Configura in **Extra Parameters**: -``` ---cpus="2.0" --memory="1g" --memory-reservation="256m" -``` - ---- - -## ?? CHECKLIST INSTALLAZIONE - -### Pre-Install -- [ ] Unraid aggiornato -- [ ] Docker service attivo -- [ ] Porta 8080 disponibile -- [ ] `docker login gitea.encke-hake.ts.net` successful - -### Install -- [ ] Template XML copiato (Metodo 1) -- [ ] O container configurato manualmente (Metodo 2) -- [ ] Container creato -- [ ] Volume dati creato - -### Post-Install -- [ ] Container status: running -- [ ] Health check: healthy -- [ ] WebUI accessibile -- [ ] Settings configurati nell'app - ---- - -## ?? 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** (1 click) -? **Template riutilizzabile** (facile reinstall) - ---- - -## ?? WORKFLOW COMPLETO - -### Sviluppo (PC) -``` -1. Codice in Visual Studio -2. Build ? Publish (Release) -3. ? Automatico: Push Gitea Registry -4. Commit: git push -``` - -### Deploy (Unraid) -``` -1. Docker tab ? TradingBot ? Stop -2. Force Update -3. Start -4. Done! ? -``` - -**Tempo totale**: ~2 minuti - ---- - -## ?? RISORSE - -### Template XML -``` -https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml -``` - -### Repository -``` -https://gitea.encke-hake.ts.net/Alby96/Encelado -``` - -### Docker Image -``` -gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest -``` - -### Support -``` -https://gitea.encke-hake.ts.net/Alby96/Encelado/issues -``` - ---- - -**?? TradingBot pronto per Unraid senza Portainer!** - -**Quick Start**: -```bash -# 1. Login -docker login gitea.encke-hake.ts.net - -# 2. Install Template -wget -O /boot/config/plugins/dockerMan/templates-user/TradingBot.xml \ - https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml - -# 3. Docker tab ? Add Container ? TradingBot ? Apply -``` - -**Access**: `http://192.168.30.23:8080` ?? diff --git a/TradingBot/unraid-template.xml b/TradingBot/unraid-template.xml deleted file mode 100644 index e449ca2..0000000 --- a/TradingBot/unraid-template.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - TradingBot - gitea.encke-hake.ts.net/alby96/encelado/tradingbot:latest - https://gitea.encke-hake.ts.net - bridge - - sh - false - https://gitea.encke-hake.ts.net/Alby96/Encelado - https://gitea.encke-hake.ts.net/Alby96/Encelado - Automated Crypto Trading Bot con Blazor UI. Analisi tecnica, simulazione trading e gestione portfolio automatizzata. - Tools:Productivity Status:Stable - http://[IP]:[PORT:8080] - https://gitea.encke-hake.ts.net/Alby96/Encelado/raw/branch/main/TradingBot/unraid-template.xml - https://raw.githubusercontent.com/docker-library/docs/master/dotnet/logo.png - --health-cmd="wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1" --health-interval=30s --health-timeout=3s --health-retries=3 --health-start-period=10s - - - - - - - 8080 - /mnt/user/appdata/tradingbot/data - Production - http://+:8080 - true -