Add the Operazioni, Strategie and Rischio screens (refs #45)

The three screens follow mockups 03, 04 and 07.

Operazioni shows the balance of the closed trades, filters, a CSV export,
and for each trade why it was bought and sold. The reasons come from the
decision codes through fixed Italian templates.

Strategie shows the four stages towards real money, a card per strategy
with its requirements, the procedure of SPEC 12.4, and why each strategy in
observation waits. A strategy that failed its backtest cannot be moved into
the simulation.

Rischio shows the emergency switch, the automatic blocks, the use of each
limit, the fall from the peak, the scenarios and the risk events. Stop,
close and restart now go through the risk engine. A restart is refused
while the STOP file exists.

Impostazioni gains the limits, the day-trade guard and the scenarios.
Lowering a limit is always allowed. Raising a limit or the entrusted capital
while a strategy uses real money needs the phrase and the password.

The demo now holds the decisions behind its trades, the 58 days of
simulation and the indices of its curves, so it matches the mockups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 16:14:44 +01:00
1 parent 7041533ce2
commit 13f9c42f61
16 files changed
+2085 -34

No files matched your search

@@ -21,6 +21,9 @@
"chiavi" => "Chiavi verificate e salvate: possono fare ordini e non possono prelevare. Il motore è ripartito e le usa.",
"chiavi-tolte" => "Chiavi tolte: quel conto torna al simulatore interno per le strategie che non hanno ancora storia sul conto di prova.",
"capitale" => "Capitale affidato aggiornato e diviso tra le strategie.",
"limiti" => "Limiti di rischio salvati.",
"rischio" => "Impostazione del rischio salvata.",
_ => "Fatto.",
})</p>
}
@@ -30,7 +33,7 @@
}
<nav class="tabs" aria-label="Sezioni delle impostazioni">
<a href="#aspetto">Aspetto</a><a href="#conti">Conti</a><a href="#dati">Dati</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
<a href="#aspetto">Aspetto</a><a href="#conti">Conti</a><a href="#rischio">Rischio</a><a href="#dati">Dati</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
</nav>
<section class="panel" id="aspetto">
@@ -135,7 +138,56 @@
}
</section>
<section class="panel" id="rischio">
<h2>Rischio</h2>
<p class="note">I limiti valgono per tutte le strategie insieme. Abbassarli è sempre possibile. @(_anyLive ? "Una strategia usa soldi veri: per alzarne uno servono la frase e la password." : "Finché nessuna strategia usa soldi veri, puoi anche alzarli.")</p>
@if (!Shell.IsDemo)
{
<form method="post" action="/azioni/rischio/limiti" class="form-grid limits-form">
<AntiforgeryToken />
@foreach (var l in _limits)
{
<label>@l.Label<input name="@l.Key" value="@l.Value" inputmode="decimal" autocomplete="off" readonly="@l.ReadOnly" /></label>
}
@if (_anyLive)
{
<label>Per alzare un limite scrivi: <code>@StageBook.RaisePhrase</code><input name="frase" autocomplete="off" /></label>
<label>Password<input name="password" type="password" autocomplete="current-password" /></label>
<label>Codice a sei cifre (se attivo)<input name="codice" inputmode="numeric" autocomplete="one-time-code" /></label>
}
<button class="btn" type="submit">Salva i limiti</button>
</form>
<h3>Protezione day trade</h3>
<form method="post" action="/azioni/rischio/@Anubis.Risk.RiskSettings.PdtGuard.Key" class="form-inline">
<AntiforgeryToken />
<label for="pdt">Per un conto Alpaca sotto i 25.000 $: al massimo 3 operazioni aperte e chiuse in giornata ogni 5 sedute.</label>
<select id="pdt" name="valore" data-autosubmit>
<option value="off" selected="@(_pdt == "off")">Spenta</option>
<option value="on" selected="@(_pdt == "on")">Accesa</option>
</select>
<noscript><button class="btn btn-small" type="submit">Salva</button></noscript>
</form>
<h3>Scenari «Se succedesse domani»</h3>
<form method="post" action="/azioni/rischio/@Anubis.Risk.Scenarios.Setting.Key" class="form">
<AntiforgeryToken />
<label for="scenari">Uno per riga: descrizione; variazione delle crypto %; delle azioni USA %; del dollaro sull'euro %. Per esempio «Le crypto perdono il 20% in un giorno; -20; 0; 0».</label>
<textarea id="scenari" name="valore" rows="5" spellcheck="false">@_scenarios</textarea>
<button class="btn" type="submit">Salva gli scenari</button>
</form>
}
else
{
<dl class="facts">
@foreach (var l in _limits)
{
<dt>@l.Label</dt><dd>@l.Value</dd>
}
</dl>
}
</section>
<section class="panel" id="dati">
<h2>Dati</h2>
@if (Host.Services!.MarketData is not { } market)
{
@@ -302,7 +354,13 @@
private sealed record BrokerSetup(string Broker, string Title, string Short, IReadOnlyList<BrokerKey> Keys, AccountState? State, EntrustedCapital? Entrusted,
IReadOnlyList<StrategyCapital> Strategies);
private sealed record LimitField(string Key, string Label, string Value, bool ReadOnly);
private readonly List<LimitField> _limits = [];
private bool _anyLive;
private string _pdt = "off";
private string _scenarios = "";
private IReadOnlyList<Anubis.Data.SourceState> _sources = [];
private SettingValue _meetings = new(SettingsStore.CentralBankMeetings.Key, "", false, null);
private List<SettingChange> _history = [];
private IReadOnlyList<BackupInfo> _backups = [];
@@ -328,6 +386,16 @@
_history = await services.Settings.HistoryAsync(null, 50, ct);
_meetings = await services.Settings.GetAsync(SettingsStore.CentralBankMeetings.Key, ct);
_sources = await new Anubis.Data.SourceStateStore(services.Db, Clock).ListAsync(ct);
foreach (var definition in Anubis.Risk.RiskSettings.Limits)
{
var value = await services.Settings.GetAsync(definition.Key, ct);
_limits.Add(new LimitField(definition.Key, definition.Label, value.Value, value.ReadOnly));
}
_pdt = (await services.Settings.GetAsync(Anubis.Risk.RiskSettings.PdtGuard.Key, ct)).Value;
_scenarios = (await services.Settings.GetAsync(Anubis.Risk.Scenarios.Setting.Key, ct)).Value;
_anyLive = await (services.Trading?.Stages ?? new StageBook(services.Db, Clock, TradingConsent.None, (_, _, _) => Task.FromResult(false))).AnyLiveAsync(null, ct);
_backups = services.Backups.List();
var ledger = new Ledger(services.Db, Clock);
var capital = new Capital(services.Db, Clock, ledger, new FxStore(services.Db, Clock));
@@ -372,6 +440,12 @@
"importo" => "Scrivi un importo in euro, per esempio 4000 o 1.500,50.",
"cambio" => "Manca ancora il cambio euro/dollaro della BCE: lo scarico ogni giorno, riprova più tardi.",
"capitale" => "Una strategia ha investito più di quanto le resterebbe: potrò ridurre il capitale quando avrà venduto.",
"limite" => "Un limite non è valido: controlla che ogni valore sia un numero dentro il suo intervallo.",
"ordine-limiti" => "Il dimezzamento sul calo dal massimo deve venire prima dell'interruttore, e la perdita di un giorno non può superare quella di una settimana.",
"frase-rischio" => $"Una strategia usa soldi veri: per aggiungere rischio scrivi la frase «{StageBook.RaisePhrase}». Non ho cambiato nulla.",
"password-rischio" => "Password o codice non corretti. Non ho cambiato nulla.",
"scenari" => "Gli scenari non sono validi: una riga ciascuno, con descrizione e tre percentuali separate da punto e virgola.",
_ => PasswordMessages.For(Errore),
};