Build the Panoramica and Diario e sistema screens as in the mockups (refs #51)
Panoramica now follows mockup 01. Below "Finora" and "Adesso e dopo" it shows: - the two account cards with the invested/cash bar and a 30-day trend; - the four risk limits; - the open positions by value; - the strategies; - the news, learning and system tiles. On the phone it follows mockup 09: Conti as a list, four positions with "Vedi le altre", and two limits. Outside the demo, news and learning say they are not active yet (Phases 7 and 8). The next moves are the scheduler's moves only, no longer every interval job. Diario e sistema follows mockup 08: - the diary grouped by day, with search and filter chips (plain links, no JavaScript) and older days on request; - how each component is doing; - the scheduled jobs; - the host's processor, memory and disk; - the technical logs as a zip, for signed-in users only. In demo mode the screens show the values of appendix F.10. Tests cover the demo figures, the filters and search, and the logs download. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
84c540786c
commit
e96ca70a1a
11 files changed
+1666
-85
No files matched your search
@@ -5,86 +5,157 @@
|
||||
|
||||
<PageTitle>Diario e sistema · Anubis</PageTitle>
|
||||
|
||||
<div class="columns">
|
||||
<section class="panel">
|
||||
<h2>Diario</h2>
|
||||
@if (_entries.Count == 0)
|
||||
@{
|
||||
var d = _diary;
|
||||
var s = _system;
|
||||
}
|
||||
<div class="journal-columns">
|
||||
<section class="panel journal" aria-labelledby="diario">
|
||||
<div class="journal-head">
|
||||
<h2 id="diario">Diario</h2>
|
||||
<form class="search journal-search" method="get" action="/diario" role="search">
|
||||
@if (d.Filter != "tutto")
|
||||
{
|
||||
<input type="hidden" name="tipo" value="@d.Filter" />
|
||||
}
|
||||
<Icon Name="search" Size="16" />
|
||||
<label class="visually-hidden" for="cerca-diario">Cerca nel diario</label>
|
||||
<input id="cerca-diario" type="search" name="cerca" value="@d.Search" placeholder="Cerca nel diario" maxlength="100" />
|
||||
</form>
|
||||
</div>
|
||||
<nav class="chips" aria-label="Tipo di voce">
|
||||
@foreach (var (key, label, _) in DiaryView.Filters)
|
||||
{
|
||||
<a href="@d.Link(filter: key, range: DiaryView.DefaultRange)" class="chip @(key == d.Filter ? "on" : null)" aria-current="@(key == d.Filter ? "true" : null)">@label</a>
|
||||
}
|
||||
</nav>
|
||||
@if (d.Search is { } search)
|
||||
{
|
||||
<p class="note">Ancora nessuna voce.</p>
|
||||
<p class="note journal-found">
|
||||
@(d.Days.Sum(x => x.Entries.Count) switch { 0 => "Nessuna voce", 1 => "Una voce", var n => $"{n} voci" }) con «@search»@(d.Truncated ? $", le {DiaryView.MaxSearchResults} più recenti" : "").
|
||||
<a href="@(new DiaryView([], d.Filter, null, DiaryView.DefaultRange, false, false).Link())">Togli la ricerca</a>
|
||||
</p>
|
||||
}
|
||||
else
|
||||
@if (d.IsEmpty && d.Search is null)
|
||||
{
|
||||
<div class="table-wrap">
|
||||
<table class="table">
|
||||
<thead><tr><th scope="col">Quando</th><th scope="col">Tipo</th><th scope="col">Voce</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var e in _entries)
|
||||
{
|
||||
<tr><td class="nowrap">@Format.ShortDate(e.At, Shell.Now, Shell.Zone)</td><td>@e.Kind</td><td>@e.Text</td></tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="note">@(d.Filter == "tutto" ? "Ancora nessuna voce. Qui il bot scrive ogni decisione, ordine e controllo, in parole semplici, appena succede." : "Nessuna voce di questo tipo finora.")</p>
|
||||
}
|
||||
@foreach (var day in d.Days)
|
||||
{
|
||||
<h3 class="journal-day">@day.Heading</h3>
|
||||
<ol class="journal-list">
|
||||
@foreach (var e in day.Entries)
|
||||
{
|
||||
<li class="@(e.Attention ? "attention-entry" : null)">
|
||||
<time datetime="@e.At.ToString("o", CultureInfo.InvariantCulture)">@TimeZoneInfo.ConvertTime(e.At, Shell.Zone).ToString("HH:mm", CultureInfo.InvariantCulture)</time>
|
||||
<Icon Name="@e.Icon" Size="18" Class="journal-icon" />
|
||||
<div class="journal-text">
|
||||
<p>@if (e.Lead is { } lead) {<strong>@lead</strong>}@foreach (var piece in e.Main) {if (piece.Class is { } css) {<strong class="@css">@piece.Text</strong>} else {@piece.Text}}</p>
|
||||
@if (e.Rest is { } rest)
|
||||
{
|
||||
<p class="journal-rest">@rest</p>
|
||||
}
|
||||
@if (e.Trade is { } trade)
|
||||
{
|
||||
<a href="/operazioni?cerca=@Uri.EscapeDataString(trade)">Perché l'ho comprata e venduta</a>
|
||||
}
|
||||
</div>
|
||||
<span class="journal-kind">@e.Kind</span>
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
@if (d.HasOlder)
|
||||
{
|
||||
<div class="journal-more"><a class="btn" href="@d.Link(range: d.Range + 7)">Mostra i giorni precedenti</a></div>
|
||||
}
|
||||
</section>
|
||||
<section class="panel">
|
||||
<h2>Sistema</h2>
|
||||
<dl class="facts">
|
||||
<dt>Versione</dt><dd>@AnubisInfo.Version</dd>
|
||||
<dt>Piattaforma</dt><dd>@(Host.Config.Platform == PlatformKind.Docker ? "Docker" : "Desktop")</dd>
|
||||
<dt>Database</dt><dd>@(Host.Config.Db?.Engine == DbEngine.Postgres ? "PostgreSQL" : "SQLite") · risponde</dd>
|
||||
<dt>In funzione da</dt><dd>@Format.Ago(Shell.Now - _since).Replace(" fa", "", StringComparison.Ordinal)</dd>
|
||||
</dl>
|
||||
<h3 class="list-title">Lavori in programma</h3>
|
||||
<ul class="moves">
|
||||
@foreach (var job in _upcoming)
|
||||
{
|
||||
<li><span class="move-time">@Format.ShortDate(job.DueUtc, Shell.Now, Shell.Zone)</span><span>@job.Description</span></li>
|
||||
}
|
||||
</ul>
|
||||
@if (_jobs.Count > 0)
|
||||
{
|
||||
<h3 class="list-title">Ultimi lavori</h3>
|
||||
<ul class="moves moves-past">
|
||||
@foreach (var job in _jobs)
|
||||
|
||||
<div class="journal-side">
|
||||
<section class="panel" aria-labelledby="sistema">
|
||||
<div class="panel-head">
|
||||
<h2 id="sistema">Come sta il sistema</h2>
|
||||
<span class="status-pill @(s.AllWell ? "gain" : "attention")"><Icon Name="@(s.AllWell ? "check" : "alert")" Size="16" />@(s.AllWell ? "Tutto regolare" : "Qualcosa da controllare")</span>
|
||||
</div>
|
||||
<ul class="system-parts">
|
||||
@foreach (var part in s.Parts)
|
||||
{
|
||||
<li><span class="move-time">@(job.Finished is { } f ? Format.ShortDate(f, Shell.Now, Shell.Zone) : "—")</span><span>@job.Description: @Outcome(job.Outcome)</span></li>
|
||||
<li class="@PartClass(part.State)">
|
||||
<Icon Name="@PartIcon(part.State)" Size="16" />
|
||||
<span><strong>@part.Name</strong><span>@part.Detail</span></span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section class="panel" aria-labelledby="lavori">
|
||||
<h2 id="lavori">Lavori in programma</h2>
|
||||
@if (s.Jobs.Count == 0)
|
||||
{
|
||||
<p class="note">Nessun lavoro in programma: il pianificatore parte con il motore.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="moves job-list">
|
||||
@foreach (var job in s.Jobs)
|
||||
{
|
||||
<li><span class="move-time">@job.Time</span><span>@job.Text</span></li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="plain host" aria-labelledby="computer">
|
||||
<h2 id="computer">Il computer che lo ospita</h2>
|
||||
@foreach (var r in s.Resources)
|
||||
{
|
||||
<div class="limit">
|
||||
<div class="limit-line"><span>@r.Label</span><span><strong>@r.Value</strong>@if (r.Of is { } of) {<span class="muted"> su @of</span>}</span></div>
|
||||
<span class="usage @(r.Share >= 0.85m ? "high" : null)"><span style="width: @Css(r.Share * 100m)%"></span></span>
|
||||
</div>
|
||||
}
|
||||
<p class="note">@s.Running</p>
|
||||
<a class="btn" href="/api/registri.zip" download><Icon Name="download" Size="18" />Scarica i registri tecnici</a>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<(DateTimeOffset At, string Kind, string Text)> _entries = [];
|
||||
private List<(string Description, DateTimeOffset? Finished, string? Outcome)> _jobs = [];
|
||||
private IReadOnlyList<UpcomingRun> _upcoming = [];
|
||||
private DateTimeOffset _since;
|
||||
private DiaryView _diary = null!;
|
||||
private SystemView _system = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "tipo")]
|
||||
public string? Tipo { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "cerca")]
|
||||
public string? Cerca { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "giorni")]
|
||||
public string? Giorni { get; set; }
|
||||
|
||||
protected override async Task LoadAsync()
|
||||
{
|
||||
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
|
||||
var services = Host.Services!;
|
||||
(_entries, _jobs) = await services.Db.ReadAsync(async s =>
|
||||
{
|
||||
var entries = await s.QueryAsync("SELECT occurred_at, kind, message FROM journal ORDER BY occurred_at DESC LIMIT 200",
|
||||
r => (r.Moment("occurred_at"), r.Text("kind"), r.Text("message")));
|
||||
var jobs = await s.QueryAsync("SELECT description, last_finished_at, last_outcome FROM jobs ORDER BY last_finished_at DESC",
|
||||
r => (r.Text("description"), r.MomentOrNull("last_finished_at"), r.TextOrNull("last_outcome")));
|
||||
return (entries, jobs);
|
||||
}, ct);
|
||||
_upcoming = services.Scheduler.Upcoming(10);
|
||||
_since = Host.Status.Since;
|
||||
_diary = await DiaryView.LoadAsync(Host.Services!.Db, Tipo, Cerca, Giorni, Shell.Now, Shell.Zone, ct);
|
||||
_system = await SystemView.LoadAsync(Host, Shell, ct);
|
||||
}
|
||||
|
||||
private static string Outcome(string? outcome) => outcome switch
|
||||
private static string PartClass(PartState state) => state switch
|
||||
{
|
||||
"succeeded" => "fatto",
|
||||
"failed" => "non riuscito",
|
||||
"skipped" => "saltato, orario superato",
|
||||
_ => "in attesa",
|
||||
PartState.Ok => "ok",
|
||||
PartState.Warn => "warn",
|
||||
_ => "off",
|
||||
};
|
||||
|
||||
private static string PartIcon(PartState state) => state switch
|
||||
{
|
||||
PartState.Ok => "tick",
|
||||
PartState.Warn => "alert",
|
||||
_ => "clock",
|
||||
};
|
||||
|
||||
private static string Css(decimal value) => Math.Round(value, 3).ToString("0.###", CultureInfo.InvariantCulture);
|
||||
}
|
||||
@@ -2,12 +2,20 @@
|
||||
@page "/"
|
||||
@inject AnubisHost Host
|
||||
@inject ShellData Shell
|
||||
@using Anubis.Trading
|
||||
@using Anubis.Data
|
||||
|
||||
<PageTitle>Panoramica · Anubis</PageTitle>
|
||||
|
||||
@{
|
||||
var o = _overview;
|
||||
var p = _panorama;
|
||||
var c = _currency;
|
||||
var moves = p.DemoMoves ?? o.Next;
|
||||
var last = p.DemoLast ?? o.Last;
|
||||
// On the phone only the first two moves of the bot, without the calendar's events (SPEC 13.4).
|
||||
var phoneMoves = moves.Select((m, i) => (m, i)).Where(x => !x.m.Calendar).Take(2).Select(x => x.i).ToHashSet();
|
||||
var v = p.Accounts;
|
||||
}
|
||||
@if (!o.CapitalSet && !Shell.IsDemo)
|
||||
{
|
||||
@@ -42,7 +50,9 @@
|
||||
<span class="big-number">@Shell.Money(o.Result.Amount, c, withSign: true)</span>
|
||||
<span class="badge @(gain ? "badge-gain" : "badge-loss")"><Arrow Up="gain" />@Format.Percent(o.Result.Percent, 2, withSign: true)</span>
|
||||
</div>
|
||||
<p class="note">Dal @Format.LongDate(o.From), partendo da @Shell.Money(o.FromEquity, c). Commissioni già tolte.</p>
|
||||
var from = Format.LongDate(o.From);
|
||||
var year = from.LastIndexOf(' ');
|
||||
<p class="note">Dal @from[..year]<span class="desk-only">@from[year..]</span>, partendo da @Shell.Money(o.FromEquity, c).<span class="desk-only"> Commissioni già tolte.</span></p>
|
||||
<div class="cells">
|
||||
@foreach (var (cell, i) in o.Cells.Select((x, i) => (x, i)))
|
||||
{
|
||||
@@ -63,47 +73,321 @@
|
||||
<h2><Icon Name="next" Size="18" />Adesso e dopo</h2>
|
||||
@if (_runningDays is { } days)
|
||||
{
|
||||
<span class="note">Attivo da @days giorni senza interruzioni</span>
|
||||
<span class="note desk-only">Attivo da @days giorni senza interruzioni</span>
|
||||
}
|
||||
</div>
|
||||
<p class="statement">@Statement(o)</p>
|
||||
<h3 class="list-title">Prossime mosse</h3>
|
||||
@if (o.Next.Count == 0)
|
||||
@if (p.NextDecision is { } decision)
|
||||
{
|
||||
<p class="note">Niente in programma.</p>
|
||||
<p class="next-decision desk-only"><Icon Name="clock" Size="16" />@decision</p>
|
||||
}
|
||||
<h3 class="list-title desk-only">Prossime mosse</h3>
|
||||
@if (moves.Count == 0)
|
||||
{
|
||||
<p class="note">Niente in programma: le mosse compaiono quando il motore di trading lavora con almeno una strategia.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="moves">
|
||||
@foreach (var move in o.Next)
|
||||
@for (var i = 0; i < moves.Count; i++)
|
||||
{
|
||||
<li><span class="move-time">@move.Time</span><span>@move.Text</span></li>
|
||||
var move = moves[i];
|
||||
<li class="@(phoneMoves.Contains(i) ? null : "desk-only")"><span class="move-time">@move.Time</span><span>@move.Text@if (move.Where is { } where) {<span class="muted desk-only"> (@where)</span>}</span></li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<h3 class="list-title">Ultime azioni</h3>
|
||||
@if (o.Last.Count == 0)
|
||||
<div class="desk-only">
|
||||
<h3 class="list-title">Ultime azioni</h3>
|
||||
@if (last.Count == 0)
|
||||
{
|
||||
<p class="note">Ancora nessuna voce nel diario.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="moves moves-past">
|
||||
@foreach (var action in last)
|
||||
{
|
||||
<li><span class="move-time">@action.When</span><span>@action.Text</span></li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<a class="more" href="/diario">Apri il diario completo</a>
|
||||
</div>
|
||||
<a class="more phone-only" href="/diario">Tutte le mosse e il diario</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@* Accounts and the four limits (mockup 01); on the phone a compact list of the accounts (mockup 09). *@
|
||||
<div class="overview-row">
|
||||
@if (!v.HasAccounts)
|
||||
{
|
||||
<section class="panel overview-empty desk-only">
|
||||
<p class="empty-title">Nessun conto ancora.</p>
|
||||
<p>Il bot crea da solo i due simulatori interni, OKX e Alpaca, al primo avvio del motore di trading. I conti di prova compaiono quando ne aggiungi le chiavi in <a href="/impostazioni#conti">Impostazioni</a>.</p>
|
||||
</section>
|
||||
}
|
||||
@foreach (var a in v.Accounts)
|
||||
{
|
||||
var up = a.Result >= 0;
|
||||
var held = v.Positions.Where(x => x.AccountId == a.Id).ToList();
|
||||
var slices = held.GroupBy(x => x.Strategy).OrderBy(g => StrategyNames.Base.ToList().FindIndex(b => b.Name == g.Key))
|
||||
.Select(g => (Strategy: g.Key, Eur: g.Sum(x => x.ValueEur))).ToList();
|
||||
var shares = Format.Shares([.. slices.Select(s => s.Eur), a.Eur(a.Cash)]);
|
||||
var trend = p.Trends.GetValueOrDefault(a.Id);
|
||||
<section class="panel overview-account desk-only" aria-label="@a.Name">
|
||||
<div class="account-head">
|
||||
<h2>@a.Name <span class="tag">@a.Kind</span></h2>
|
||||
<span class="link-state @(Down(a) ? "down" : null)"><span class="dot"></span>@(Down(a) ? "Non risponde" : "Connesso")</span>
|
||||
</div>
|
||||
<div class="account-value">
|
||||
<span class="account-equity">@Shell.Money(a.Eur(a.Equity), c)</span>
|
||||
<span class="cell-change @(up ? "gain" : "loss")"><Arrow Up="up" />@Shell.Money(a.Eur(a.Result), c, withSign: true) (@Format.Percent(a.Percent, 2, withSign: true))</span>
|
||||
</div>
|
||||
<div class="split-bar thin" role="img" aria-label="Investito @Shell.Money(a.InvestedEur, c), liquidità @Shell.Money(a.Eur(a.Cash), c)">
|
||||
@for (var i = 0; i < slices.Count; i++)
|
||||
{
|
||||
if (shares[i] > 0)
|
||||
{
|
||||
<span style="width: @Css(shares[i])%; background: var(--s-@slices[i].Strategy.Replace('_', '-'))"></span>
|
||||
}
|
||||
}
|
||||
@if (shares[^1] > 0)
|
||||
{
|
||||
<span style="width: @Css(shares[^1])%; background: var(--cash)"></span>
|
||||
}
|
||||
</div>
|
||||
<div class="split-key">
|
||||
<span>@foreach (var s in slices) {<span class="swatch" style="background: var(--s-@s.Strategy.Replace('_', '-'))"></span>}Investito <strong>@Shell.Money(a.InvestedEur, c)</strong></span>
|
||||
<span><span class="swatch" style="background: var(--cash)"></span>Liquidità <strong>@Shell.Money(a.Eur(a.Cash), c)</strong></span>
|
||||
</div>
|
||||
<div class="month">
|
||||
<div>
|
||||
<span class="cell-label">Ultimi 30 giorni</span>
|
||||
<strong>@(trend is null ? "—" : Shell.Money(trend.Month, c, withSign: true))</strong>
|
||||
</div>
|
||||
@if (trend is { Points.Count: > 1 } t)
|
||||
{
|
||||
<svg class="spark-mini" viewBox="0 0 120 36" role="img" aria-label="Andamento degli ultimi 30 giorni">
|
||||
<polyline points="@Spark(t.Points)" />
|
||||
<circle cx="@SparkEnd(t.Points).X" cy="@SparkEnd(t.Points).Y" r="2.5" />
|
||||
</svg>
|
||||
}
|
||||
</div>
|
||||
<p class="note">@AccountNote(a, held)</p>
|
||||
</section>
|
||||
}
|
||||
<section class="panel overview-risk desk-only" aria-labelledby="rischio-sintesi">
|
||||
<div class="panel-head">
|
||||
<h2 id="rischio-sintesi">Rischio</h2>
|
||||
<span class="status-pill @(p.LimitsKept ? "gain" : "attention")"><Icon Name="@(p.LimitsKept ? "check" : "alert")" Size="16" />@(p.LimitsKept ? "Tutti i limiti rispettati" : "Un limite chiede attenzione")</span>
|
||||
</div>
|
||||
<div class="limit-list">
|
||||
@foreach (var l in p.Limits)
|
||||
{
|
||||
<div class="limit">
|
||||
<div class="limit-line"><span>@l.Label</span><span><strong>@l.Value</strong> <span class="muted">su @l.Threshold</span></span></div>
|
||||
<span class="usage @(l.Worst is null ? null : "notched") @(l.Share >= 0.8m ? "high" : null)">
|
||||
<span style="width: @Css(l.Share * 100m)%"></span>
|
||||
@if (l.Worst is { } w)
|
||||
{
|
||||
<i class="notch" style="left: @Css(w * 100m)%"></i>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (p.Limits[1].Worst is not null && _worst is { } worst)
|
||||
{
|
||||
<p class="note">Ancora nessuna voce nel diario.</p>
|
||||
<p class="note">La tacca segna il calo peggiore finora: @Format.Percent(worst * 100m, 2).</p>
|
||||
}
|
||||
<a class="more" href="/rischio">Vedi tutti i limiti</a>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@if (v.HasAccounts)
|
||||
{
|
||||
<section class="panel phone-only" aria-labelledby="conti-telefono">
|
||||
<h2 id="conti-telefono">Conti</h2>
|
||||
<ul class="phone-list">
|
||||
@foreach (var a in v.Accounts)
|
||||
{
|
||||
var up = a.Result >= 0;
|
||||
<li>
|
||||
<span><strong>@a.Name</strong><span class="sub"><span class="dot @(Down(a) ? "down" : null)"></span>@a.Kind, @(Down(a) ? "non risponde" : "connesso")</span></span>
|
||||
<span class="num"><strong>@Shell.Money(a.Eur(a.Equity), c)</strong><span class="sub @(up ? "gain" : "loss")"><Arrow Up="up" /><strong>@Shell.Money(a.Eur(a.Result), c, withSign: true)</strong></span></span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
}
|
||||
|
||||
@* Positions by value and the strategies (mockup 01); on the phone the first four positions (mockup 09). *@
|
||||
<div class="overview-row overview-row-wide">
|
||||
<section class="panel overview-positions" aria-labelledby="posizioni-sintesi">
|
||||
<div class="panel-head">
|
||||
<h2 id="posizioni-sintesi">Posizioni aperte
|
||||
@if (v.Positions.Count > 0)
|
||||
{
|
||||
<span class="note desk-only">@v.Positions.Count, per @Shell.Money(v.InvestedEur, c). Risultato aperto @Shell.Money(v.OpenResultEur, c, withSign: true)</span>
|
||||
}
|
||||
</h2>
|
||||
@if (v.Positions.Count > 0)
|
||||
{
|
||||
<span class="note phone-only">@v.Positions.Count, risultato @Shell.Money(v.OpenResultEur, c, withSign: true)</span>
|
||||
}
|
||||
<a class="desk-only" href="/conti">Dettaglio</a>
|
||||
</div>
|
||||
@if (v.Positions.Count == 0)
|
||||
{
|
||||
<p class="note">Nessuna posizione aperta. Quando una strategia compra, qui vedi ogni posizione con il suo valore, il risultato e lo stop che la protegge.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="moves moves-past">
|
||||
@foreach (var action in o.Last)
|
||||
<div class="table-wrap desk-only">
|
||||
<table class="table positions">
|
||||
<thead>
|
||||
<tr><th scope="col">Strumento</th><th scope="col">Strategia</th><th scope="col" class="num">Valore</th><th scope="col" class="num">Risultato</th><th scope="col" class="num">Stop</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var x in v.Positions)
|
||||
{
|
||||
var gain = x.ResultEur >= 0;
|
||||
<tr>
|
||||
<th scope="row"><strong>@x.Symbol</strong> <span class="muted">@x.Name</span></th>
|
||||
<td class="nowrap"><span class="swatch round" style="background: var(--s-@x.Strategy.Replace('_', '-'))"></span>@StrategyNames.Label(x.Strategy)</td>
|
||||
<td class="num">@Shell.Money(x.ValueEur, c)</td>
|
||||
<td class="num nowrap @(gain ? "gain" : "loss")"><strong>@Shell.Money(x.ResultEur, c, withSign: true) (@Format.Percent(x.Percent, 2, withSign: true))</strong></td>
|
||||
<td class="num nowrap">@if (x.Stop is { } stop) {@Format.Money(stop, x.Currency, decimals: AccountsView.StopDecimals(stop))<span class="muted"> (@Format.Percent(x.Last == 0 ? 0 : (stop / x.Last - 1m) * 100m, 1))</span>} else {<span class="muted">nessuno</span>}</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<ul class="phone-list phone-only">
|
||||
@foreach (var x in v.Positions.Take(4))
|
||||
{
|
||||
<li><span class="move-time">@action.When</span><span>@action.Text</span></li>
|
||||
var gain = x.ResultEur >= 0;
|
||||
<li>
|
||||
<span><strong>@x.Symbol</strong><span class="sub"><span class="swatch round" style="background: var(--s-@x.Strategy.Replace('_', '-'))"></span>@StrategyNames.Label(x.Strategy)</span></span>
|
||||
<span class="num">@Shell.Money(x.ValueEur, c)<strong class="sub @(gain ? "gain" : "loss")">@Shell.Money(x.ResultEur, c, withSign: true)</strong></span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<a class="more" href="/diario">Tutto il diario</a>
|
||||
<a class="more phone-only" href="/conti">@(v.Positions.Count > 4 ? $"Vedi le altre {v.Positions.Count - 4}" : "Vedi i conti")</a>
|
||||
}
|
||||
</section>
|
||||
<section class="panel overview-strategies desk-only" aria-labelledby="strategie-sintesi">
|
||||
<div class="panel-head">
|
||||
<h2 id="strategie-sintesi">Strategie</h2>
|
||||
<a href="/strategie">Dettaglio</a>
|
||||
</div>
|
||||
@if (p.Strategies.Count == 0)
|
||||
{
|
||||
<p class="note">Le strategie compaiono quando parte il motore di trading.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="strategy-list">
|
||||
@foreach (var s in p.Strategies)
|
||||
{
|
||||
<li>
|
||||
<div class="strategy-line"><strong><span class="swatch round" style="background: @s.Color"></span>@s.Name</strong><strong>@Shell.Money(s.Result, c, withSign: true)</strong></div>
|
||||
<span class="strategy-bar"><span style="width: @Css(Math.Max(s.Bar * 100m, 2m))%; background: @s.Color"></span></span>
|
||||
<span class="note">@s.Stage</span>
|
||||
<span class="note">@s.Trades</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@if (!p.AnyLive)
|
||||
{
|
||||
<p class="info-note">Nessuna strategia usa soldi veri. Passano al conto reale solo dopo aver superato tutti i requisiti, e solo se lo confermi tu.</p>
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="panel phone-only" aria-labelledby="rischio-telefono">
|
||||
<div class="panel-head">
|
||||
<h2 id="rischio-telefono">Rischio</h2>
|
||||
<span class="status-pill @(p.LimitsKept ? "gain" : "attention")"><Icon Name="@(p.LimitsKept ? "check" : "alert")" Size="16" />@(p.LimitsKept ? "Limiti rispettati" : "Da controllare")</span>
|
||||
</div>
|
||||
<div class="limit-list">
|
||||
@foreach (var l in new[] { p.Limits[2], p.Limits[1] })
|
||||
{
|
||||
<div class="limit">
|
||||
<div class="limit-line"><span>@l.Label</span><span><strong>@l.Value</strong> <span class="muted">su @l.Threshold.Replace(",00%", "%", StringComparison.Ordinal)</span></span></div>
|
||||
<span class="usage @(l.Worst is null ? null : "notched")">
|
||||
<span style="width: @Css(l.Share * 100m)%"></span>
|
||||
@if (l.Worst is { } w)
|
||||
{
|
||||
<i class="notch" style="left: @Css(w * 100m)%"></i>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@* News, model and system (mockup 01): sections without a frame, under a dark rule (SPEC 13.2). *@
|
||||
<div class="overview-tiles desk-only">
|
||||
<section class="plain tile" aria-labelledby="notizie-sintesi">
|
||||
<div class="panel-head"><h2 id="notizie-sintesi">Notizie che contano</h2><a href="/notizie">Tutte</a></div>
|
||||
@if (p.News is null)
|
||||
{
|
||||
<p class="note">La lettura delle notizie non è ancora attiva. Quando lo sarà, qui vedrai le tre che contano di più per le tue posizioni e cosa ne ho fatto.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="news-list">
|
||||
@foreach (var n in p.News)
|
||||
{
|
||||
<li>
|
||||
<span class="note">@n.When, @n.About</span>
|
||||
<strong>@n.Title</strong>
|
||||
<span class="@(n.Active ? "attention" : "muted")">@if (n.Active) {<Icon Name="alert" Size="16" />}@n.Effect</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</section>
|
||||
<section class="plain tile" aria-labelledby="apprendimento-sintesi">
|
||||
<div class="panel-head"><h2 id="apprendimento-sintesi">Apprendimento</h2><a href="/apprendimento">Dettaglio</a></div>
|
||||
@if (p.Learning is not { } m)
|
||||
{
|
||||
<p class="note">L'apprendimento non è ancora attivo. Quando lo sarà, il modello osserverà i segnali delle strategie e qui vedrai quanto ci azzecca, prima che possa decidere qualcosa.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p><strong>Il modello osserva e impara, ma non decide ancora.</strong></p>
|
||||
<div class="limit">
|
||||
<div class="limit-line"><span>Segnali già valutati</span><span><strong>@m.Signals</strong> <span class="muted">su @m.Needed necessari</span></span></div>
|
||||
<span class="usage"><span style="width: @Css(Math.Min(100m, m.Signals * 100m / Math.Max(1, m.Needed)))%"></span></span>
|
||||
</div>
|
||||
<dl class="tile-facts">
|
||||
<dt>Previsioni azzeccate</dt><dd>@m.Precision% su dati mai visti</dd>
|
||||
<dt>Ultimo addestramento</dt><dd>@m.Trained</dd>
|
||||
<dt>Prossima verifica</dt><dd>@m.NextCheck</dd>
|
||||
</dl>
|
||||
}
|
||||
</section>
|
||||
<section class="plain tile" aria-labelledby="sistema-sintesi">
|
||||
<div class="panel-head"><h2 id="sistema-sintesi">Sistema</h2><a href="/diario">Dettaglio</a></div>
|
||||
<ul class="system-tiles">
|
||||
@foreach (var part in p.System.Tiles)
|
||||
{
|
||||
<li class="@PartClass(part.State)"><Icon Name="@PartIcon(part.State)" Size="16" /><span>@part.Name</span><span class="muted">@part.Detail</span></li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private Overview _overview = null!;
|
||||
private PanoramaView _panorama = null!;
|
||||
private string _currency = "EUR";
|
||||
private string _period = "avvio";
|
||||
private int? _runningDays;
|
||||
private decimal? _worst;
|
||||
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
@@ -118,6 +402,8 @@
|
||||
var services = Host.Services!;
|
||||
_currency = Shell.Effective((await services.Settings.GetAsync(SettingsStore.Currency.Key, ct)).Value);
|
||||
_overview = await Overview.LoadAsync(services, _period, Shell.Now, Shell.Zone, ct);
|
||||
_panorama = await PanoramaView.LoadAsync(Host, Shell, _overview, ct);
|
||||
_worst = _panorama.Limits[1].Worst is { } share ? -share * (await Anubis.Risk.RiskSettings.LoadAsync(services.Settings, ct)).DrawdownStop : null;
|
||||
using var aggregates = Shell.Aggregates();
|
||||
_runningDays = aggregates?.RootElement.GetProperty("giorno").GetInt32();
|
||||
}
|
||||
@@ -135,4 +421,60 @@
|
||||
: $"{o.PositionsWithoutStop} senza stop";
|
||||
return o.Positions == 1 ? $"Sorveglio una posizione, {stops}. {orders}" : $"Sorveglio {o.Positions} posizioni, {stops}. {orders}";
|
||||
}
|
||||
|
||||
private static bool Down(AccountCard a) => a.State.LastOutcome == ReconcileOutcomes.Unreachable;
|
||||
|
||||
private string AccountNote(AccountCard a, IReadOnlyList<PositionRow> held)
|
||||
{
|
||||
var count = held.Count == 1 ? "1 posizione" : $"{held.Count} posizioni";
|
||||
if (held.Count == 0)
|
||||
{
|
||||
count = "Nessuna posizione aperta";
|
||||
}
|
||||
|
||||
if (a.Broker != Venues.Alpaca)
|
||||
{
|
||||
var stops = held.Count(x => x.Stop is not null);
|
||||
var stopText = held.Count == 0 ? "" : stops == 1 ? ", 1 stop attivo" : $", {stops} stop attivi";
|
||||
return $"{count}{stopText}. Commissioni pagate finora: {Shell.Money(a.Eur(a.Fees), _currency)}.";
|
||||
}
|
||||
|
||||
var fractions = held.Any(x => x.Quantity != decimal.Truncate(x.Quantity));
|
||||
var stopsText = held.Count == 0 ? ""
|
||||
: " Stop permanenti sulle azioni intere" + (!fractions ? "." : _panorama.FractionStops is { } back
|
||||
? $"; sulle frazioni tornano alle {TimeZoneInfo.ConvertTime(back, Shell.Zone).ToString("HH:mm", CultureInfo.InvariantCulture)}."
|
||||
: "; sulle frazioni valgono fino alla chiusura.");
|
||||
var dollars = a.Currency == "USD" && a.Rate > 0m ? $" Conto in dollari: {Format.Money(a.Equity, "USD")} al cambio {Format.Quantity(a.Rate)}." : "";
|
||||
return count + "." + stopsText + dollars;
|
||||
}
|
||||
|
||||
private static string PartClass(PartState state) => state switch
|
||||
{
|
||||
PartState.Ok => "ok",
|
||||
PartState.Warn => "warn",
|
||||
_ => "off",
|
||||
};
|
||||
|
||||
private static string PartIcon(PartState state) => state switch
|
||||
{
|
||||
PartState.Ok => "tick",
|
||||
PartState.Warn => "alert",
|
||||
_ => "clock",
|
||||
};
|
||||
|
||||
private static string Css(decimal value) => Math.Round(value, 3).ToString("0.###", CultureInfo.InvariantCulture);
|
||||
|
||||
private static string Spark(IReadOnlyList<decimal> points)
|
||||
{
|
||||
var (min, max) = (points.Min(), points.Max());
|
||||
var range = Math.Max(0.01m, max - min);
|
||||
return string.Join(' ', points.Select((x, i) => Css(i * 116m / (points.Count - 1) + 2m) + "," + Css(32m - (x - min) / range * 28m)));
|
||||
}
|
||||
|
||||
private static (string X, string Y) SparkEnd(IReadOnlyList<decimal> points)
|
||||
{
|
||||
var (min, max) = (points.Min(), points.Max());
|
||||
var range = Math.Max(0.01m, max - min);
|
||||
return ("118", Css(32m - (points[^1] - min) / range * 28m));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user