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
@@ -35,6 +35,9 @@
|
||||
case "dots":
|
||||
<circle cx="5.5" cy="12" r="1" /><circle cx="12" cy="12" r="1" /><circle cx="18.5" cy="12" r="1" />
|
||||
break;
|
||||
case "download":
|
||||
<path d="M12 4v11M7 10.5l5 5 5-5M5 19.5h14" />
|
||||
break;
|
||||
case "collapse":
|
||||
<path d="m11 17-5-5 5-5M18 17l-5-5 5-5" />
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,413 @@
|
||||
@inherits LoadedComponent
|
||||
@page "/conti"
|
||||
@inject AnubisHost Host
|
||||
@inject ShellData Shell
|
||||
@inject IClock Clock
|
||||
@using Anubis.Trading
|
||||
@using Anubis.Data
|
||||
|
||||
<PageTitle>Conti e posizioni · Anubis</PageTitle>
|
||||
|
||||
<Pending Title="Nessun conto collegato.">Conti, posizioni e ordini arrivano con la contabilità: lì aggiungerai le chiavi dei conti di prova e vedrai patrimonio, liquidità e commissioni di ciascuno.</Pending>
|
||||
@{
|
||||
var v = _view;
|
||||
var c = _currency;
|
||||
}
|
||||
@if (!v.HasAccounts)
|
||||
{
|
||||
<Pending Title="Nessun conto ancora.">Il bot crea da solo i due simulatori interni, OKX e Alpaca, al primo avvio del motore di trading. I conti di prova dei broker compaiono quando ne aggiungi le chiavi in <a href="/impostazioni#conti">Impostazioni</a>.</Pending>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (_message is { } message)
|
||||
{
|
||||
<p class="notice @(_ok ? "notice-gain" : "notice-loss")" role="status"><Icon Name="@(_ok ? "check" : "alert")" Size="16" />@message</p>
|
||||
}
|
||||
|
||||
var shares = Format.Shares([.. v.Slices.Select(s => s.Eur), v.CashEur]);
|
||||
var winners = v.Positions.Count(p => p.ResultEur >= 0);
|
||||
<section class="panel totals" aria-label="Totale dei conti">
|
||||
<div class="totals-cells">
|
||||
<div class="cell">
|
||||
<span class="cell-label">Totale dei conti</span>
|
||||
<span class="total-value">@Shell.Money(v.TotalEur, c)</span>
|
||||
<span class="cell-change @(v.ResultEur >= 0 ? "gain" : "loss")"><Arrow Up="v.ResultEur >= 0" />@Shell.Money(v.ResultEur, c, withSign: true) dall'avvio</span>
|
||||
</div>
|
||||
<div class="cell">
|
||||
<span class="cell-label">Investito</span>
|
||||
<span class="total-value">@Shell.Money(v.InvestedEur, c)</span>
|
||||
<span class="cell-note">@Format.Percent(Part(v.InvestedEur, v.TotalEur)) del totale</span>
|
||||
</div>
|
||||
<div class="cell">
|
||||
<span class="cell-label">Liquidità</span>
|
||||
<span class="total-value">@Shell.Money(v.CashEur, c)</span>
|
||||
<span class="cell-note">@Format.Percent(Part(v.CashEur, v.TotalEur)) del totale</span>
|
||||
</div>
|
||||
<div class="cell">
|
||||
<span class="cell-label">Risultato delle posizioni aperte</span>
|
||||
<span class="total-value">@Shell.Money(v.OpenResultEur, c, withSign: true)</span>
|
||||
<span class="cell-note">@(v.Positions.Count == 0 ? "Nessuna posizione aperta" : $"{winners} in guadagno, {v.Positions.Count - winners} in perdita")</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="split-bar" role="img" aria-label="Divisione del totale tra strategie e liquidità">
|
||||
@for (var i = 0; i < v.Slices.Count; i++)
|
||||
{
|
||||
if (shares[i] > 0)
|
||||
{
|
||||
<span style="width: @Css(shares[i])%; background: @v.Slices[i].Color"></span>
|
||||
}
|
||||
}
|
||||
@if (shares[^1] > 0)
|
||||
{
|
||||
<span style="width: @Css(shares[^1])%; background: var(--cash)"></span>
|
||||
}
|
||||
</div>
|
||||
<ul class="split-legend">
|
||||
@for (var i = 0; i < v.Slices.Count; i++)
|
||||
{
|
||||
<li><span class="swatch" style="background: @v.Slices[i].Color"></span>@v.Slices[i].Label <strong>@Format.Percent(shares[i])</strong></li>
|
||||
}
|
||||
<li><span class="swatch" style="background: var(--cash)"></span>Liquidità <strong>@Format.Percent(shares[^1])</strong></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<div class="account-grid">
|
||||
@foreach (var a in v.Accounts)
|
||||
{
|
||||
var state = a.State;
|
||||
var up = a.Result >= 0;
|
||||
var usd = a.Currency == "USD";
|
||||
<section class="panel account" aria-label="@a.Name">
|
||||
<div class="account-head">
|
||||
<h2>@a.Name <span class="tag">@a.Kind</span></h2>
|
||||
<span class="link-state @(state.LastOutcome == ReconcileOutcomes.Unreachable ? "down" : null)"><span class="dot"></span>@Connection(a)</span>
|
||||
</div>
|
||||
<div class="account-value">
|
||||
<span class="account-equity">@Shell.Money(a.Eur(a.Equity), c)</span>
|
||||
@if (usd)
|
||||
{
|
||||
<span class="account-native">@Format.Money(a.Equity, "USD")</span>
|
||||
}
|
||||
<span class="cell-change @(up ? "gain" : "loss")"><Arrow Up="up" />@Shell.Money(a.Eur(a.Result), c, withSign: true) (@Format.Percent(a.Percent, 2, withSign: true))</span>
|
||||
</div>
|
||||
<dl class="account-lines">
|
||||
<dt>Liquidità in @(usd ? "dollari" : "euro")</dt>
|
||||
<dd><strong>@Shell.Money(a.Eur(a.Cash), c)</strong>@if (usd) {<span class="native"> @Format.Money(a.Cash, "USD")</span>}</dd>
|
||||
<dt>Investito in @Holdings(a)</dt>
|
||||
<dd><strong>@Shell.Money(a.InvestedEur, c)</strong>@if (usd) {<span class="native"> @Format.Money(a.Invested, "USD")</span>}</dd>
|
||||
<dt>Guadagni già incassati</dt>
|
||||
<dd><strong>@Shell.Money(a.Eur(a.Realized), c, withSign: true)</strong></dd>
|
||||
<dt>Guadagni sulle posizioni aperte</dt>
|
||||
<dd><strong>@Shell.Money(a.Eur(a.Unrealized), c, withSign: true)</strong></dd>
|
||||
<dt>Commissioni pagate</dt>
|
||||
<dd><strong>@Shell.Money(a.Eur(a.Fees), c)</strong></dd>
|
||||
</dl>
|
||||
@if (state.IsPrudent)
|
||||
{
|
||||
<div class="notice notice-attention prudent">
|
||||
<Icon Name="alert" Size="16" />
|
||||
<div>
|
||||
@if (state.ModeReason == Reconciler.KeyReason)
|
||||
{
|
||||
<p>La chiave di questo conto permette i prelievi: niente nuovi acquisti finché non la sostituisci con una senza prelievo in <a href="/impostazioni#conti">Impostazioni</a>. Vendite e stop proseguono.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Modalità prudente dalle @Time(state.ModeSince): niente nuovi acquisti, vendite e stop proseguono.</p>
|
||||
<ul class="differences">
|
||||
@foreach (var d in state.Differences)
|
||||
{
|
||||
<li>@d.Message</li>
|
||||
}
|
||||
</ul>
|
||||
@if (state.WaitsForUser(Clock.UtcNow, TimeSpan.FromMinutes(15)) && !Shell.IsDemo)
|
||||
{
|
||||
<p>Sono passati 15 minuti e la differenza non si è spiegata da sola. Scegli tu:</p>
|
||||
<div class="choices">
|
||||
<form method="post" action="/azioni/conti/@a.Id/allinea"><AntiforgeryToken /><button class="btn btn-small" type="submit" data-confirm="Il registro prende i numeri del conto, con una riga di rettifica che resta nel diario. Confermi?">Allinea il registro al conto</button></form>
|
||||
<form method="post" action="/azioni/conti/@a.Id/escludi"><AntiforgeryToken /><button class="btn btn-small" type="submit">Lascia fuori ciò che non è del bot</button></form>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="note">Se entro 15 minuti si spiega da sola il conto torna normale; altrimenti qui potrai scegliere se allineare il registro o lasciare fuori la differenza.</p>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<ul class="account-facts">
|
||||
@if (a.Environment == TradingEnvironments.Simulation)
|
||||
{
|
||||
<li><Icon Name="flask" Size="16" />Simulazione interna: prezzi veri, ordini finti</li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li><Icon Name="flask" Size="16" />Conto di prova del broker: ordini veri su denaro finto</li>
|
||||
}
|
||||
@if (state.KeyCanWithdraw == true)
|
||||
{
|
||||
<li class="loss"><Icon Name="alert" Size="16" />La chiave permette i prelievi: va sostituita</li>
|
||||
}
|
||||
else if (state.KeyCheckedAt is not null)
|
||||
{
|
||||
<li><Icon Name="check" Size="16" />La chiave può solo leggere e fare ordini: i prelievi sono disattivati</li>
|
||||
}
|
||||
@if (usd)
|
||||
{
|
||||
<li><Icon Name="clock" Size="16" />@(v.MarketOpen ? $"Mercato aperto: chiude alle {Time(v.MarketNext)}." : $"Mercato chiuso: apre alle {Time(v.MarketNext)}.") @RateText(v, withSource: false)</li>
|
||||
}
|
||||
@if (state.LastReconciledAt is null)
|
||||
{
|
||||
<li><Icon Name="clock" Size="16" />Primo controllo con il registro entro 5 minuti</li>
|
||||
}
|
||||
else if (state.LastOutcome is ReconcileOutcomes.Different)
|
||||
{
|
||||
<li class="attention"><Icon Name="alert" Size="16" />Differenza tra conto e registro (controllo delle @Time(state.LastReconciledAt))</li>
|
||||
}
|
||||
else if (state.LastOutcome is ReconcileOutcomes.Unreachable)
|
||||
{
|
||||
<li class="attention"><Icon Name="alert" Size="16" />Il broker non risponde: riprovo ogni 5 minuti (ultimo tentativo alle @Time(state.LastReconciledAt))</li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li><Icon Name="check" Size="16" />@(a.Environment == TradingEnvironments.Simulation ? "Registro interno coerente" : "Conto e registro interno coincidono") (controllo delle @Time(state.LastReconciledAt))</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
|
||||
var shownPositions = v.Positions.Where(p => _filter is null || p.Broker == _filter).ToList();
|
||||
<section class="panel" aria-labelledby="posizioni">
|
||||
<div class="panel-head">
|
||||
<h2 id="posizioni">Posizioni aperte</h2>
|
||||
<div class="panel-tools">
|
||||
<nav class="segmented" aria-label="Conto">
|
||||
<a href="/conti" class="@(_filter is null ? "on" : null)" aria-current="@(_filter is null ? "true" : null)">Tutti i conti</a>
|
||||
@foreach (var a in v.Accounts)
|
||||
{
|
||||
<a href="/conti?conto=@a.Broker" class="@(_filter == a.Broker ? "on" : null)" aria-current="@(_filter == a.Broker ? "true" : null)">@a.Name</a>
|
||||
}
|
||||
</nav>
|
||||
<a class="btn" href="/api/conti/posizioni.csv@(_filter is null ? "" : "?conto=" + _filter)" download><Icon Name="download" Size="18" />Esporta CSV</a>
|
||||
</div>
|
||||
</div>
|
||||
@if (shownPositions.Count == 0)
|
||||
{
|
||||
<p class="note">Nessuna posizione aperta@(_filter is null ? "" : " su questo conto").</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-wrap">
|
||||
<table class="table positions">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Strumento</th>
|
||||
<th scope="col" class="wide">Conto</th>
|
||||
<th scope="col" class="wide">Strategia</th>
|
||||
<th scope="col" class="num wide">Quantità</th>
|
||||
<th scope="col" class="num wide">Prezzo medio</th>
|
||||
<th scope="col" class="num wide">Prezzo ora</th>
|
||||
<th scope="col" class="num">Valore</th>
|
||||
<th scope="col" class="num">Risultato</th>
|
||||
<th scope="col" class="num wide">Stop</th>
|
||||
<th scope="col" class="num wide">Aperta da</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var p in shownPositions)
|
||||
{
|
||||
var gain = p.ResultEur >= 0;
|
||||
<tr>
|
||||
<th scope="row"><strong>@p.Symbol</strong> <span class="muted">@p.Name</span></th>
|
||||
<td class="wide">@(p.Broker == Venues.Alpaca ? "Alpaca" : "OKX")</td>
|
||||
<td class="nowrap wide"><span class="swatch round" style="background: var(--s-@p.Strategy.Replace('_', '-'))"></span>@Strategies.Label(p.Strategy)</td>
|
||||
<td class="num wide">@Format.Quantity(p.Quantity)</td>
|
||||
<td class="num wide">@Format.Money(p.Average, p.Currency)</td>
|
||||
<td class="num wide">@Format.Money(p.Last, p.Currency)</td>
|
||||
<td class="num"><strong>@Shell.Money(p.ValueEur, c)</strong></td>
|
||||
<td class="num nowrap @(gain ? "gain" : "loss")"><strong>@Shell.Money(p.ResultEur, c, withSign: true)<span class="cell-extra"> (@Format.Percent(p.Percent, 2, withSign: true))</span></strong></td>
|
||||
<td class="num wide">@(p.Stop is { } stop ? Format.Money(stop, p.Currency, decimals: AccountsView.StopDecimals(stop)) : "—")</td>
|
||||
<td class="num wide nowrap">@Age(p.OpenedAt)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th scope="row">Totale</th>
|
||||
<td class="wide"></td><td class="wide"></td><td class="wide"></td><td class="wide"></td><td class="wide"></td>
|
||||
<td class="num"><strong>@Shell.Money(shownPositions.Sum(p => p.ValueEur), c)</strong></td>
|
||||
<td class="num @(shownPositions.Sum(p => p.ResultEur) >= 0 ? "gain" : "loss")"><strong>@Shell.Money(shownPositions.Sum(p => p.ResultEur), c, withSign: true)</strong></td>
|
||||
<td class="wide"></td><td class="wide"></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
<div class="columns">
|
||||
<section class="panel" aria-labelledby="ordini">
|
||||
<div class="panel-head">
|
||||
<h2 id="ordini">Ordini in attesa</h2>
|
||||
<span class="note">@(v.PendingOthers == 0 ? (v.Pending.Count == 0 ? "Nessun ordine aperto" : "Solo stop di protezione: nessun acquisto in coda") : $"{v.PendingOthers} {(v.PendingOthers == 1 ? "ordine" : "ordini")} in corso oltre agli stop")</span>
|
||||
</div>
|
||||
@if (v.Pending.Count > 0)
|
||||
{
|
||||
<div class="table-wrap">
|
||||
<table class="table pending">
|
||||
<thead><tr><th scope="col">Ordine</th><th scope="col">Dove</th><th scope="col" class="num">Scatta a</th><th scope="col">Stato</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var o in v.Pending)
|
||||
{
|
||||
<tr>
|
||||
<th scope="row">@o.Action <strong>@o.Subject</strong></th>
|
||||
<td>@o.Where</td>
|
||||
<td class="num @(o.Level == "vedi tabella sopra" ? "muted" : null)">@o.Level</td>
|
||||
<td><span class="order-state">@if (o.Waiting) {<Icon Name="clock" Size="16" />} else {<span class="dot"></span>}@o.Status</span></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
@if (v.AlpacaStops)
|
||||
{
|
||||
<p class="aside">Le azioni intere hanno uno stop permanente sul broker, che resta attivo anche a bot spento. Sulle frazioni il broker accetta solo ordini che valgono un giorno: quelli li rimetto a ogni apertura e, a mercato chiuso, li sorveglio io.</p>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="panel" aria-labelledby="valute">
|
||||
<h2 id="valute">In quale valuta sono i soldi</h2>
|
||||
@{
|
||||
var dollars = v.Accounts.Where(a => a.Currency == "USD").Sum(a => a.Eur(a.Equity));
|
||||
var euros = v.TotalEur - dollars;
|
||||
var parts = Format.Shares([dollars, euros]);
|
||||
}
|
||||
<div class="split-bar slim" role="img" aria-label="Dollari @Format.Percent(parts[0]), euro @Format.Percent(parts[1])">
|
||||
@if (parts[0] > 0) {<span style="width: @Css(parts[0])%; background: var(--text-2)"></span>}
|
||||
@if (parts[1] > 0) {<span style="width: @Css(parts[1])%; background: var(--cash)"></span>}
|
||||
</div>
|
||||
<dl class="currency-lines">
|
||||
<dt><span class="swatch" style="background: var(--text-2)"></span>Dollari (conto Alpaca)</dt><dd><strong>@Shell.Money(dollars, c)</strong> <span class="muted">@Format.Percent(parts[0])</span></dd>
|
||||
<dt><span class="swatch" style="background: var(--cash)"></span>Euro e crypto (conto OKX)</dt><dd><strong>@Shell.Money(euros, c)</strong> <span class="muted">@Format.Percent(parts[1])</span></dd>
|
||||
</dl>
|
||||
<p class="note">@RateText(v)@(v.FxEffect is { } fx && fx != 0 ? $" Effetto del cambio sul risultato in euro: {Format.Money(fx, "EUR", withSign: true)}." : "")</p>
|
||||
@if (dollars > 0)
|
||||
{
|
||||
<p class="notice notice-attention fx-warning"><Icon Name="alert" Size="16" />Se il dollaro perde il 5% sull'euro, il totale scende di circa @Format.Money(Math.Round(dollars * 0.05m), "EUR", decimals: 0) anche a prezzi fermi.</p>
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@if (v.Residues.Count > 0)
|
||||
{
|
||||
<section class="panel" aria-labelledby="residui">
|
||||
<div class="panel-head">
|
||||
<h2 id="residui">Residui sotto il minimo vendibile</h2>
|
||||
<span class="note">Restano sul conto ma non sono più del bot: tolti dal registro al valore di mercato</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="table">
|
||||
<thead><tr><th scope="col">Strumento</th><th scope="col">Conto</th><th scope="col" class="num">Quantità</th><th scope="col" class="num">Valore</th><th scope="col" class="num">Dal</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var r in v.Residues)
|
||||
{
|
||||
<tr><th scope="row">@r.Symbol</th><td>@r.Broker</td><td class="num">@Format.Quantity(r.Quantity)</td><td class="num">@Format.Money(r.Value, r.Currency)</td><td class="num">@Format.ShortDate(r.At, Shell.Now, Shell.Zone, withTime: false)</td></tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
private AccountsView _view = null!;
|
||||
private string _currency = "EUR";
|
||||
private string? _filter;
|
||||
private string? _message;
|
||||
private bool _ok;
|
||||
private Dictionary<Guid, int>? _latency;
|
||||
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "conto")]
|
||||
public string? Conto { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "ok")]
|
||||
public string? Ok { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "errore")]
|
||||
public string? Errore { get; set; }
|
||||
|
||||
protected override async Task LoadAsync()
|
||||
{
|
||||
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
|
||||
var services = Host.Services!;
|
||||
_currency = Shell.Effective((await services.Settings.GetAsync(SettingsStore.Currency.Key, ct)).Value);
|
||||
_view = await AccountsView.LoadAsync(services, Clock, Shell.Zone, ct);
|
||||
_filter = Conto is Venues.Okx or Venues.Alpaca ? Conto : null;
|
||||
(_message, _ok) = (Ok, Errore) switch
|
||||
{
|
||||
("allinea", _) => ("Fatto: il registro ha preso i numeri del conto e il conto è tornato normale.", true),
|
||||
("escludi", _) => ("Fatto: la differenza resta fuori dal registro e il conto è tornato normale.", true),
|
||||
(_, "motore") => ("Il motore di trading non è attivo: riprova tra poco.", false),
|
||||
(_, "chiave") => ("Una chiave che permette i prelievi non si allinea: va sostituita in Impostazioni.", false),
|
||||
(_, { }) => ("Non è stato possibile completare la scelta: riprova.", false),
|
||||
_ => (null, false),
|
||||
};
|
||||
using var aggregates = Shell.Aggregates();
|
||||
if (aggregates is not null)
|
||||
{
|
||||
var names = aggregates.RootElement.GetProperty("conti").EnumerateArray().Select(x => x.GetProperty("risposta_ms").GetInt32()).ToList();
|
||||
_latency = _view.Accounts.Select((a, i) => (a.Id, i)).Where(x => x.i < names.Count).ToDictionary(x => x.Id, x => names[x.i]);
|
||||
}
|
||||
}
|
||||
|
||||
private string Connection(AccountCard a)
|
||||
{
|
||||
if (a.State.LastOutcome == ReconcileOutcomes.Unreachable)
|
||||
{
|
||||
return "Il broker non risponde";
|
||||
}
|
||||
|
||||
if (_latency?.GetValueOrDefault(a.Id) is > 0 and var ms)
|
||||
{
|
||||
return $"Connesso, risposta in {ms} ms";
|
||||
}
|
||||
|
||||
return a.Environment == TradingEnvironments.Simulation ? "Attivo, nel simulatore" : "Connesso";
|
||||
}
|
||||
|
||||
private static string Holdings(AccountCard a) => (a.Broker, a.Holdings) switch
|
||||
{
|
||||
(_, 0) => "nulla",
|
||||
(Venues.Alpaca, 1) => "1 azione",
|
||||
(Venues.Alpaca, var n) => $"{n} azioni",
|
||||
(_, 1) => "1 moneta",
|
||||
(_, var n) => $"{n} monete",
|
||||
};
|
||||
|
||||
private static string RateText(AccountsView v, bool withSource = true) => v.UsdRate is { } rate
|
||||
? $"Cambio usato: 1 € = {Format.Quantity(rate)} $" + (withSource ? $" (BCE, {AccountsView.DayMonth(new DateTimeOffset(v.RateDay!.Value.ToDateTime(TimeOnly.MinValue), TimeSpan.Zero))})." : ".")
|
||||
: "Manca ancora il cambio euro/dollaro della BCE: i dollari restano nella loro valuta.";
|
||||
|
||||
private static decimal Part(decimal part, decimal total) => total == 0 ? 0 : part / total * 100m;
|
||||
|
||||
private static string Css(decimal percent) => percent.ToString("0.###", CultureInfo.InvariantCulture);
|
||||
|
||||
private string Time(DateTimeOffset? moment) => moment is { } m ? TimeZoneInfo.ConvertTime(m, Shell.Zone).ToString("HH:mm", CultureInfo.InvariantCulture) : "—";
|
||||
|
||||
private string Age(DateTimeOffset opened)
|
||||
{
|
||||
var days = (int)Math.Floor((Shell.Now - opened).TotalDays);
|
||||
return days switch
|
||||
{
|
||||
< 1 => "oggi",
|
||||
1 => "1 giorno",
|
||||
_ => $"{days} giorni",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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)",
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
var o = _overview;
|
||||
var c = _currency;
|
||||
}
|
||||
@if (!o.CapitalSet && !Shell.IsDemo)
|
||||
{
|
||||
<p class="notice notice-attention" role="status"><Icon Name="alert" Size="16" /><span>Primo passo: decidi quanto capitale affidare al bot in <a href="/impostazioni#conti">Impostazioni, Conti e chiavi</a>. Lì puoi anche inserire le chiavi dei conti di prova. Finché non c'è capitale, le strategie osservano soltanto.</span></p>
|
||||
}
|
||||
<section class="panel head-block" aria-label="Il punto della situazione">
|
||||
<div class="half half-past">
|
||||
<div class="half-head">
|
||||
|
||||
Reference in new issue
Block a user