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
@@ -175,4 +175,44 @@ public sealed class LiveEngineTests
|
||||
Assert.IsLessThan(live.Instruments[symbol].Spec.LotSize ?? 0m, Math.Abs(quantity - ledger[symbol]), symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A purchase was working when the process stopped. Normally it is proposed again; after a restore (SPEC 15.1) the
|
||||
/// archive may be older than the account, so nothing is proposed: the strategies decide again.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
[DataRow(false)]
|
||||
[DataRow(true)]
|
||||
public async Task AfterARestoreAnInterruptedPurchaseIsNotProposedAgain(bool restored)
|
||||
{
|
||||
var last = LiveFrom.AddDays(120);
|
||||
await using var live = await LiveRig.CreateAsync(LiveFrom, last).ConfigureAwait(false);
|
||||
var found = false;
|
||||
for (var day = LiveFrom; day <= last && !found; day = day.AddDays(1))
|
||||
{
|
||||
await live.DayAsync(day, async _ =>
|
||||
{
|
||||
if (found || await live.WorkingOrdersAsync().ConfigureAwait(false) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
found = true;
|
||||
await live.Rig.Db.WriteAsync(async s =>
|
||||
{
|
||||
await s.ExecuteAsync("DELETE FROM installation").ConfigureAwait(false);
|
||||
await s.ExecuteAsync("INSERT INTO installation (id, fingerprint, engine, protected_restart, created_at, renewed_at) VALUES (@id, @f, @e, @p, @now, @now)", CancellationToken.None, ("e", "sqlite"),
|
||||
("id", Guid.NewGuid()), ("f", Guid.NewGuid()), ("p", restored), ("now", live.Rig.Clock.UtcNow)).ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
var again = await live.Engine.ResumeAsync(live.Manager, CancellationToken.None).ConfigureAwait(false);
|
||||
Assert.AreEqual(restored ? 0 : 1, Math.Min(again, 1));
|
||||
Assert.AreEqual(0, await live.WorkingOrdersAsync().ConfigureAwait(false), "What was working is canceled either way.");
|
||||
Assert.HasCount(restored ? 0 : again, await live.Rig.QueryAsync("SELECT id FROM planned_orders WHERE status = @s AND execution_id IS NULL", r => r.Id("id"),
|
||||
("s", PlannedStates.Pending)).ConfigureAwait(false));
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Assert.IsTrue(found, "A purchase must have been working.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user