Finish an interrupted rebuild and replay the past without acting on it
The independent review found that a rebuild cut halfway was never finished (stops canceled or lowered), that old stop executions replayed from the broker queued a real sale, that a pending "close all" survived the restore, and that reconciliation and corporate actions touched accounts not rebuilt yet. The rebuild now keeps its starting point until it ends, protects the bot before the first row, meets the splits at their date and leaves the ledger alone until it is done. Dividends count the shares of after a split. A failed restore of a missing SQLite file leaves no empty database, and a failed migration can be tried again from the choice page. refs #69 #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24e20584d4
commit
5ef54b6f2a
17 files changed
+613
-80
No files matched your search
@@ -114,7 +114,7 @@ internal sealed class TradingRig : IAsyncDisposable
|
||||
}
|
||||
|
||||
public OrderManager Manager(IBrokerAccount broker, AccountContext account, Func<Instrument, CancellationToken, Task<bool>>? marketOpen = null,
|
||||
Func<Instrument, CancellationToken, Task<CorporateAction?>>? pendingSplit = null)
|
||||
Func<Instrument, CancellationToken, Task<CorporateAction?>>? pendingSplit = null, Func<Instrument, CancellationToken, Task<IReadOnlyList<CorporateAction>>>? splits = null)
|
||||
{
|
||||
var manager = new OrderManager(Db, Clock, Ledger, broker, account, Installation, FindAsync, QuoteAsync)
|
||||
{
|
||||
@@ -122,6 +122,7 @@ internal sealed class TradingRig : IAsyncDisposable
|
||||
ConfirmPrice = QuoteAsync,
|
||||
MarketOpen = marketOpen ?? ((_, _) => Task.FromResult(true)),
|
||||
PendingSplit = pendingSplit,
|
||||
Splits = splits,
|
||||
};
|
||||
_owned.Add(manager);
|
||||
return manager;
|
||||
@@ -181,6 +182,12 @@ internal sealed class FaultyBroker(IBrokerAccount inner, string? environment = n
|
||||
/// <summary>Every fill is reported twice.</summary>
|
||||
public bool DuplicateFills { get; set; }
|
||||
|
||||
/// <summary>Every execution of a stop is reported in two halves.</summary>
|
||||
public bool SplitStopFills { get; set; }
|
||||
|
||||
/// <summary>Which reading of the fills fails, counting from now: 1 the next, 2 the one after it.</summary>
|
||||
public int FailFillsAt { get; set; }
|
||||
|
||||
/// <summary>Every call fails as if the network were down.</summary>
|
||||
public bool Down { get; set; }
|
||||
|
||||
@@ -246,7 +253,21 @@ internal sealed class FaultyBroker(IBrokerAccount inner, string? environment = n
|
||||
|
||||
public async Task<IReadOnlyList<BrokerFill>> GetFillsAsync(DateTimeOffset since, CancellationToken cancellationToken)
|
||||
{
|
||||
if (FailFillsAt > 0 && --FailFillsAt == 0)
|
||||
{
|
||||
throw new BrokerException("risposta interrotta", retryable: true);
|
||||
}
|
||||
|
||||
var fills = await Guard(() => inner.GetFillsAsync(since, cancellationToken)).ConfigureAwait(false);
|
||||
if (SplitStopFills)
|
||||
{
|
||||
fills = [.. fills.SelectMany(f => ClientOrderIds.Parse(f.ClientOrderId)?.Purpose != OrderPurpose.Stop ? [f] : new[]
|
||||
{
|
||||
f with { ExecutionId = f.ExecutionId + "a", Quantity = f.Quantity / 2m, Fee = f.Fee / 2m },
|
||||
f with { ExecutionId = f.ExecutionId + "b", Quantity = f.Quantity / 2m, Fee = f.Fee / 2m, ExecutedAt = f.ExecutedAt.AddSeconds(1) },
|
||||
})];
|
||||
}
|
||||
|
||||
return DuplicateFills ? [.. fills, .. fills] : fills;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user