Rebuild the state from the brokers after a restore and refuse an older copy
A restore, an import or an adopted database restarts protected: the engine stays stopped, reads from the broker what the archive does not know (orders, stops, executions, also from the OKX history up to 89 days), cancels orders left working, protects what it finds and waits for the user. Strategies with real money stay exit only until confirmed again. The database of before the restore, put back by mistake, is refused by its fingerprint. A failed migration leaves the engine off with one backup and a way to try again; an archive is checked whole before the database is touched; a changed secret key no longer crashes anything, and "anubis access reset" gives the access back to whoever holds the computer. The image runs the db and access commands without the guard. refs #69 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3da9b00f44
commit
4897594b87
40 files changed
+1871
-90
No files matched your search
@@ -9,6 +9,29 @@ namespace Anubis.Server;
|
||||
/// <summary>A row of the limits table: what is used now against the threshold, and what happens beyond it.</summary>
|
||||
internal sealed record LimitRow(string Label, string Now, string? Detail, decimal? Usage, string Threshold, string Beyond, string Key);
|
||||
|
||||
/// <summary>
|
||||
/// The protected restart of SPEC 15.1: since when, the accounts still to rebuild, what was rebuilt, the strategies
|
||||
/// that stay in exit only until they are confirmed again.
|
||||
/// </summary>
|
||||
internal sealed record ProtectedRestartView(DateTimeOffset Since, bool Working, IReadOnlyList<string> Waiting, IReadOnlyList<string> Rebuilt, IReadOnlyList<string> ToReconfirm)
|
||||
{
|
||||
public bool CanRestart => !Working && Waiting.Count == 0;
|
||||
|
||||
public static async Task<ProtectedRestartView?> LoadAsync(AppServices services, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await Platform.Installation.ReadRowAsync(services.Db, cancellationToken).ConfigureAwait(false) is not { ProtectedRestart: true } row)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var rebuilt = await services.Db.ReadAsync(s => s.QueryAsync("SELECT message FROM journal WHERE code = 'ledger_rebuilt' AND occurred_at >= @f ORDER BY occurred_at, id",
|
||||
r => r.Text("message"), ("f", row.RenewedAt)), cancellationToken).ConfigureAwait(false);
|
||||
var stages = services.Trading is { } trading ? await trading.Stages.AllAsync(cancellationToken).ConfigureAwait(false) : [];
|
||||
return new ProtectedRestartView(row.RenewedAt, services.Trading is { Started: false }, services.Trading?.AccountsToRebuild ?? [], rebuilt,
|
||||
[.. stages.Where(s => s.WaitsForReconfirmation).Select(s => StrategyNames.Label(s.Strategy, withMarket: true))]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A point of the fall from the high, as a fraction: 0 at the high, −0,03 three percent below.</summary>
|
||||
internal sealed record DrawdownPoint(DateTimeOffset At, decimal Drawdown);
|
||||
|
||||
@@ -33,6 +56,9 @@ internal sealed record RiskView(
|
||||
bool HasPositions,
|
||||
IReadOnlyList<WorldRisk> Tripped)
|
||||
{
|
||||
/// <summary>After a restore (SPEC 15.1): what the restart waits for, and what stays in exit only after it.</summary>
|
||||
public ProtectedRestartView? ProtectedRestart { get; init; }
|
||||
|
||||
public bool AnyBlock => Tripped.Count > 0 || Risk.EntriesBlocked || Risk.Multiplier < 1m || BotState != "active";
|
||||
|
||||
/// <summary>The switch tripped by itself in a world (SPEC 9.2): it waits for the user's restart, like "Ferma tutto".</summary>
|
||||
@@ -133,7 +159,10 @@ internal sealed record RiskView(
|
||||
|
||||
return new RiskView(bot, engine.StopRequested, (await engine.BotAsync(cancellationToken).ConfigureAwait(false)).CloseAll, world, risk, limits, rows, drawdown, scenarios,
|
||||
await engine.EventsAsync(8, cancellationToken).ConfigureAwait(false), next, last, await RiskSettings.PdtGuardAsync(services.Settings, cancellationToken).ConfigureAwait(false),
|
||||
positions.Count > 0, tripped);
|
||||
positions.Count > 0, tripped)
|
||||
{
|
||||
ProtectedRestart = await ProtectedRestartView.LoadAsync(services, cancellationToken).ConfigureAwait(false),
|
||||
};
|
||||
}
|
||||
|
||||
private static decimal? Worst(IReadOnlyList<IndexPoint> index, DateTimeOffset? from)
|
||||
|
||||
Reference in new issue
Block a user