Write the manuals and fix what following them found

The manual, the runbook and the go-live list are written and checked claim by
claim against the code, and the installation is done from zero by following
them on both engines. That found real defects, now fixed:

- with SQLite a missing database file left no way to restore a backup: the
  choices appear, and the file is created only by the user's choice;
- an account whose difference vanished after the 15 minutes stayed prudent
  with no button, a missing stop could be left out for good, and a choice
  made while the broker was silent used old numbers;
- after "Ferma tutto" the positions could not be closed without restarting;
- a refused key looked like a silent broker: it has its own notice now;
- the split of the capital between the strategies of a broker (SPEC 13.5)
  could not be changed from the interface.

refs #72 #68

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 21:38:33 +01:00
1 parent 2257c3e16c
commit 24e20584d4
28 files changed
+1147 -57

No files matched your search

+65 -9
View File
@@ -34,6 +34,7 @@ internal static partial class Forms
signed.MapPost("/chiavi/{broker}", SaveKeysAsync);
signed.MapPost("/chiavi/{broker}/togli", RemoveKeysAsync);
signed.MapPost("/capitale/{broker}", SetCapitalAsync);
signed.MapPost("/quote/{broker}", SetSharesAsync);
signed.MapPost("/telegram", SaveTelegramAsync);
signed.MapPost("/telegram/prova", TestTelegramAsync);
signed.MapPost("/telegram/togli", RemoveTelegramAsync);
@@ -361,9 +362,15 @@ internal static partial class Forms
return Results.Redirect("/conti?errore=presto");
}
await trading.Reconciler.ResolveAsync(manager, choice == "allinea" ? Anubis.Trading.ReconcileChoice.Align : Anubis.Trading.ReconcileChoice.Exclude,
var resolution = await trading.Reconciler.ResolveAsync(manager, choice == "allinea" ? Anubis.Trading.ReconcileChoice.Align : Anubis.Trading.ReconcileChoice.Exclude,
context.User.Identity?.Name ?? "utente", ct).ConfigureAwait(false);
return Results.Redirect("/conti?ok=" + choice);
return Results.Redirect(resolution switch
{
Anubis.Trading.ReconcileResolution.NotCompared => "/conti?errore=broker",
Anubis.Trading.ReconcileResolution.StopsMissing => "/conti?errore=stop",
_ when !state.HasChoices => "/conti?ok=ricontrollo",
_ => "/conti?ok=" + choice,
});
}
/// <summary>
@@ -590,6 +597,54 @@ internal static partial class Forms
return Results.Redirect(back + "?ok=capitale#conti");
}
/// <summary>How the capital of a broker is split between its strategies, in percent (SPEC 13.5): only the user changes it.</summary>
private static async Task<IResult> SetSharesAsync(string broker, IFormCollection form, AnubisHost host, IClock clock, HttpContext context, CancellationToken ct)
{
const string back = "/impostazioni";
if (broker is not (Anubis.Data.Venues.Okx or Anubis.Data.Venues.Alpaca))
{
return Results.Redirect(back + "?errore=conto#conti");
}
if (host.IsDemo || host.Services?.Trading is not { } trading)
{
return Results.Redirect(back + "?errore=motore#conti");
}
var shares = new Dictionary<string, decimal>(StringComparer.Ordinal);
foreach (var strategy in await trading.Capital.StrategiesAsync(broker, ct).ConfigureAwait(false))
{
if (ParseEuro(form["quota-" + strategy.Strategy].ToString().Replace("%", "", StringComparison.Ordinal)) is not { } percent)
{
return Results.Redirect(back + "?errore=quote#conti");
}
shares[strategy.Strategy] = percent / 100m;
}
if (shares.Count == 0 || shares.Values.Any(s => s is < 0m or > 1m) || shares.Values.Sum() != 1m)
{
return Results.Redirect(back + "?errore=quote#conti");
}
// Moving capital between strategies gives some of them more: with real money on this broker it is more risk (SPEC 12.4).
if (await RaiseRefusalAsync(host.Services!, clock, broker, form, ct).ConfigureAwait(false) is { } refusal)
{
return Results.Redirect(back + "?errore=" + refusal + "#conti");
}
try
{
await trading.SetSharesAsync(broker, shares, context.User.Identity?.Name ?? "utente", ct).ConfigureAwait(false);
}
catch (Anubis.Trading.CapitalException)
{
return Results.Redirect(back + "?errore=capitale#conti");
}
return Results.Redirect(back + "?ok=quote#conti");
}
/// <summary>
/// The user's choices on the Strategie screen (SPEC 12.3, 12.4): observation and simulation from a button, real
/// money only through the procedure, with the phrase, the password and the second factor checked by the stage book.
@@ -1097,7 +1152,6 @@ internal static partial class Forms
// The startup loop stays still until the choice is done and the installation renewed.
using var exclusive = await host.ExclusiveAsync(ct).ConfigureAwait(false);
var status = host.Status;
var db = host.Database;
if (choice == "riprova" && status.Mode == HostMode.SchemaProblem)
{
host.MigrationFailed = null;
@@ -1106,8 +1160,10 @@ internal static partial class Forms
return Results.Redirect("/");
}
if (status.Mode != HostMode.IdentityProblem || status.Identity is null || db is null)
// Without a database the choices stand only while the SQLite file is missing: one that came back is used as it is.
if (status.Mode != HostMode.IdentityProblem || status.Identity is null || (host.Database is null && !host.SqliteFileMissing))
{
host.Wake();
return Results.Redirect("/");
}
@@ -1123,8 +1179,8 @@ internal static partial class Forms
return Results.Redirect("/?errore=scelta");
}
await Archive.ImportAsync(db, Path.Combine(backup.Folder, Backups.ArchiveFolder), clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Salvataggio ripristinato", ct).ConfigureAwait(false);
await Archive.ImportAsync(host.OpenForChoice(), Path.Combine(backup.Folder, Backups.ArchiveFolder), clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(host.OpenForChoice(), config.Data, clock, "Salvataggio ripristinato", ct).ConfigureAwait(false);
break;
case "importa" when verdict == IdentityVerdict.EmptyDatabase:
var folder = ServiceChoices.ImportFolders(config.Data).FirstOrDefault(f => Path.GetFileName(f) == form["archivio"].ToString());
@@ -1133,8 +1189,8 @@ internal static partial class Forms
return Results.Redirect("/?errore=scelta");
}
await Archive.ImportAsync(db, folder, clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Archivio importato", ct).ConfigureAwait(false);
await Archive.ImportAsync(host.OpenForChoice(), folder, clock, ct).ConfigureAwait(false);
await Installation.RenewAsync(host.OpenForChoice(), config.Data, clock, "Archivio importato", ct).ConfigureAwait(false);
break;
case "da-capo" when verdict == IdentityVerdict.EmptyDatabase:
Installation.StartOver(config.Data, clock);
@@ -1142,7 +1198,7 @@ internal static partial class Forms
case "usa-questo" when verdict is IdentityVerdict.DifferentInstallation or IdentityVerdict.StaleDatabase or IdentityVerdict.MissingFile:
// An old copy may have an old schema: it is brought up to date, after its own backup, before it is protected.
await host.MigrateAsync(new Backups(config.Data, clock), ct).ConfigureAwait(false);
await Installation.RenewAsync(db, config.Data, clock, "Database scelto dalla pagina d'errore", ct).ConfigureAwait(false);
await Installation.RenewAsync(host.OpenForChoice(), config.Data, clock, "Database scelto dalla pagina d'errore", ct).ConfigureAwait(false);
break;
default:
return Results.Redirect("/?errore=scelta");