Show data sources and the central bank list in Settings (refs #22)

A "Dati" section lists every external source with its state, last answer
and the reason it is off (Alpaca without the paper keys, FRED and Finnhub
without theirs), links the 30-day quality report, and edits the Fed/ECB
meeting list; a list that does not parse is refused with an example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-10 15:45:06 +01:00
1 parent 1e71038209
commit 4a65d4060f
4 files changed
+99 -2

No files matched your search

+4
View File
@@ -203,6 +203,10 @@ code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-siz
height: 40px; border: 1px solid var(--control); border-radius: 8px; background: var(--surface); color: var(--text);
font: inherit; font-size: 14px; padding: 0 12px;
}
textarea {
border: 1px solid var(--control); border-radius: 8px; background: var(--surface); color: var(--text);
font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; padding: 8px 12px; resize: vertical;
}
.currency select { appearance: none; padding: 0 40px 0 16px; font-weight: 550; cursor: pointer; }
.select-chevron { position: absolute; right: 14px; top: 12px; pointer-events: none; color: var(--text-2); }
@@ -3,6 +3,7 @@
@inject AnubisHost Host
@inject ShellData Shell
@inject SecondFactorDrafts Drafts
@inject Anubis.Core.IClock Clock
<PageTitle>Impostazioni · Anubis</PageTitle>
@@ -24,7 +25,7 @@
}
<nav class="tabs" aria-label="Sezioni delle impostazioni">
<a href="#aspetto">Aspetto</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
<a href="#aspetto">Aspetto</a><a href="#dati">Dati</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
</nav>
<section class="panel" id="aspetto">
@@ -55,6 +56,51 @@
<p class="hint">Gli importi in dollari usano il cambio del giorno, che arriva con i dati di mercato. Fino ad allora restano in euro.</p>
</section>
<section class="panel" id="dati">
<h2>Dati</h2>
@if (Host.Services!.MarketData is not { } market)
{
<p class="note">@(Shell.IsDemo ? "Nella modalità dimostrativa i dati di mercato non si scaricano." : "La raccolta dei dati di mercato è spenta (ANUBIS_MARKET_DATA).")</p>
}
else
{
<dl class="facts">
<dt>Prezzi crypto in diretta</dt><dd>@(market.LiveConnected ? "collegati" : "non collegati")</dd>
<dt>Ultimo giro dello storico</dt><dd>@(market.LastHistoryRun is { } run ? Format.ShortDate(run, Shell.Now, Shell.Zone) : "in corso o non ancora fatto")</dd>
</dl>
}
@if (_sources.Count > 0)
{
<h3>Fonti</h3>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Fonte</th><th scope="col">Stato</th><th scope="col">Ultima risposta</th><th scope="col">Note</th></tr></thead>
<tbody>
@foreach (var s in _sources)
{
<tr>
<td>@SourceName(s.Source)</td>
<td>@(!s.Enabled ? "spenta" : s.LastError is null ? "attiva" : "in errore")</td>
<td class="nowrap">@(s.LastSuccessAt is { } at ? Format.ShortDate(at, Shell.Now, Shell.Zone) : "—")</td>
<td>@(s.LastError ?? s.Note)</td>
</tr>
}
</tbody>
</table>
</div>
}
<p class="hint"><a href="/api/data/quality?format=md&amp;days=30">Rapporto sulla qualità dei dati degli ultimi 30 giorni</a></p>
<h3>Riunioni di Fed e BCE</h3>
<form method="post" action="/azioni/impostazioni/@SettingsStore.CentralBankMeetings.Key" class="form">
<AntiforgeryToken />
<input type="hidden" name="ritorno" value="/impostazioni#dati" />
<label for="riunioni">Un giorno di decisione per riga, per esempio «FED 2027-01-27» o «BCE 2027-02-04». Aggiungi le date del nuovo anno quando le banche le pubblicano.</label>
<textarea id="riunioni" name="valore" rows="8" spellcheck="false" readonly="@_meetings.ReadOnly">@_meetings.Value</textarea>
<button class="btn" type="submit">Salva l'elenco</button>
</form>
</section>
<section class="panel" id="sicurezza">
<h2>Sicurezza</h2>
@if (Shell.IsDemo)
@@ -171,6 +217,8 @@
@code {
private readonly List<SettingValue> _appearance = [];
private IReadOnlyList<Anubis.Data.SourceState> _sources = [];
private SettingValue _meetings = new(SettingsStore.CentralBankMeetings.Key, "", false, null);
private List<SettingChange> _history = [];
private IReadOnlyList<BackupInfo> _backups = [];
private bool _hasSecondFactor;
@@ -193,6 +241,8 @@
_appearance.Add(await services.Settings.GetAsync(SettingsStore.Theme.Key, ct));
_appearance.Add(await services.Settings.GetAsync(SettingsStore.Currency.Key, ct));
_history = await services.Settings.HistoryAsync(null, 50, ct);
_meetings = await services.Settings.GetAsync(SettingsStore.CentralBankMeetings.Key, ct);
_sources = await new Anubis.Data.SourceStateStore(services.Db, Clock).ListAsync(ct);
_backups = services.Backups.List();
var user = HttpContext!.User;
_hasSecondFactor = CurrentUser.HasSecondFactor(user);
@@ -210,10 +260,29 @@
"segreto" => "La chiave è scaduta: ricarica la pagina e aggiungi di nuovo Anubis nell'app.",
"salvataggio" => "Il salvataggio non è riuscito. Controlla lo spazio libero nella cartella dei dati.",
"impostazione" => "Questa impostazione non si può cambiare così.",
"riunioni" => "L'elenco delle riunioni non è valido: una riga per riunione, con FED o BCE e la data, per esempio «FED 2027-01-27».",
"bot" => "Comando non ammesso nello stato attuale del bot.",
_ => PasswordMessages.For(Errore),
};
private static string SourceName(string source) => source switch
{
"okx" => "OKX Europe (crypto)",
"alpaca" => "Alpaca (azioni, conto di prova)",
"storico" => "Storico giornaliero delle crypto",
"storico_azioni" => "Storico giornaliero delle azioni",
"binance" => "Archivi Binance (ricerca)",
"ecb" => "Cambi della BCE",
"forexfactory" => "Calendario economico (Forex Factory)",
"fred" => "Date dei dati USA (FRED)",
"finnhub" => "Date delle trimestrali (Finnhub)",
"central_banks" => "Riunioni di Fed e BCE",
"alternative.me" => "Indice di paura e avidità",
"cboe" => "VIX (Cboe)",
"okx_derivatives" => "Funding e interesse aperto di BTC (OKX)",
_ => source,
};
private static string Label(string? value) => value switch
{
null => "—",
+6 -1
View File
@@ -151,11 +151,16 @@ internal static partial class Forms
private static async Task<IResult> SetSettingAsync(string key, IFormCollection form, AnubisHost host, HttpContext context, CancellationToken ct)
{
var back = Back(form, "/impostazioni");
if (key != SettingsStore.Theme.Key && key != SettingsStore.Currency.Key)
if (key != SettingsStore.Theme.Key && key != SettingsStore.Currency.Key && key != SettingsStore.CentralBankMeetings.Key)
{
return Results.Redirect(With(back, "errore", "impostazione"));
}
if (key == SettingsStore.CentralBankMeetings.Key && Anubis.Data.CentralBanks.Check(form["valore"].ToString()) is not null)
{
return Results.Redirect(With(back, "errore", "riunioni"));
}
var result = await Endpoints.SetSettingAsync(host, key, form["valore"].ToString(), context, ct).ConfigureAwait(false);
return Results.Redirect(result is IStatusCodeHttpResult { StatusCode: StatusCodes.Status204NoContent } ? back : With(back, "errore", "impostazione"));
}
@@ -47,6 +47,25 @@ public sealed class MarketDataServerTests
var report = await server.TextAsync("/api/data/quality?format=md");
StringAssert.Contains(report, "# Qualità dei dati");
StringAssert.Contains(report, "| alpaca | no |");
// The settings page says which source is off and why, and edits the central bank list.
var page = await server.TextAsync("/impostazioni");
StringAssert.Contains(page, "Alpaca (azioni, conto di prova)");
StringAssert.Contains(page, "mancano le chiavi del conto di prova Alpaca");
StringAssert.Contains(page, "FED 2026-12-09");
using (var wrong = await server.PostFormAsync("/impostazioni", "/azioni/impostazioni/calendar.central_banks", ("valore", "FED il 9 dicembre"),
("ritorno", "/impostazioni#dati")))
{
Assert.AreEqual("/impostazioni?errore=riunioni#dati", ServerHarness.Location(wrong));
}
using (var right = await server.PostFormAsync("/impostazioni", "/azioni/impostazioni/calendar.central_banks", ("valore", "FED 2027-01-27\r\nBCE 2027-02-04"),
("ritorno", "/impostazioni#dati")))
{
Assert.AreEqual("/impostazioni#dati", ServerHarness.Location(right));
}
StringAssert.Contains(await server.TextAsync("/impostazioni"), "BCE 2027-02-04");
}
[TestMethod]