The Conti e posizioni screen follows mockup 02: totals split by strategy, one card per account with key permissions and the last reconciliation, positions with a per-account filter and CSV export, pending stops (Alpaca grouped into permanent and day stops), residues, and exposure by currency. It shows one world only, real accounts when there are any, so simulated and real money never add up. Position values are rounded to the cent per row, as the table shows them, so the figures add up on screen. Settings gain "Conti e chiavi": practice keys are asked to the broker before they are saved and refused when they may withdraw or cannot trade; they are never shown again and the engine restarts to use them. The capital entrusted to each broker is set there in euro. Until any capital is set, the overview points to that section as the first step. The overview now reads one world, nets capital flows out of its results and uses the time-weighted index; open orders exclude protective stops. The demo seed gains cash rows, closed trades, stops, the ECB rate and the reconciliation state, so the ledger itself computes the mockup's figures. Screenshots now capture the whole page and include Conti. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2441df592
commit
4c4f848d80
18 files changed
+1472
-33
No files matched your search
@@ -4,10 +4,12 @@
|
||||
@inject ShellData Shell
|
||||
@inject SecondFactorDrafts Drafts
|
||||
@inject Anubis.Core.IClock Clock
|
||||
@using Anubis.Data
|
||||
@using Anubis.Trading
|
||||
|
||||
<PageTitle>Impostazioni · Anubis</PageTitle>
|
||||
|
||||
@* First part of SPEC 13.5: appearance, security, system. The other sections arrive with their phases. *@
|
||||
@* SPEC 13.5: appearance, accounts and keys, data, security, system. The other sections arrive with their phases. *@
|
||||
@if (Ok is { } ok)
|
||||
{
|
||||
<p class="notice notice-gain" role="status"><Icon Name="check" Size="16" />@(ok switch
|
||||
@@ -16,6 +18,9 @@
|
||||
"due-fattori" => "Secondo fattore attivato.",
|
||||
"due-fattori-tolti" => "Secondo fattore disattivato.",
|
||||
"salvataggio" => "Salvataggio fatto.",
|
||||
"chiavi" => "Chiavi verificate e salvate: possono fare ordini e non possono prelevare. Il motore è ripartito e le usa.",
|
||||
"chiavi-tolte" => "Chiavi tolte: quel conto torna al simulatore interno per le strategie che non hanno ancora storia sul conto di prova.",
|
||||
"capitale" => "Capitale affidato aggiornato e diviso tra le strategie.",
|
||||
_ => "Fatto.",
|
||||
})</p>
|
||||
}
|
||||
@@ -25,7 +30,7 @@
|
||||
}
|
||||
|
||||
<nav class="tabs" aria-label="Sezioni delle impostazioni">
|
||||
<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>
|
||||
<a href="#aspetto">Aspetto</a><a href="#conti">Conti</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">
|
||||
@@ -56,6 +61,80 @@
|
||||
<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="conti">
|
||||
<h2>Conti e chiavi</h2>
|
||||
<p class="hint">In questa fase uso solo denaro finto: il simulatore interno è sempre acceso e, con le chiavi dei conti di prova, le strategie passano ai conti di prova dei broker. Le chiavi di conti veri non servono e non vanno inserite.</p>
|
||||
@foreach (var b in _brokers)
|
||||
{
|
||||
<h3>@b.Title</h3>
|
||||
<dl class="facts">
|
||||
@foreach (var k in b.Keys)
|
||||
{
|
||||
<dt>@k.Label</dt><dd>@KeyState(k.Status)</dd>
|
||||
}
|
||||
@if (b.State is { KeyCheckedAt: { } checkedAt } state)
|
||||
{
|
||||
<dt>Permessi</dt>
|
||||
<dd class="@(state.KeyCanWithdraw == true ? "loss" : null)">@(state.KeyCanWithdraw == true ? "Permette i prelievi: va sostituita, intanto niente nuovi acquisti" : state.KeyCanTrade == true ? "Legge e fa ordini, nessun prelievo" : "Solo lettura") (verificati @Inline(Format.ShortDate(checkedAt, Shell.Now, Shell.Zone)))</dd>
|
||||
}
|
||||
</dl>
|
||||
@if (Shell.IsDemo)
|
||||
{
|
||||
<p class="hint">Nella modalità dimostrativa chiavi e capitale non si cambiano.</p>
|
||||
}
|
||||
else if (b.Keys.Any(k => k.Status.FromEnvironment))
|
||||
{
|
||||
<p class="hint">Le chiavi arrivano dalle variabili d'ambiente e valgono più di quelle salvate qui: si cambiano nella configurazione del container.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post" action="/azioni/chiavi/@b.Broker" class="form" autocomplete="off">
|
||||
<AntiforgeryToken />
|
||||
@foreach (var k in b.Keys)
|
||||
{
|
||||
<label for="k-@k.Name">@k.Label</label>
|
||||
<input id="k-@k.Name" name="@k.Name" type="password" autocomplete="off" spellcheck="false" maxlength="512" required />
|
||||
}
|
||||
<button class="btn" type="submit">Verifica e salva</button>
|
||||
</form>
|
||||
<p class="hint">Non le rimostro mai. Prima di salvarle chiedo al broker cosa possono fare: una chiave che permette i prelievi la rifiuto. Dopo il salvataggio il motore riparte da solo, in pochi secondi.</p>
|
||||
@if (b.Keys.Any(k => k.Status.IsSet))
|
||||
{
|
||||
<form method="post" action="/azioni/chiavi/@b.Broker/togli" class="form-inline"><AntiforgeryToken /><button class="btn btn-small" type="submit" data-confirm="Tolgo le chiavi di @b.Short? Le posizioni sul conto di prova restano lì, ma il bot non le segue più finché non le rimetti.">Togli le chiavi</button></form>
|
||||
}
|
||||
}
|
||||
|
||||
<h4>Capitale affidato a @b.Short</h4>
|
||||
@if (b.Entrusted is { } e)
|
||||
{
|
||||
<p>@Format.Money(e.AmountEur, "EUR")@(e.Currency == "EUR" ? "" : $", cioè {Format.Money(e.Amount, e.Currency)} al cambio di {Format.Quantity(e.FxRate)}"), deciso @Inline(Format.ShortDate(e.At, Shell.Now, Shell.Zone)) da @e.ChangedBy.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Nessun capitale affidato: le strategie di @b.Short osservano soltanto.</p>
|
||||
}
|
||||
@if (b.Strategies.Count > 0)
|
||||
{
|
||||
<ul class="plain">
|
||||
@foreach (var s in b.Strategies)
|
||||
{
|
||||
<li>@Strategies.Label(s.Strategy, withMarket: true): quota @Format.Percent(s.Share * 100m, 0), capitale @Format.Money(s.Capital, s.Currency), liquidità @Format.Money(s.Cash, s.Currency)</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@if (!Shell.IsDemo)
|
||||
{
|
||||
<form method="post" action="/azioni/capitale/@b.Broker" class="form-inline">
|
||||
<AntiforgeryToken />
|
||||
<label for="euro-@b.Broker">Nuovo importo in euro</label>
|
||||
<input id="euro-@b.Broker" name="euro" inputmode="decimal" autocomplete="off" value="@(b.Entrusted is { } cur ? Format.Quantity(cur.AmountEur) : "")" required />
|
||||
<button class="btn btn-small" type="submit">Salva</button>
|
||||
</form>
|
||||
<p class="hint">Si divide tra le strategie del conto secondo le quote@(b.Broker == Venues.Alpaca ? ", in dollari al cambio BCE del giorno" : ""). Ridurlo non vende nulla: se una strategia ha investito più di quanto le resterebbe, aspetto che venda.</p>
|
||||
}
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="panel" id="dati">
|
||||
<h2>Dati</h2>
|
||||
@if (Host.Services!.MarketData is not { } market)
|
||||
@@ -217,6 +296,12 @@
|
||||
|
||||
@code {
|
||||
private readonly List<SettingValue> _appearance = [];
|
||||
private readonly List<BrokerSetup> _brokers = [];
|
||||
|
||||
private sealed record BrokerKey(string Name, string Label, SecretStatus Status);
|
||||
|
||||
private sealed record BrokerSetup(string Broker, string Title, string Short, IReadOnlyList<BrokerKey> Keys, AccountState? State, EntrustedCapital? Entrusted,
|
||||
IReadOnlyList<StrategyCapital> Strategies);
|
||||
private IReadOnlyList<Anubis.Data.SourceState> _sources = [];
|
||||
private SettingValue _meetings = new(SettingsStore.CentralBankMeetings.Key, "", false, null);
|
||||
private List<SettingChange> _history = [];
|
||||
@@ -244,6 +329,21 @@
|
||||
_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 ledger = new Ledger(services.Db, Clock);
|
||||
var capital = new Capital(services.Db, Clock, ledger, new FxStore(services.Db, Clock));
|
||||
var reconciler = new Reconciler(services.Db, Clock, ledger);
|
||||
foreach (var (broker, title, name) in new[] { (Venues.Okx, "OKX Europe · conto demo", "OKX"), (Venues.Alpaca, "Alpaca · conto di prova (paper)", "Alpaca") })
|
||||
{
|
||||
var keys = new List<BrokerKey>();
|
||||
foreach (var (secret, label) in TradingService.KeyFields(broker))
|
||||
{
|
||||
keys.Add(new BrokerKey(secret, label, await services.Secrets.StatusAsync(secret, ct)));
|
||||
}
|
||||
|
||||
var demoAccount = await services.Db.ReadAsync(s => s.FirstOrDefaultAsync("SELECT id FROM accounts WHERE broker = @b AND environment = 'demo'", r => (Guid?)r.Id("id"), ("b", broker)), ct);
|
||||
var state = demoAccount is { } id ? await reconciler.StateAsync(id, ct) : null;
|
||||
_brokers.Add(new BrokerSetup(broker, title, name, keys, state, await capital.EntrustedAsync(broker, ct), await capital.StrategiesAsync(broker, ct)));
|
||||
}
|
||||
var user = HttpContext!.User;
|
||||
_hasSecondFactor = CurrentUser.HasSecondFactor(user);
|
||||
if (!_hasSecondFactor && !Shell.IsDemo)
|
||||
@@ -262,9 +362,30 @@
|
||||
"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.",
|
||||
"motore" => "Il motore di trading non è attivo (modalità dimostrativa o ANUBIS_TRADING spento): qui non si cambia nulla.",
|
||||
"conto" => "Conto sconosciuto.",
|
||||
"ambiente" => "Le chiavi di questo conto arrivano dalle variabili d'ambiente: si cambiano nella configurazione del container.",
|
||||
"chiavi-vuote" => "Servono tutti i campi della chiave.",
|
||||
"chiavi-rifiutate" => "Il broker non ha accettato la chiave, o non ha risposto. Controlla di aver copiato la chiave del conto di prova e riprova. Non ho salvato nulla.",
|
||||
"prelievo" => "Questa chiave permette i prelievi: non la salvo. Creane una senza il permesso di prelievo.",
|
||||
"sola-lettura" => "Questa chiave può solo leggere: per lavorare sul conto di prova serve anche il permesso di fare ordini. Non l'ho salvata.",
|
||||
"importo" => "Scrivi un importo in euro, per esempio 4000 o 1.500,50.",
|
||||
"cambio" => "Manca ancora il cambio euro/dollaro della BCE: lo scarico ogni giorno, riprova più tardi.",
|
||||
"capitale" => "Una strategia ha investito più di quanto le resterebbe: potrò ridurre il capitale quando avrà venduto.",
|
||||
_ => PasswordMessages.For(Errore),
|
||||
};
|
||||
|
||||
private string KeyState(SecretStatus status) => status switch
|
||||
{
|
||||
{ FromEnvironment: true } => "Dalle variabili d'ambiente",
|
||||
{ IsSet: true, UpdatedAt: { } at } => "Impostata " + Inline(Format.ShortDate(at, Shell.Now, Shell.Zone)),
|
||||
{ IsSet: true } => "Impostata",
|
||||
_ => "Non impostata",
|
||||
};
|
||||
|
||||
// "Oggi 08:20" inside a sentence reads "oggi 08:20".
|
||||
private static string Inline(string text) => text.Length == 0 ? text : char.ToLowerInvariant(text[0]) + text[1..];
|
||||
|
||||
private static string SourceName(string source) => source switch
|
||||
{
|
||||
"okx" => "OKX Europe (crypto)",
|
||||
|
||||
Reference in new issue
Block a user