Replay the past of a rebuilt account in its order
What an account did while the bot was off is now written before the splits and the dividends of those days, once and without acting on it; an attempt cut halfway is taken up from the same point. Until then the account is not valued at today's price, the guard keeps the last figures it knew with their time, and a stop order only cancels what is open. Protective sales of the archive are not continued, and the rest of a stop that fired in part is sold. Also the decisions of the phase (ADR 0020), the manuals and the dates under the equity chart. refs #69 #72 #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e58a26e8fa
commit
76b64ef147
31 files changed
+957
-130
No files matched your search
@@ -92,6 +92,8 @@ public sealed class FormatTests
|
||||
Assert.AreEqual("mer 31 dic 2025", Format.ShortDate(new DateTimeOffset(2025, 12, 31, 10, 0, 0, TimeSpan.Zero), now, _rome));
|
||||
Assert.AreEqual("Venerdì 9 ottobre 2026, ore 08:21", Format.LongDateTime(now, _rome));
|
||||
Assert.AreEqual("12 agosto 2026", Format.LongDate(new DateOnly(2026, 8, 12)));
|
||||
Assert.AreEqual("12 ago", Format.AxisDay(new DateOnly(2026, 8, 12), 58));
|
||||
Assert.AreEqual("ago 2026", Format.AxisDay(new DateOnly(2026, 8, 12), 900));
|
||||
Assert.AreEqual("4 secondi fa", Format.Ago(TimeSpan.FromSeconds(4)));
|
||||
Assert.AreEqual("1 minuto fa", Format.Ago(TimeSpan.FromSeconds(65)));
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public sealed class LedgerTests
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await rig.Ledger.MarkAsync(instrument.Id, price, _none).ConfigureAwait(false);
|
||||
await rig.Ledger.MarkAsync(account.AccountId, instrument.Id, price, _none).ConfigureAwait(false);
|
||||
await AssertBooksAsync(rig, account, strategy, step).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -363,7 +363,7 @@ public sealed class LedgerTests
|
||||
// A gain of 400 € on OKX, then the capital doubles: the return stays 10%, the deposit is no gain.
|
||||
var btc = await rig.InstrumentAsync(TradingRig.Btc).ConfigureAwait(false);
|
||||
await rig.Ledger.RecordFillAsync(rig.Fill(okx, btc, StrategyNames.CryptoTrend, OrderSide.Buy, 0.05m, 60000m), _none).ConfigureAwait(false);
|
||||
await rig.Ledger.MarkAsync(btc.Id, 68000m, _none).ConfigureAwait(false);
|
||||
await rig.Ledger.MarkAsync(okx.AccountId, btc.Id, 68000m, _none).ConfigureAwait(false);
|
||||
rig.Clock.Advance(TimeSpan.FromMinutes(5));
|
||||
await book.TakeAsync(_none).ConfigureAwait(false);
|
||||
await capital.SetAsync(Venues.Okx, 8000m, "test", _none).ConfigureAwait(false);
|
||||
|
||||
@@ -209,7 +209,7 @@ internal sealed class StockRig : IAsyncDisposable
|
||||
await MinutesAsync(3).ConfigureAwait(false);
|
||||
foreach (var symbol in Stocks)
|
||||
{
|
||||
await Rig.Ledger.MarkAsync(_instruments[symbol].Id, (decimal)Bar(symbol, day)!.Close, none).ConfigureAwait(false);
|
||||
await Rig.Ledger.MarkAsync(Alpaca.AccountId, _instruments[symbol].Id, (decimal)Bar(symbol, day)!.Close, none).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await Equity.TakeAsync(none).ConfigureAwait(false);
|
||||
|
||||
@@ -239,7 +239,7 @@ internal sealed class LiveRig : IAsyncDisposable
|
||||
|
||||
foreach (var coin in Coins)
|
||||
{
|
||||
await Rig.Ledger.MarkAsync(_instruments[coin].Id, (decimal)Bar(coin, day).Close, none).ConfigureAwait(false);
|
||||
await Rig.Ledger.MarkAsync(Okx.AccountId, _instruments[coin].Id, (decimal)Bar(coin, day).Close, none).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await Equity.TakeAsync(none).ConfigureAwait(false);
|
||||
|
||||
@@ -113,6 +113,28 @@ public sealed class RestoreServerTests
|
||||
}
|
||||
|
||||
Assert.IsFalse(File.Exists(file), "Trap 20: no database by itself.");
|
||||
|
||||
// The true file comes back while a choice is at work, and the choice fails: it is not taken away.
|
||||
using (await server.Host.ExclusiveAsync(CancellationToken.None))
|
||||
{
|
||||
var db = server.Host.OpenForChoice();
|
||||
File.Copy(away, file);
|
||||
Assert.IsFalse((await Migrations.StatusAsync(db, CancellationToken.None)).IsEmpty);
|
||||
await server.Host.AbandonChoiceAsync();
|
||||
Assert.IsTrue(File.Exists(file), "The file that came back stays in its place.");
|
||||
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
|
||||
foreach (var f in Directory.EnumerateFiles(Path.GetDirectoryName(file)!))
|
||||
{
|
||||
File.Delete(f);
|
||||
}
|
||||
|
||||
// What a choice began to write is another thing: it steps aside.
|
||||
await Migrations.MigrateAsync(server.Host.OpenForChoice(), SystemClock.Instance, null, CancellationToken.None);
|
||||
await server.Host.AbandonChoiceAsync();
|
||||
Assert.IsFalse(File.Exists(file));
|
||||
Assert.HasCount(1, Directory.GetFiles(Path.GetDirectoryName(file)!, "*.incompleto-*").Where(f => !f.EndsWith("-wal", StringComparison.Ordinal) && !f.EndsWith("-shm", StringComparison.Ordinal)).ToList());
|
||||
}
|
||||
|
||||
File.Copy(away, file);
|
||||
await server.WaitForAsync(HostMode.Ready);
|
||||
}
|
||||
|
||||
@@ -325,6 +325,9 @@ public sealed class RestoreTests
|
||||
Assert.IsNotEmpty(await rig.QueryAsync("SELECT id FROM orders WHERE reason = 'rebuilt from the broker'", r => r.Id("id")), "Interrupted after the orders.");
|
||||
Assert.AreEqual("stopped", (await settings.GetAsync(SettingsStore.BotState.Key)).Value, "The protection comes before the first row.");
|
||||
|
||||
// One of them was cut right after its row: it still has no state.
|
||||
await rig.Db.WriteAsync(s => s.ExecuteAsync("UPDATE orders SET status = 'created', filled_quantity = 0 WHERE reason = 'rebuilt from the broker' AND purpose <> 'stop'", _none), _none);
|
||||
|
||||
// The last execution made it into the ledger: what comes before it is still to be read.
|
||||
var last = (await a.Paper.GetFillsAsync(DateTimeOffset.MinValue, _none)).MaxBy(f => f.ExecutedAt)!;
|
||||
await rig.Ledger.RecordFillAsync(new LedgerFill(a.Context.AccountId, a.Eth.Id, StrategyNames.CryptoTrend, last.ExecutionId, last.Side, last.Quantity, last.Price, last.Fee,
|
||||
@@ -333,6 +336,7 @@ public sealed class RestoreTests
|
||||
// The next attempt knows every order already, and finishes all the same.
|
||||
await service.RebuildAsync(manager, _none);
|
||||
await a.SameLedgerAsync(rig, "The ledger is the one that was lost, stops included.");
|
||||
Assert.IsEmpty(await rig.QueryAsync("SELECT id FROM orders WHERE status = 'created'", r => r.Id("id")), "Every rebuilt order has the state the broker says.");
|
||||
await new Reconciler(rig.Db, rig.Clock, rig.Ledger).ReconcileAsync(manager, _none);
|
||||
await manager.AlignStopsAsync(_none);
|
||||
CollectionAssert.AreEqual(stops, (await a.Paper.GetOpenOrdersAsync(_none)).Select(o => o.ClientOrderId).Order(StringComparer.Ordinal).ToList(), "No stop was touched.");
|
||||
@@ -474,14 +478,31 @@ public sealed class RestoreTests
|
||||
|
||||
await using var restored = await rig.RestoreAsync(archive);
|
||||
await Installation.RenewAsync(restored.Db, new DataDirectory(Path.Combine(folder, "data")), restored.Clock, "Salvataggio ripristinato", _none);
|
||||
var again = restored.Manager(broker, context, splits: SplitsAsync);
|
||||
var asked = new List<(string Symbols, DateOnly Since)>();
|
||||
var photographs = new List<decimal>();
|
||||
var down = true;
|
||||
var again = restored.Manager(broker, context, splits: async (i, ct) => down ? [] : await SplitsAsync(i, ct), refreshSplits: (symbols, since, _) =>
|
||||
{
|
||||
asked.Add((string.Join(',', symbols), since));
|
||||
return down ? throw new MarketDataException("rete giù") : Task.CompletedTask;
|
||||
}, afterFills: async ct => photographs.Add((await restored.Ledger.PositionAsync(context.AccountId, msft.Id, StrategyNames.EquityMomentum, ct))!.Quantity));
|
||||
again.AwaitingRebuild = true;
|
||||
again.StopGeneration = restored.Clock.UtcNow.UtcTicks;
|
||||
var known = await restored.QueryAsync("SELECT id FROM fills", r => r.Id("id"));
|
||||
await Assert.ThrowsExactlyAsync<MarketDataException>(() => again.RebuildAsync(_none));
|
||||
Assert.IsTrue(again.AwaitingRebuild, "Without the splits nothing is replayed.");
|
||||
Assert.HasCount(known.Count, await restored.QueryAsync("SELECT id FROM fills", r => r.Id("id")));
|
||||
down = false;
|
||||
var report = await again.RebuildAsync(_none);
|
||||
Assert.AreEqual(2, asked.Count(a => a == ("MSFT", new DateOnly(2026, 11, 9))), "Back to a day before the last execution of the archive.");
|
||||
CollectionAssert.AreEqual(new[] { 22m }, photographs, "One photograph, when every split is in its place.");
|
||||
Assert.IsEmpty(report.Unclear, string.Join(" | ", report.Unclear));
|
||||
var position = (await restored.Ledger.PositionAsync(context.AccountId, msft.Id, StrategyNames.EquityMomentum, _none))!;
|
||||
Assert.AreEqual((22m, 180m), (position.Quantity, position.StopPrice));
|
||||
Assert.IsEmpty(await restored.QueryAsync("SELECT message FROM notifications WHERE kind = 'ledger_refused_fill'", r => r.Text("message")));
|
||||
Assert.HasCount(1, await restored.QueryAsync("SELECT id FROM applied_actions WHERE source_key = 'split-msft'", r => r.Id("id")));
|
||||
await again.RebuildAsync(_none);
|
||||
Assert.HasCount(2, asked, "Nothing new to write: no need to ask.");
|
||||
var reconciled = await new Reconciler(restored.Db, restored.Clock, restored.Ledger).ReconcileAsync(again, _none);
|
||||
Assert.IsEmpty(reconciled.Differences, string.Join(" | ", reconciled.Differences.Select(d => d.Message)));
|
||||
}
|
||||
@@ -491,12 +512,261 @@ public sealed class RestoreTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task StoppingAnAccountNotRebuiltYetKeepsTheStopOfAPurchase()
|
||||
{
|
||||
// The purchase filled and the engine died before reading it; "Ferma tutto" comes while the account waits.
|
||||
await using var a = await Account.OpenAsync();
|
||||
a.Rig.Refresh();
|
||||
await a.Manager.SubmitAsync(new TradeIntent(a.Btc.Id, StrategyNames.CryptoTrend, OrderSide.Buy, 0.01m, OrderPurpose.Entry, Ids.NewId(a.Rig.Clock)) { StopLevel = 57_000m, StartAggressive = true }, _none);
|
||||
a.Broker.FailFillsAt = 2;
|
||||
await Assert.ThrowsExactlyAsync<BrokerException>(() => a.Manager.TickAsync(_none));
|
||||
a.Rig.Refresh();
|
||||
await a.Paper.PumpAsync(_none);
|
||||
|
||||
var manager = a.Rig.Manager(a.Broker, a.Context);
|
||||
manager.AwaitingRebuild = true;
|
||||
Assert.IsEmpty(await manager.CancelWorkingAsync("manual_stop"));
|
||||
await manager.RebuildAsync(_none);
|
||||
Assert.HasCount(1, await manager.CancelWorkingAsync(LiveReasons.Restart));
|
||||
Assert.AreEqual(57_000m, (await a.Rig.Ledger.PositionAsync(a.Context.AccountId, a.Btc.Id, StrategyNames.CryptoTrend, _none))!.StopPrice);
|
||||
Assert.AreEqual(57_000m, (await a.Paper.GetOpenOrdersAsync(_none)).Single().StopPrice);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task ExecutionsOfWhileTheBotWasOffComeBeforeTheSplitsAndTheDividends()
|
||||
{
|
||||
await using var rig = await TradingRig.CreateAsync();
|
||||
var context = await rig.AccountAsync(Venues.Alpaca, TradingEnvironments.Demo);
|
||||
var msft = await rig.InstrumentAsync(TradingRig.Stock("MSFT"));
|
||||
var nvda = await rig.InstrumentAsync(TradingRig.Stock("NVDA"));
|
||||
var paper = rig.Paper(PaperOptions.Alpaca(), context.AccountId, persist: false);
|
||||
await paper.DepositAsync(100_000m, "USD", _none);
|
||||
await rig.Ledger.RecordCapitalAsync(context.AccountId, StrategyNames.EquityMomentum, 100_000m, "USD", "test", _none);
|
||||
var broker = new FaultyBroker(paper, TradingEnvironments.Demo);
|
||||
using var service = Service(rig);
|
||||
Task<IReadOnlyList<CorporateAction>> SplitsAsync(Instrument i, CancellationToken ct) => rig.Db.ReadAsync<IReadOnlyList<CorporateAction>>(async s =>
|
||||
[.. await s.QueryAsync("SELECT source_key FROM corporate_actions WHERE symbol = @s AND kind = 'split'", r => new CorporateAction(i.Symbol, "split", new DateOnly(2026, 11, 12), "test", r.Text("source_key")) { Ratio = 10m }, ("s", i.Symbol))], ct);
|
||||
OrderManager Manager() => rig.Manager(broker, context, splits: SplitsAsync);
|
||||
async Task TurnsAsync(OrderManager manager)
|
||||
{
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
rig.Refresh();
|
||||
await paper.PumpAsync(_none);
|
||||
await manager.TickAsync(_none);
|
||||
rig.Clock.Advance(_minute);
|
||||
}
|
||||
}
|
||||
|
||||
Task<(Guid?, string?)> BuyAsync(OrderManager manager, Instrument instrument, decimal quantity) => manager.SubmitAsync(
|
||||
new TradeIntent(instrument.Id, StrategyNames.EquityMomentum, OrderSide.Buy, quantity, OrderPurpose.Entry, Ids.NewId(rig.Clock)) { StopLevel = 360m, StartAggressive = true }, _none);
|
||||
|
||||
// 10 MSFT with their stop; NVDA bought and sold before, then bought again: filled, and the engine dies before reading it.
|
||||
rig.Quote("MSFT", 399.9m, 400m);
|
||||
rig.Quote("NVDA", 399.9m, 400m);
|
||||
var first = Manager();
|
||||
await BuyAsync(first, msft, 10m);
|
||||
await TurnsAsync(first);
|
||||
await rig.Ledger.RecordFillAsync(rig.Fill(context, nvda, StrategyNames.EquityMomentum, OrderSide.Buy, 1m, 400m, feeCurrency: "USD"), _none);
|
||||
await rig.Ledger.RecordFillAsync(rig.Fill(context, nvda, StrategyNames.EquityMomentum, OrderSide.Sell, 1m, 400m, feeCurrency: "USD"), _none);
|
||||
rig.Clock.Advance(_minute);
|
||||
await BuyAsync(first, nvda, 10m);
|
||||
broker.FailFillsAt = 2;
|
||||
await Assert.ThrowsExactlyAsync<BrokerException>(() => first.TickAsync(_none));
|
||||
rig.Refresh();
|
||||
await paper.PumpAsync(_none);
|
||||
|
||||
// Off: the stop of MSFT fires on Wednesday; Thursday, 10-for-1 for both and a dividend of MSFT.
|
||||
rig.Clock.Advance(TimeSpan.FromDays(1));
|
||||
rig.Quote("MSFT", 350m, 350.1m);
|
||||
await paper.PumpAsync(_none);
|
||||
rig.Clock.Advance(TimeSpan.FromDays(1));
|
||||
rig.Quote("MSFT", 35m, 35.01m);
|
||||
rig.Quote("NVDA", 40m, 40.01m);
|
||||
await rig.Db.WriteAsync(async s =>
|
||||
{
|
||||
foreach (var (symbol, kind, ratio, cash) in new[] { ("MSFT", "split", (decimal?)10m, (decimal?)null), ("NVDA", "split", 10m, null), ("MSFT", "cash_dividend", null, 1m) })
|
||||
{
|
||||
await s.ExecuteAsync("INSERT INTO corporate_actions (id, symbol, kind, ex_date, ratio, cash_amount, currency, source, source_key, created_at) VALUES (@id, @s, @k, '2026-11-12', @r, @c, 'USD', 'test', @key, @now)",
|
||||
_none, ("id", Ids.NewId(rig.Clock)), ("s", symbol), ("k", kind), ("r", ratio), ("c", cash), ("key", kind + symbol), ("now", rig.Clock.UtcNow));
|
||||
}
|
||||
}, _none);
|
||||
|
||||
var second = Manager();
|
||||
second.AwaitingRebuild = true;
|
||||
|
||||
var report = await second.RebuildAsync(_none);
|
||||
Assert.AreEqual(0, report.Orders);
|
||||
await service.CorporateActionsAsync(second, _none);
|
||||
Assert.AreEqual(0m, (await rig.Ledger.PositionAsync(context.AccountId, msft.Id, StrategyNames.EquityMomentum, _none))?.Quantity ?? 0m, "The stop sold the 10 old shares.");
|
||||
Assert.AreEqual(100m, (await rig.Ledger.PositionAsync(context.AccountId, nvda.Id, StrategyNames.EquityMomentum, _none))!.Quantity, "The purchase finds its split.");
|
||||
Assert.IsEmpty(await rig.QueryAsync("SELECT id FROM cash_ledger WHERE kind = 'dividend'", r => r.Id("id")), "Sold before the ex-date: nothing is owed.");
|
||||
Assert.IsEmpty(await rig.QueryAsync("SELECT id FROM executions WHERE purpose = 'protective'", r => r.Id("id")));
|
||||
Assert.IsNotEmpty(await rig.QueryAsync("SELECT id FROM notifications WHERE kind = 'fill' AND message LIKE '%Vend%MSFT%'", r => r.Id("id")), "The sale of the stop reaches the phone.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task TheRestOfAStopThatFiredInPartWhileOffIsSold()
|
||||
{
|
||||
await using var rig = await TradingRig.CreateAsync();
|
||||
var context = await rig.AccountAsync(Venues.Alpaca, TradingEnvironments.Demo);
|
||||
var msft = await rig.InstrumentAsync(TradingRig.Stock("MSFT"));
|
||||
var paper = rig.Paper(PaperOptions.Alpaca(), context.AccountId, persist: false);
|
||||
await paper.DepositAsync(100_000m, "USD", _none);
|
||||
await rig.Ledger.RecordCapitalAsync(context.AccountId, StrategyNames.EquityMomentum, 100_000m, "USD", "test", _none);
|
||||
var broker = new FaultyBroker(paper, TradingEnvironments.Demo);
|
||||
var first = rig.Manager(broker, context);
|
||||
rig.Quote("MSFT", 399.9m, 400m);
|
||||
await first.SubmitAsync(new TradeIntent(msft.Id, StrategyNames.EquityMomentum, OrderSide.Buy, 1.5m, OrderPurpose.Entry, Ids.NewId(rig.Clock)) { StopLevel = 360m, StartAggressive = true }, _none);
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
rig.Refresh();
|
||||
await paper.PumpAsync(_none);
|
||||
await first.TickAsync(_none);
|
||||
rig.Clock.Advance(_minute);
|
||||
}
|
||||
|
||||
// The stop of the fraction is a day order and is over; that of the whole share fires while the bot is off.
|
||||
var stops = await paper.GetOpenOrdersAsync(_none);
|
||||
Assert.HasCount(2, stops);
|
||||
await paper.CancelOrderAsync(stops.Single(o => o.Quantity == 0.5m).ClientOrderId, "MSFT", _none);
|
||||
rig.Clock.Advance(TimeSpan.FromHours(1));
|
||||
rig.Quote("MSFT", 350m, 350.1m);
|
||||
await paper.PumpAsync(_none);
|
||||
|
||||
var second = rig.Manager(broker, context);
|
||||
second.AwaitingRebuild = true;
|
||||
await second.RebuildAsync(_none);
|
||||
Assert.AreEqual(0.5m, (await rig.QueryAsync("SELECT quantity FROM executions WHERE purpose = 'protective' AND status = 'working'", r => r.Money("quantity"))).Single());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task TheProtectiveSalesOfTheArchiveAreNotContinued()
|
||||
{
|
||||
await using var a = await Account.OpenAsync();
|
||||
await a.BuyAsync(a.Btc, 0.01m, 57_000m);
|
||||
await a.Manager.SubmitAsync(new TradeIntent(a.Btc.Id, StrategyNames.CryptoTrend, OrderSide.Sell, 0.01m, OrderPurpose.Protective, Ids.NewId(a.Rig.Clock)), _none);
|
||||
var simulated = await a.Rig.AccountAsync(Venues.Okx, TradingEnvironments.Simulation);
|
||||
await a.Rig.Manager(a.Rig.Paper(PaperOptions.Okx(), simulated.AccountId, persist: false), simulated)
|
||||
.SubmitAsync(new TradeIntent(a.Btc.Id, StrategyNames.CryptoTrend, OrderSide.Sell, 0.01m, OrderPurpose.Protective, Ids.NewId(a.Rig.Clock)), _none);
|
||||
var (rig, _) = await a.RestoreAsync(await a.ArchiveAsync());
|
||||
async Task<string> StatusAsync(Guid account) => (await rig.QueryAsync("SELECT status FROM executions WHERE account_id = @a AND purpose = 'protective'", r => r.Text("status"), ("a", account))).Single();
|
||||
Assert.AreEqual(ExecutionStates.Canceled, await StatusAsync(a.Context.AccountId));
|
||||
Assert.AreEqual(ExecutionStates.Working, await StatusAsync(simulated.AccountId), "The simulator went back in time with its sales.");
|
||||
|
||||
// One of an execution that is over, still open on the account, is canceled there too.
|
||||
a.Rig.Refresh();
|
||||
await a.Manager.CancelWorkingAsync("prova");
|
||||
await a.Rig.Db.WriteAsync(s => s.ExecuteAsync("UPDATE executions SET status = 'canceled' WHERE status = 'working'", _none), _none);
|
||||
await a.Manager.SubmitAsync(new TradeIntent(a.Btc.Id, StrategyNames.CryptoTrend, OrderSide.Sell, 0.004m, OrderPurpose.Exit, Ids.NewId(a.Rig.Clock)), _none);
|
||||
await a.Manager.TickAsync(_none);
|
||||
Assert.HasCount(1, (await a.Paper.GetOpenOrdersAsync(_none)).Where(o => o.Kind == OrderKind.Limit).ToList());
|
||||
await a.Rig.Db.WriteAsync(s => s.ExecuteAsync("UPDATE executions SET status = 'canceled' WHERE status = 'working'", _none), _none);
|
||||
await a.Rig.Manager(a.Broker, a.Context).RebuildAsync(_none);
|
||||
Assert.IsEmpty((await a.Paper.GetOpenOrdersAsync(_none)).Where(o => o.Kind == OrderKind.Limit).ToList());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task ProtectionFromTheLoopStopsTheOtherAccountsAndKeepsWhatIsOfToday()
|
||||
{
|
||||
await using var a = await Account.OpenAsync();
|
||||
await a.BuyAsync(a.Btc, 0.01m, 57_000m);
|
||||
var archive = await a.ArchiveAsync();
|
||||
await a.SellAsync(a.Btc, 0.003m);
|
||||
|
||||
foreach (var (asked, kept) in new[] { ("2026-11-07T10:00:00+00:00", false), ("2026-12-31T10:00:00+00:00", true) })
|
||||
{
|
||||
var rig = await a.Rig.RestoreAsync(archive);
|
||||
a.Restored.Add(rig);
|
||||
await rig.Db.WriteAsync(s => s.ExecuteAsync("UPDATE installation SET protected_restart = @no", _none, ("no", false)), _none);
|
||||
using var service = Service(rig);
|
||||
await service.StartAsync(_none);
|
||||
var simulator = service.Managers.Single(m => m.Account.Broker == Venues.Okx);
|
||||
rig.Clock.Advance(_minute);
|
||||
var (buy, _) = await simulator.SubmitAsync(new TradeIntent(a.Btc.Id, StrategyNames.CryptoTrend, OrderSide.Buy, 0.001m, OrderPurpose.Entry, Ids.NewId(rig.Clock)), _none);
|
||||
await AskCloseAllAsync(rig, asked);
|
||||
var manager = rig.Manager(a.Broker, a.Context);
|
||||
await service.RebuildAsync(manager, _none);
|
||||
Assert.AreEqual(ExecutionStates.Canceled, (await rig.QueryAsync("SELECT status FROM executions WHERE id = @id", r => r.Text("status"), ("id", buy))).Single());
|
||||
var state = (await rig.QueryAsync("SELECT state FROM risk_state WHERE world = 'bot'", r => r.Json("state").Text)).Single();
|
||||
Assert.AreEqual(kept, System.Text.Json.JsonDocument.Parse(state).RootElement.GetProperty("close_all").GetBoolean(), asked);
|
||||
Assert.HasCount(1, await rig.QueryAsync("SELECT message FROM notifications WHERE kind = 'protected_restart'", r => r.Text("message")));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task AnAttemptCutRightAfterTheProtectionStillNamesTheStopsAnew()
|
||||
{
|
||||
await using var a = await Account.OpenAsync();
|
||||
await a.BuyAsync(a.Btc, 0.01m, 57_000m);
|
||||
var archive = await a.ArchiveAsync();
|
||||
await a.SellAsync(a.Btc, 0.003m);
|
||||
var rig = await a.Rig.RestoreAsync(archive);
|
||||
a.Restored.Add(rig);
|
||||
await Installation.ProtectAsync(rig.Db, rig.Clock, rig.Clock.UtcNow, "prova", _none);
|
||||
using var service = Service(rig);
|
||||
var manager = rig.Manager(a.Broker, a.Context);
|
||||
await service.RebuildAsync(manager, _none);
|
||||
Assert.AreEqual((await Installation.ReadRowAsync(rig.Db, _none))!.RenewedAt.UtcTicks, manager.StopGeneration);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task AResumedRebuildOfTheGuardsStopsDoesNotStopTheBot()
|
||||
{
|
||||
await using var a = await Account.OpenAsync();
|
||||
await a.BuyAsync(a.Btc, 0.01m, 57_000m);
|
||||
var own = (await a.Paper.GetOpenOrdersAsync(_none)).Single();
|
||||
await a.Paper.CancelOrderAsync(own.ClientOrderId, own.Symbol, _none);
|
||||
Task PlaceAsync(int sequence) => a.Paper.SubmitOrderAsync(new OrderRequest(ClientOrderIds.Build(TradingRig.Installation, TradingEnvironments.Demo, StrategyNames.CryptoTrend,
|
||||
OrderPurpose.Stop, "GGGGGGGG", sequence), a.Btc.Symbol, OrderSide.Sell, OrderKind.Stop, own.Quantity / 2m, TimeInForce.Gtc)
|
||||
{ StopPrice = 57_000m }, _none);
|
||||
using var service = Service(a.Rig);
|
||||
await PlaceAsync(1);
|
||||
a.Broker.FailFillsAt = 2;
|
||||
await Assert.ThrowsExactlyAsync<BrokerException>(() => service.RebuildAsync(a.Manager, _none));
|
||||
await PlaceAsync(2);
|
||||
await service.RebuildAsync(a.Manager, _none);
|
||||
Assert.IsFalse((await Installation.ReadRowAsync(a.Rig.Db, _none))!.ProtectedRestart);
|
||||
Assert.IsEmpty(await a.Rig.QueryAsync("SELECT message FROM notifications WHERE kind = 'protected_restart'", r => r.Text("message")));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Simulation)]
|
||||
public async Task TheGuardCountsFromTheMomentTheFiguresOfTheAccountWereRead()
|
||||
{
|
||||
await using var a = await Account.OpenAsync();
|
||||
await a.BuyAsync(a.Btc, 0.01m, 57_000m);
|
||||
var known = await a.Manager.GuardAccountAsync(_none);
|
||||
var read = a.Rig.Clock.UtcNow;
|
||||
a.Rig.Clock.Advance(_minute);
|
||||
await a.SellAsync(a.Btc, 0.004m);
|
||||
var held = (await a.Rig.Ledger.PositionAsync(a.Context.AccountId, a.Btc.Id, StrategyNames.CryptoTrend, _none))!.Quantity;
|
||||
await a.Paper.SubmitOrderAsync(new OrderRequest("a-mano", a.Btc.Symbol, OrderSide.Buy, OrderKind.Market, 0.5m, TimeInForce.Gtc), _none);
|
||||
await a.TurnsAsync(a.Manager, 2);
|
||||
foreach (var stop in await a.Paper.GetOpenOrdersAsync(_none))
|
||||
{
|
||||
await a.Paper.CancelOrderAsync(stop.ClientOrderId, stop.Symbol, _none);
|
||||
}
|
||||
|
||||
var state = new Anubis.Supervision.GuardState(a.Rig.Clock.UtcNow, TradingRig.Installation, [known with { WrittenAt = read }]);
|
||||
var outcome = await Anubis.Supervision.GuardRepair.RunAsync(state, state.Accounts[0], a.Broker, a.Rig.Clock, _none);
|
||||
Assert.AreEqual(held, outcome.Placed.Single().Quantity, "What was sold after the figures, not what the user holds.");
|
||||
}
|
||||
|
||||
private static TradingService Service(TradingRig rig) => new(rig.Db, rig.Clock, new EventBus(), new SecretStore(rig.Db, rig.Clock, new byte[32]), null, new FxStore(rig.Db, rig.Clock),
|
||||
TradingConsent.None, new Guid("0193a7c0-0000-7000-8000-0000000000aa"), new FakeHttp());
|
||||
|
||||
private static Task<int> AskCloseAllAsync(TradingRig rig) => rig.Db.WriteAsync(s => s.ExecuteAsync(
|
||||
private static Task<int> AskCloseAllAsync(TradingRig rig, string since = "2026-11-07T10:00:00+00:00") => rig.Db.WriteAsync(s => s.ExecuteAsync(
|
||||
"INSERT INTO risk_state (id, world, state, created_at, updated_at) VALUES (@id, 'bot', @j, @t, @t)", _none,
|
||||
("id", Ids.NewId(rig.Clock)), ("j", new DbJson("{\"close_all\":true,\"close_all_since\":\"2026-11-07T10:00:00+00:00\"}")), ("t", rig.Clock.UtcNow)), _none);
|
||||
("id", Ids.NewId(rig.Clock)), ("j", new DbJson($"{{\"close_all\":true,\"close_all_since\":\"{since}\"}}")), ("t", rig.Clock.UtcNow)), _none);
|
||||
|
||||
private static async Task<int> CloseAllAsync(TradingRig rig, OrderManager manager)
|
||||
{
|
||||
|
||||
@@ -503,7 +503,7 @@ public sealed class RiskEngineTests
|
||||
("id", planned), ("a", live.Account.AccountId), ("i", s.Btc.Id), ("no", false), ("t", s.Rig.Clock.UtcNow)), _none);
|
||||
|
||||
await Installation.CheckAsync(s.Rig.Db, new DataDirectory(TempFolder.Create("reconfirm")), s.Rig.Clock, _none);
|
||||
await Installation.ProtectAsync(s.Rig.Db, s.Rig.Clock, _none);
|
||||
await Installation.ProtectAsync(s.Rig.Db, s.Rig.Clock, s.Rig.Clock.UtcNow, "prova", _none);
|
||||
|
||||
// Stopped, exit only, with its counts untouched; what was planned does not leave; the stop stays.
|
||||
Assert.AreEqual("stopped", (await s.Settings.GetAsync(SettingsStore.BotState.Key)).Value);
|
||||
|
||||
@@ -92,6 +92,10 @@ public sealed class TradingServiceTests
|
||||
await rig.Db.WriteAsync(s => s.ExecuteAsync("INSERT INTO corporate_actions (id, symbol, kind, ex_date, ratio, source, source_key, created_at) VALUES (@id, 'MSFT', 'split', '2026-11-11', @r, 'test', 'k', @now)",
|
||||
_none, ("id", Ids.NewId(rig.Clock)), ("r", 2m), ("now", rig.Clock.UtcNow)), _none).ConfigureAwait(false);
|
||||
rig.Clock.Advance(TimeSpan.FromDays(2));
|
||||
service.Quotes.Put(new Quote("MSFT", 200m, 200.10m, rig.Clock.UtcNow));
|
||||
await service.PhotographAsync(_none).ConfigureAwait(false);
|
||||
Assert.AreEqual(400m, (await service.Ledger.PositionAsync(paper.Account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!.LastPrice,
|
||||
"Old shares at the price of the new ones would be a loss that is not there.");
|
||||
var before = http.Requests.Count;
|
||||
await service.CorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
await service.ReconcileAllAsync(_none).ConfigureAwait(false);
|
||||
@@ -170,6 +174,10 @@ public sealed class TradingServiceTests
|
||||
Assert.AreEqual(10m, (await service.Ledger.PositionAsync(account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!.Quantity);
|
||||
|
||||
rig.Clock.Advance(TimeSpan.FromDays(1));
|
||||
service.Quotes.Put(new Quote("MSFT", 200m, 200.10m, rig.Clock.UtcNow));
|
||||
await service.PhotographAsync(_none).ConfigureAwait(false);
|
||||
Assert.AreEqual(400m, (await service.Ledger.PositionAsync(account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!.LastPrice,
|
||||
"The split is not applied yet: the photograph waits for it.");
|
||||
await service.CorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
await service.CorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
var position = (await service.Ledger.PositionAsync(account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!;
|
||||
@@ -189,4 +197,139 @@ public sealed class TradingServiceTests
|
||||
await service.PhotographAsync(_none).ConfigureAwait(false);
|
||||
Assert.AreEqual(230.05m, (await service.Ledger.PositionAsync(account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!.LastPrice);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task TheSimulatorsAbsenceMeetsASplitAtItsDate()
|
||||
{
|
||||
await using var rig = await TradingRig.CreateAsync().ConfigureAwait(false);
|
||||
using var service = Service(rig, new FakeHttp());
|
||||
var msft = await rig.InstrumentAsync(TradingRig.Stock("MSFT")).ConfigureAwait(false);
|
||||
await service.StartAsync(_none).ConfigureAwait(false);
|
||||
var manager = service.Managers.Single(m => m.Account.Broker == Venues.Alpaca);
|
||||
var paper = (PaperBroker)manager.Broker;
|
||||
await paper.DepositAsync(10_000m, "USD", _none).ConfigureAwait(false);
|
||||
await service.Ledger.RecordCapitalAsync(manager.Account.AccountId, StrategyNames.EquityMomentum, 10_000m, "USD", "test", _none).ConfigureAwait(false);
|
||||
await manager.SubmitAsync(new TradeIntent(msft.Id, StrategyNames.EquityMomentum, OrderSide.Buy, 10m, OrderPurpose.Entry, Ids.NewId(rig.Clock)) { StopLevel = 360m, StartAggressive = true }, _none)
|
||||
.ConfigureAwait(false);
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
service.Quotes.Put(new Quote("MSFT", 399.9m, 400m, rig.Clock.UtcNow));
|
||||
await paper.PumpAsync(_none).ConfigureAwait(false);
|
||||
await manager.TickAsync(_none).ConfigureAwait(false);
|
||||
rig.Clock.Advance(TimeSpan.FromSeconds(20));
|
||||
}
|
||||
|
||||
Assert.HasCount(1, await paper.GetOpenOrdersAsync(_none).ConfigureAwait(false));
|
||||
|
||||
// Off. Wednesday it falls through the stop and comes back; Thursday 2-for-1 and a dividend.
|
||||
var day = new DateTimeOffset(2026, 11, 11, 16, 0, 0, TimeSpan.Zero);
|
||||
await new BarStore(rig.Db, rig.Clock).UpsertMinuteAsync(msft.Id, [new Bar(day, 365, 366, 350, 364, 1000), new Bar(day.AddDays(1), 199, 201, 198, 200, 1000)], "test", BarQuality.Ok, _none)
|
||||
.ConfigureAwait(false);
|
||||
await rig.Db.WriteAsync(async s =>
|
||||
{
|
||||
foreach (var (kind, ratio, cash) in new[] { ("split", (decimal?)2m, (decimal?)null), ("cash_dividend", null, 1m) })
|
||||
{
|
||||
await s.ExecuteAsync("INSERT INTO corporate_actions (id, symbol, kind, ex_date, ratio, cash_amount, currency, source, source_key, created_at) VALUES (@id, 'MSFT', @k, '2026-11-12', @r, @c, 'USD', 'test', @k, @now)",
|
||||
_none, ("id", Ids.NewId(rig.Clock)), ("k", kind), ("r", ratio), ("c", cash), ("now", rig.Clock.UtcNow)).ConfigureAwait(false);
|
||||
}
|
||||
}, _none).ConfigureAwait(false);
|
||||
rig.Clock.Advance(TimeSpan.FromDays(3));
|
||||
await service.CatchUpAsync(manager, paper, _none).ConfigureAwait(false);
|
||||
await service.CorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
|
||||
Assert.IsEmpty(await service.Ledger.PositionsAsync(manager.Account.AccountId, _none).ConfigureAwait(false), "The stop of before the split met the prices of before it.");
|
||||
Assert.IsEmpty(await paper.GetPositionsAsync(_none).ConfigureAwait(false));
|
||||
Assert.IsEmpty(await rig.QueryAsync("SELECT id FROM cash_ledger WHERE kind = 'dividend'", r => r.Id("id")).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task UntilItIsRebuiltTheGuardKeepsWhatItKnewOfAnAccount()
|
||||
{
|
||||
await using var rig = await TradingRig.CreateAsync().ConfigureAwait(false);
|
||||
var folder = TempFolder.Create("guard-state");
|
||||
try
|
||||
{
|
||||
var paths = new Anubis.Supervision.GuardPaths(folder);
|
||||
var http = new FakeHttp().On(_ => true, _ => FakeHttp.Respond("{}", System.Net.HttpStatusCode.BadRequest));
|
||||
using var service = new TradingService(rig.Db, rig.Clock, new EventBus(), new SecretStore(rig.Db, rig.Clock, new byte[32],
|
||||
new Dictionary<string, string> { ["ALPACA_API_KEY_DEMO"] = "test-key", ["ALPACA_API_SECRET_DEMO"] = "test-secret" }), null, new FxStore(rig.Db, rig.Clock), TradingConsent.None,
|
||||
new Guid("0193a7c0-0000-7000-8000-0000000000aa"), http)
|
||||
{ GuardFiles = paths };
|
||||
var msft = await rig.InstrumentAsync(TradingRig.Stock("MSFT")).ConfigureAwait(false);
|
||||
await service.StartAsync(_none).ConfigureAwait(false);
|
||||
var account = service.Managers.Single(m => m.Account.Environment == TradingEnvironments.Demo).Account;
|
||||
await service.Ledger.RecordCapitalAsync(account.AccountId, StrategyNames.EquityMomentum, 5000m, "USD", "test", _none).ConfigureAwait(false);
|
||||
await service.Ledger.RecordFillAsync(rig.Fill(account, msft, StrategyNames.EquityMomentum, OrderSide.Buy, 10m, 400m, feeCurrency: "USD"), _none).ConfigureAwait(false);
|
||||
|
||||
// Nor is it valued at a price of today: the shares of the ledger may be those of another time.
|
||||
service.Quotes.Put(new Quote("MSFT", 200m, 200.10m, rig.Clock.UtcNow));
|
||||
await service.PhotographAsync(_none).ConfigureAwait(false);
|
||||
Assert.AreEqual(400m, (await service.Ledger.PositionAsync(account.AccountId, msft.Id, StrategyNames.EquityMomentum, _none).ConfigureAwait(false))!.LastPrice);
|
||||
async Task<(DateTimeOffset At, Anubis.Supervision.GuardAccount Account)> WrittenAsync()
|
||||
{
|
||||
await service.WriteGuardStateAsync(_none).ConfigureAwait(false);
|
||||
var state = Anubis.Supervision.GuardFiles.ReadState(paths)!;
|
||||
return (state.WrittenAt, state.Accounts.Single(a => a.AccountId == account.AccountId));
|
||||
}
|
||||
|
||||
Assert.IsEmpty((await WrittenAsync().ConfigureAwait(false)).Account.Positions, "Nothing known: no stop is put on a ledger that may be old.");
|
||||
|
||||
// What the last state said, with its time, however often it is written again.
|
||||
var first = rig.Clock.UtcNow;
|
||||
var known = (await WrittenAsync().ConfigureAwait(false)).Account with { Positions = [new Anubis.Supervision.GuardPosition(msft.Id, "MSFT", StrategyNames.EquityMomentum, 4m, 380m, 0.0001m, false, "KKKKKKKK", 3)] };
|
||||
Anubis.Supervision.GuardFiles.WriteState(paths, new Anubis.Supervision.GuardState(first, service.InstallationCode, [known with { WrittenAt = null }]));
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
rig.Clock.Advance(TimeSpan.FromSeconds(10));
|
||||
var (at, again) = await WrittenAsync().ConfigureAwait(false);
|
||||
Assert.AreEqual(rig.Clock.UtcNow, at);
|
||||
Assert.AreEqual((4m, first), (again.Positions.Single().Quantity, again.WrittenAt!.Value));
|
||||
}
|
||||
|
||||
// Of another installation: not of this account's past.
|
||||
Anubis.Supervision.GuardFiles.WriteState(paths, new Anubis.Supervision.GuardState(first, "OTHR", [known]));
|
||||
Assert.IsEmpty((await WrittenAsync().ConfigureAwait(false)).Account.Positions);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TempFolder.Delete(folder);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task SplitsAndDividendsAreAskedAlsoForWhatLeftTheUniverse()
|
||||
{
|
||||
await using var rig = await TradingRig.CreateAsync().ConfigureAwait(false);
|
||||
var http = new FakeHttp().On(_ => true, _ => FakeHttp.Respond("{\"corporate_actions\":{},\"next_page_token\":null}"));
|
||||
var bus = new EventBus();
|
||||
var secrets = new SecretStore(rig.Db, rig.Clock, new byte[32], new Dictionary<string, string> { ["ALPACA_API_KEY_DEMO"] = "test-key", ["ALPACA_API_SECRET_DEMO"] = "test-secret" });
|
||||
using var market = new MarketDataService(rig.Db, rig.Clock, bus, new SettingsStore(rig.Db, rig.Clock, bus), secrets, null, http);
|
||||
await market.RefreshCorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
Assert.IsEmpty(http.Requests, "Nothing to ask about.");
|
||||
|
||||
var account = await rig.AccountAsync(Venues.Alpaca, TradingEnvironments.Demo).ConfigureAwait(false);
|
||||
await rig.Ledger.RecordCapitalAsync(account.AccountId, StrategyNames.EquityMomentum, 5000m, "USD", "test", _none).ConfigureAwait(false);
|
||||
foreach (var (symbol, sold) in new[] { ("MSFT", false), ("NVDA", true), ("OLDX", true) })
|
||||
{
|
||||
var stock = await rig.InstrumentAsync(TradingRig.Stock(symbol)).ConfigureAwait(false);
|
||||
var buy = rig.Fill(account, stock, StrategyNames.EquityMomentum, OrderSide.Buy, 1m, 400m, feeCurrency: "USD");
|
||||
var sell = rig.Fill(account, stock, StrategyNames.EquityMomentum, OrderSide.Sell, 1m, 400m, feeCurrency: "USD");
|
||||
var at = rig.Clock.UtcNow - TimeSpan.FromDays(symbol == "OLDX" ? 120 : 30);
|
||||
await rig.Ledger.RecordFillAsync(buy with { ExecutedAt = at }, _none).ConfigureAwait(false);
|
||||
if (sold)
|
||||
{
|
||||
await rig.Ledger.RecordFillAsync(sell with { ExecutedAt = at.AddDays(1) }, _none).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await market.RefreshCorporateActionsAsync(_none).ConfigureAwait(false);
|
||||
StringAssert.Contains(http.Requests[^1].RequestUri!.Query, "symbols=MSFT%2CNVDA&");
|
||||
StringAssert.Contains(http.Requests[^1].RequestUri!.Query, "start=2026-11-03&");
|
||||
await market.RefreshCorporateActionsAsync(["NEWX"], new DateOnly(2026, 10, 20), _none).ConfigureAwait(false);
|
||||
StringAssert.Contains(http.Requests[^1].RequestUri!.Query, "symbols=MSFT%2CNEWX%2CNVDA&");
|
||||
StringAssert.Contains(http.Requests[^1].RequestUri!.Query, "start=2026-10-13&");
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,8 @@ 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<IReadOnlyList<CorporateAction>>>? splits = null)
|
||||
Func<Instrument, CancellationToken, Task<CorporateAction?>>? pendingSplit = null, Func<Instrument, CancellationToken, Task<IReadOnlyList<CorporateAction>>>? splits = null,
|
||||
Func<IReadOnlyCollection<string>, DateOnly, CancellationToken, Task>? refreshSplits = null, Func<CancellationToken, Task>? afterFills = null)
|
||||
{
|
||||
var manager = new OrderManager(Db, Clock, Ledger, broker, account, Installation, FindAsync, QuoteAsync)
|
||||
{
|
||||
@@ -123,6 +124,8 @@ internal sealed class TradingRig : IAsyncDisposable
|
||||
MarketOpen = marketOpen ?? ((_, _) => Task.FromResult(true)),
|
||||
PendingSplit = pendingSplit,
|
||||
Splits = splits,
|
||||
RefreshSplits = refreshSplits,
|
||||
AfterFills = afterFills,
|
||||
};
|
||||
_owned.Add(manager);
|
||||
return manager;
|
||||
|
||||
Reference in new issue
Block a user