Apply the SPEC 10.5 news and calendar rules to new entries (refs #59)
ci / test (postgres) (push) Successful in 8m20s
ci / test (sqlite) (push) Successful in 4m25s
ci / test (postgres) (pull_request) Successful in 8m13s
ci / test (sqlite) (pull_request) Successful in 4m38s
ci / image (push) Successful in 2m5s
ci / image (pull_request) Successful in 2m6s

Confirmed serious events hold new purchases of an instrument for 72 hours
and keep its stop where it is; confirmed negative news holds them for 24
hours; an unconfirmed rumour only gets a diary note and a check two hours
later. Coming earnings keep mean reversion out and macro figures hold
entries around their release, now in the live engine too. The strictest
row wins, every row can be switched off in the settings, and windows count
from the fact, so after an absence only effects still in force apply.

A held purchase moves to the end of its restriction while the order is
still valid and keeps its first due time, so the price drift check of
SPEC 5.6 still compares with the decision. Each restriction is written to
the diary once, with its motive. The per-instrument state keeps the tone
over one and three days, the story count against its norm and the active
restriction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-16 17:39:26 +01:00
1 parent 1aede2fc1c
commit b087dd215b
21 files changed
+1170 -30

No files matched your search

+56
View File
@@ -132,6 +132,62 @@ public sealed class AbsenceTests
CollectionAssert.AreEqual(new[] { "crypto_trend:2026-09-02" }, runs.ToList());
}
/// <summary>
/// The row of 5.6 on news and calendar: back after 51 hours, at 02:00 UTC of 3 September, the bot reads the backlog
/// of the news. An effect still in force applies (a serious event on ETH published 44 hours before, 72 hours long);
/// one already over does not (a negative story on SOL 25 hours old, 24 hours long), nor a figure of the day before.
/// The crypto decision of the night is still made, and it buys no ETH.
/// </summary>
[TestMethod]
public async Task AfterTwoDaysOffOnlyTheNewsEffectsStillInForceApply()
{
await using var live = await LiveRig.CreateAsync(LiveFrom, LiveFrom.AddDays(39)).ConfigureAwait(false);
var db = live.Rig.Db;
var clock = live.Rig.Clock;
live.UseGate(new News.EntryGate(db, clock));
var back = Off.AddHours(51);
await RestartAsync(live.Rig, back).ConfigureAwait(false);
foreach (var coin in new[] { "ETH-EUR", "SOL-EUR" })
{
await db.WriteAsync(s => s.ExecuteAsync("INSERT INTO universe_members (id, universe, as_of, instrument_id, rank, created_at) VALUES (@id, @u, '2026-09-02', @i, 1, @now)", _none,
("id", Ids.NewId(clock)), ("u", Universes.Crypto), ("i", live.Instruments[coin].Id), ("now", back)), _none).ConfigureAwait(false);
}
// The backlog, read at the restart.
var eth = live.Instruments["ETH-EUR"].Spec;
var sol = live.Instruments["SOL-EUR"].Spec;
await NewsRulesTests.StoryAsync(db, clock, eth, "Ethereum bridge exploited", back.AddHours(-44), 4, -0.9, "CoinDesk", trusted: true).ConfigureAwait(false);
await NewsRulesTests.StoryAsync(db, clock, sol, "Solana outage halts the network", back.AddHours(-25), 3, -0.8, "CoinDesk", trusted: true).ConfigureAwait(false);
await new CalendarEventStore(db, clock).UpsertAsync(
[new CalendarEvent(CalendarEventKinds.Economic, "Inflazione USA", back.AddHours(-13.5), true, "test", "cpi") { Currency = "USD", Impact = "High" }], _none).ConfigureAwait(false);
Assert.AreEqual(1, await new News.NewsWatcher(db, clock).RunOnceAsync(_none).ConfigureAwait(false));
Assert.AreEqual("Ho messo una restrizione per 72 ore: niente nuovi acquisti di ETH/EUR. Motivo: «Ethereum bridge exploited» (CoinDesk).",
(await DiaryAsync(live.Rig).ConfigureAwait(false))[^1]);
var gate = new News.EntryGate(db, clock);
var held = await gate.HoldAsync(eth, back, _none).ConfigureAwait(false);
Assert.AreEqual(News.NewsReasons.Severe, held!.Code);
Assert.AreEqual(back.AddHours(28), held.Until);
Assert.IsNull(await gate.HoldAsync(sol, back, _none).ConfigureAwait(false), "The 24 hours of SOL ended while the bot was off.");
Assert.IsNull(await gate.HoldAsync(live.Instruments["BTC-EUR"].Spec, back, _none).ConfigureAwait(false), "The figure was yesterday.");
for (var day = LiveFrom.AddDays(-1); day <= LiveFrom.AddDays(1); day = day.AddDays(1))
{
await live.StoreBarAsync(day).ConfigureAwait(false);
}
live.Quotes(LiveFrom.AddDays(2), b => b.Open);
await live.MinutesAsync(10).ConfigureAwait(false);
var runs = await live.Rig.QueryAsync("SELECT run_key, mode FROM engine_runs", r => (r.Text("run_key"), r.Text("mode"))).ConfigureAwait(false);
CollectionAssert.AreEqual(new[] { ("crypto_trend:2026-09-02", DecisionModes.Full) }, runs.ToList());
Assert.IsFalse((await live.LiveFillsAsync().ConfigureAwait(false)).Any(f => f is { Symbol: "ETH-EUR", Side: OrderSide.Buy }));
var news = await live.Rig.QueryAsync("SELECT symbol, reasons FROM decisions WHERE stage = @c", r => (Symbol: r.TextOrNull("symbol"), Reasons: r.Text("reasons")),
("c", DecisionStages.Correctives)).ConfigureAwait(false);
Assert.IsFalse(news.Any(n => n.Symbol == "SOL-EUR" && n.Reasons.Contains("news_", StringComparison.Ordinal)), "No rule acts on SOL.");
Assert.IsTrue(news.Any(n => n.Symbol == "ETH-EUR" && n.Reasons.Contains(News.NewsReasons.Severe, StringComparison.Ordinal)), "The purchase of ETH was proposed and held back.");
Assert.IsTrue((await live.LiveFillsAsync().ConfigureAwait(false)).Any(f => f is { Symbol: "SOL-EUR", Side: OrderSide.Buy }), "SOL is bought as the strategy decided.");
}
private sealed class Counts
{
public int Backups { get; set; }