Fix what the review of Phase 9 found in accounts, access, capital, health and publication
A position left out together with its stop kept the account prudent for good: the stop was still asked for shares that no longer exist. The cover required now stops at what the account holds, the stops are compared again after the choice, and where one is still missing Align takes the excluded position up again. After the choice the account waits for the stop with its own reason, so it returns to normal by itself also past the 15 minutes; a new difference still gets its own 15 minutes. A right password alone no longer clears the wrong second-factor codes: it takes back only its own attempt. Capital and shares are planned and written in one transaction, so overlapping changes cannot apply twice and an interruption leaves nothing halfway; sending the same figures again completes what an old one left. The cash that purchases under way still hold is no longer given away, counted as the risk engine counts it. /health said healthy when the trading engine had failed to start. It now says so at once, or after ten minutes of a stalled start, and the host tries the start again every minute; the guard still sees a start that does not move. The image of the manual publication says its version and its commit, marked when the tree is dirty, and publish.sh refuses before any login an image that does not come from the commit of the tag. refs #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24e20584d4
commit
81d6c5f667
20 files changed
+814
-174
No files matched your search
@@ -62,6 +62,7 @@ internal sealed partial class AnubisHost(
|
||||
|
||||
private readonly AccessGuards _accessGuards = new(clock);
|
||||
private readonly TimeSpan _interval = overrides?.DatabaseCheckInterval ?? TimeSpan.FromSeconds(5);
|
||||
private readonly TimeSpan _tradingRetry = overrides?.TradingRetry ?? TimeSpan.FromMinutes(1);
|
||||
private readonly Lock _gate = new();
|
||||
|
||||
// One step of the loop or one error-page choice at a time: a restore must not race the start that would follow it.
|
||||
@@ -666,7 +667,11 @@ internal sealed partial class AnubisHost(
|
||||
{
|
||||
try
|
||||
{
|
||||
await trading.StartAsync(cancellationToken).ConfigureAwait(false);
|
||||
while (!await TryStartAsync(trading, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
await Task.Delay(_tradingRetry, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await trading.RunAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
||||
@@ -678,6 +683,20 @@ internal sealed partial class AnubisHost(
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> TryStartAsync(TradingService trading, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
await trading.StartAsync(cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException || !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
LogTradingStartFailed(logger, ex, _tradingRetry);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The jobs table keeps the outcome of the last run of each job (Diario e sistema, SPEC 13.6).
|
||||
private async Task RecordJobsAsync(EventSubscription<JobRun> runs, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -813,6 +832,9 @@ internal sealed partial class AnubisHost(
|
||||
[LoggerMessage(Level = LogLevel.Error, Message = "Trading stopped")]
|
||||
private static partial void LogTradingFailed(ILogger logger, Exception exception);
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Error, Message = "Trading could not start: tried again in {Delay}")]
|
||||
private static partial void LogTradingStartFailed(ILogger logger, Exception exception, TimeSpan delay);
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not record the run of job {Job}")]
|
||||
private static partial void LogJobRecordFailed(ILogger logger, Exception exception, string job);
|
||||
}
|
||||
@@ -130,12 +130,23 @@ else
|
||||
}
|
||||
else if (state.WaitsForUser(Clock.UtcNow, TimeSpan.FromMinutes(15)) && !Shell.IsDemo)
|
||||
{
|
||||
<p>Sono passati 15 minuti e la differenza non si è spiegata da sola. Scegli tu:</p>
|
||||
@if (state.Differences.All(d => d.Kind == DifferenceKinds.Stop))
|
||||
{
|
||||
<p>Manca ancora uno stop, dove avevi lasciato fuori una differenza. Se il conto non lo accetta, allinea il registro:</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Sono passati 15 minuti e la differenza non si è spiegata da sola. Scegli tu:</p>
|
||||
}
|
||||
<div class="choices">
|
||||
<form method="post" action="/azioni/conti/@a.Id/allinea"><AntiforgeryToken /><button class="btn btn-small" type="submit" data-confirm="Il registro prende i numeri del conto, con una riga di rettifica che resta nel diario. Confermi?">Allinea il registro al conto</button></form>
|
||||
<form method="post" action="/azioni/conti/@a.Id/escludi"><AntiforgeryToken /><button class="btn btn-small" type="submit">Lascia fuori ciò che non è del bot</button></form>
|
||||
</div>
|
||||
}
|
||||
else if (state.ModeReason == Reconciler.StopReason)
|
||||
{
|
||||
<p class="note">Manca ancora uno stop: riprovo a ogni confronto e il conto torna normale da solo quando c'è.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="note">Se entro 15 minuti si spiega da sola il conto torna normale; altrimenti qui potrai scegliere se allineare il registro o lasciare fuori la differenza.</p>
|
||||
|
||||
@@ -792,7 +792,7 @@
|
||||
"sola-lettura" => "Questa chiave può solo leggere: per lavorare sul conto di prova serve anche il permesso di fare ordini. Non l'ho salvata.",
|
||||
"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.",
|
||||
"capitale" => "Una strategia ha investito, o sta comprando, più di quanto le resterebbe: potrò ridurre il capitale quando avrà venduto o finito di comprare.",
|
||||
"quote" => "Le quote vanno da 0 a 100 e insieme fanno 100: per esempio 60 e 40. Non ho cambiato nulla.",
|
||||
"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.",
|
||||
|
||||
@@ -62,7 +62,8 @@ internal static partial class Endpoints
|
||||
|
||||
checks["scheduler"] = host.SchedulerRunning ? "ok" : "fermo";
|
||||
healthy &= host.SchedulerRunning;
|
||||
var (loop, loopOk) = HealthRules.Loop(host.Clock.UtcNow, services.Trading is { IsStarted: true }, services.Trading?.LastTurnAt);
|
||||
var (loop, loopOk) = HealthRules.Loop(host.Clock.UtcNow, services.Trading is null ? null : status.Since, services.Trading is { IsStarted: true },
|
||||
services.Trading is { StartFailed: true }, services.Trading?.LastTurnAt);
|
||||
var (feed, feedOk) = HealthRules.Feed(host.Clock.UtcNow, services.MarketData?.LiveFeed.Since, services.MarketData?.LiveFeed.LastDataAt);
|
||||
checks["motore"] = loop;
|
||||
checks["dati"] = feed;
|
||||
@@ -540,14 +541,19 @@ internal static class HealthRules
|
||||
/// <summary>The same silence after which the guard steps in (SPEC 9.3).</summary>
|
||||
public static readonly TimeSpan LoopLimit = TimeSpan.FromMinutes(2);
|
||||
|
||||
/// <summary>A start of the engine this long is stalled, as for the guard (SPEC 9.3).</summary>
|
||||
public static readonly TimeSpan StartLimit = TimeSpan.FromMinutes(10);
|
||||
|
||||
/// <summary>Longer than the silence that blocks new entries (SPEC 6.5): a line that drops for a moment is not an ill container.</summary>
|
||||
public static readonly TimeSpan FeedLimit = TimeSpan.FromMinutes(5);
|
||||
|
||||
public static (string Text, bool Ok) Loop(DateTimeOffset now, bool started, DateTimeOffset? lastTurn) => (started, lastTurn) switch
|
||||
/// <summary>The engine's loop; <paramref name="since"/> is when the services became ready, null where there is no engine to start.</summary>
|
||||
public static (string Text, bool Ok) Loop(DateTimeOffset now, DateTimeOffset? since, bool started, bool failed, DateTimeOffset? lastTurn) => (since, started, lastTurn) switch
|
||||
{
|
||||
(false, _) => ("non avviato", true),
|
||||
(_, null) => ("in avvio", true),
|
||||
(_, { } at) when now - at > LoopLimit => ("fermo", false),
|
||||
(null, _, _) => ("non avviato", true),
|
||||
({ } from, false, _) when failed || now - from > StartLimit => ("non avviato", false),
|
||||
(_, false, _) or (_, _, null) => ("in avvio", true),
|
||||
(_, _, { } at) when now - at > LoopLimit => ("fermo", false),
|
||||
_ => ("ok", true),
|
||||
};
|
||||
|
||||
|
||||
@@ -81,4 +81,7 @@ internal sealed record ServerOverrides
|
||||
|
||||
/// <summary>True starts the accounts and the order managers in a test; off by default in tests.</summary>
|
||||
public bool? Trading { get; init; }
|
||||
|
||||
/// <summary>How long after a failed start of the trading engine it is tried again.</summary>
|
||||
public TimeSpan? TradingRetry { get; init; }
|
||||
}
|
||||
Reference in new issue
Block a user