First commit
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
{% set is_gold = kinds == ['gold'] %}{% set P = 'gold' if is_gold else 'inv' %}
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<div><h1>{{ title }}</h1>
|
||||
<div class="sub">{{ 'Physical gold valued at live spot price' if is_gold else 'Stocks, ETFs and crypto at live prices' }} · <span class="live-status"></span></div></div>
|
||||
<div class="actions">
|
||||
<a class="btn secondary" href="#add-trade">{{ icon('plus', 'sm') }} {{ 'Purchase' if is_gold else 'Trade' }}</a>
|
||||
<form method="post" action="/prices/refresh" data-ajax-refresh><button>{{ icon('refresh-cw', 'sm') }}<span> Refresh prices</span></button></form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid cols-4 mb">
|
||||
{% set a = t.get('all') %}
|
||||
<div class="card kpi"><div class="kpi-ico tint-accent">{{ icon('gem' if is_gold else 'line-chart') }}</div><div class="label">Current value</div><div class="value" data-live="{{ P }}_value" data-fmt="eur">{{ (a.value if a else 0)|eur }}</div>
|
||||
<div class="sub">{% if a and a.missing_price %}<span class="warn">{{ a.missing_price }} without price (counted at cost)</span>{% else %}live prices{% endif %}</div></div>
|
||||
<div class="card kpi"><div class="kpi-ico tint-warn">{{ icon('banknote') }}</div><div class="label">Paid</div><div class="value" data-live="{{ P }}_cost" data-fmt="eur">{{ (a.cost if a else 0)|eur }}</div><div class="sub">incl. fees, open positions</div></div>
|
||||
<div class="card kpi"><div class="kpi-ico {{ 'tint-good' if a and a.pnl >= 0 else 'tint-bad' }}">{{ icon('arrow-up-right' if a and a.pnl >= 0 else 'arrow-down-right') }}</div><div class="label">Unrealised P/L</div>
|
||||
<div class="value {{ 'good' if a and a.pnl >= 0 else 'bad' }}" data-live="{{ P }}_pnl" data-fmt="eurs" data-color>{{ (a.pnl if a else 0)|eur(2, true) }}</div><div class="sub" data-live="{{ P }}_pnl_pct" data-fmt="pct">{{ (a.pnl_pct if a else None)|pct }}</div></div>
|
||||
<div class="card kpi"><div class="kpi-ico tint-accent">{{ icon('check') }}</div><div class="label">Realised P/L</div><div class="value" data-live="{{ P }}_realized" data-fmt="eurs">{{ (a.realized if a else 0)|eur(2, true) }}</div><div class="sub">from sells</div></div>
|
||||
</div>
|
||||
|
||||
{% if not is_gold %}
|
||||
<div class="grid cols-2 mb">
|
||||
{% for k, label in [('stock','Stocks & ETFs'),('crypto','Crypto')] %}{% set x = t.get(k) %}
|
||||
<div class="card kpi"><div class="kpi-ico tint-accent">{{ icon('bitcoin' if k == 'crypto' else 'bar-chart-3') }}</div><div class="label">{{ label }}</div>
|
||||
<div class="value" data-live="{{ k }}_value" data-fmt="eur">{{ (x.value if x else 0)|eur }}</div>
|
||||
<div class="sub">paid <span data-live="{{ k }}_cost" data-fmt="eur">{{ (x.cost if x else 0)|eur }}</span> · <span data-live="{{ k }}_pnl" data-fmt="eurs" data-color class="{{ 'good' if x and x.pnl >= 0 else 'bad' }}">{{ (x.pnl if x else 0)|eur(2, true) }}</span> (<span data-live="{{ k }}_pnl_pct" data-fmt="pct" data-color>{{ (x.pnl_pct if x else None)|pct }}</span>)</div></div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card mb">
|
||||
<h2>{{ icon('coins') }} Holdings</h2>
|
||||
<div class="table-wrap"><table>
|
||||
<thead><tr><th>Asset</th>{% if not is_gold %}<th>Type</th>{% endif %}<th class="num">Quantity</th>{% if is_gold %}<th class="num">Fine gold</th>{% endif %}
|
||||
<th class="num">Avg paid</th><th class="num">Price</th><th class="num">Paid</th><th class="num">Value</th><th class="num">P/L</th><th class="num">%</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in rows %}{% set as = r.asset %}
|
||||
<tr>
|
||||
<td><strong>{{ as.name }}</strong><div class="desc">{{ as.symbol }}{% if as.price_error %} · <span class="bad" title="{{ as.price_error }}">price error</span>{% endif %}
|
||||
{% if as.manual_price is not none %} · <span class="warn">manual price</span>{% elif as.last_price_at %} · {{ as.last_price_at.strftime('%d-%m %H:%M') }}{% endif %}</div></td>
|
||||
{% if not is_gold %}<td><span class="badge">{{ as.kind }}</span></td>{% endif %}
|
||||
<td class="num">{{ r.qty|num }} {{ as.unit if as.unit != 'unit' }}{% if is_gold and as.purity != 1 %} <span class="muted small">@{{ as.purity|num }}</span>{% endif %}</td>
|
||||
{% if is_gold %}<td class="num">{{ r.grams|num(2) }} g</td>{% endif %}
|
||||
<td class="num">{{ r.avg|eur }}</td>
|
||||
<td class="num" data-live="a{{ as.id }}_price" data-fmt="eur">{{ r.price|eur }}</td>
|
||||
<td class="num">{{ r.cost|eur }}</td>
|
||||
<td class="num"><strong data-live="a{{ as.id }}_value" data-fmt="eur">{{ r.value|eur }}</strong></td>
|
||||
<td class="num {{ 'good' if r.pnl and r.pnl >= 0 else 'bad' }}" data-live="a{{ as.id }}_pnl" data-fmt="eurs" data-color>{{ r.pnl|eur(2, true) }}</td>
|
||||
<td class="num {{ 'good' if r.pnl and r.pnl >= 0 else 'bad' }}" data-live="a{{ as.id }}_pnl_pct" data-fmt="pct" data-color>{{ r.pnl_pct|pct }}</td>
|
||||
<td style="white-space:nowrap">
|
||||
<details><summary class="small muted">{{ icon('pencil', 'sm') }}</summary>
|
||||
<form method="post" action="/assets/{{ as.id }}/update" class="row small" style="margin:.4rem 0">
|
||||
<input name="symbol" value="{{ as.symbol }}" style="width:110px" title="Ticker / CoinGecko id">
|
||||
<input name="manual_price" value="{{ as.manual_price if as.manual_price is not none else '' }}" placeholder="manual €/unit" style="width:110px">
|
||||
<button class="sm">Save</button></form>
|
||||
<form method="post" action="/assets/{{ as.id }}/delete" data-confirm="Delete {{ as.name }} and all its trades?"><button class="sm danger">Delete</button></form>
|
||||
</details></td>
|
||||
</tr>
|
||||
{% else %}<tr><td colspan="11" class="muted">No holdings yet. Add an asset below, then record your purchases.</td></tr>{% endfor %}
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
|
||||
<div class="grid cols-3 mb">
|
||||
<div class="card span-2">
|
||||
<div class="card-head"><h2>{{ icon('line-chart') }} Value vs paid</h2>
|
||||
<div class="seg" data-range-for="inv-history">
|
||||
<button type="button" data-days="30">1M</button><button type="button" data-days="90">3M</button>
|
||||
<button type="button" data-days="180">6M</button><button type="button" data-days="365" class="on">1Y</button><button type="button" data-days="0">All</button>
|
||||
</div></div>
|
||||
{% if chart.labels %}
|
||||
<div class="chart-box tall"><canvas id="inv-history" data-chart="history" data-json='{{ {"labels": chart.labels, "value": chart.value, "cost": chart.cost}|tojson }}'></canvas></div>
|
||||
{% else %}<div class="empty">{{ icon('line-chart') }}<br>A data point is stored each time prices refresh.</div>{% endif %}
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h2>{{ icon('pie-chart') }} Allocation</h2></div>
|
||||
{% if chart.alloc_values %}
|
||||
<div class="chart-box sm"><canvas data-chart="donut" data-legend="alloc-legend" data-json='{{ {"labels": chart.alloc_labels, "data": chart.alloc_values}|tojson }}'></canvas></div>
|
||||
<div class="legend" id="alloc-legend" style="margin-top:.6rem"></div>
|
||||
{% else %}<div class="empty">{{ icon('pie-chart') }}<br>No priced holdings yet.</div>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid cols-2 mb">
|
||||
<form class="card" method="post" action="/trades/add" id="add-trade">
|
||||
<h2>{{ icon('plus') }} Record a {{ 'purchase' if is_gold else 'trade' }}</h2>
|
||||
{% if assets %}
|
||||
<div class="form-grid">
|
||||
<label>Asset<select name="asset_id">{% for as in assets %}<option value="{{ as.id }}">{{ as.name }}</option>{% endfor %}</select></label>
|
||||
<label>Buy / sell<select name="side"><option value="buy">Buy</option><option value="sell">Sell</option></select></label>
|
||||
<label>Date<input type="date" name="date" value="{{ today().isoformat() }}"></label>
|
||||
<label>Quantity{{ ' (grams/oz/pieces)' if is_gold }}<input name="quantity" inputmode="decimal" required></label>
|
||||
<label>Price per unit (€)<input name="price" inputmode="decimal" placeholder="or fill total →"></label>
|
||||
<label>…or total paid (€)<input name="total" inputmode="decimal"></label>
|
||||
<label>Fees (€)<input name="fees" inputmode="decimal" value="0"></label>
|
||||
<label>Note<input name="notes"></label>
|
||||
<div><button>Save</button></div>
|
||||
</div>
|
||||
{% else %}<p class="muted">Add an asset first →</p>{% endif %}
|
||||
</form>
|
||||
|
||||
<form class="card" method="post" action="/assets/add">
|
||||
<h2>{{ icon('sparkles') }} Add an asset</h2>
|
||||
{% if is_gold %}
|
||||
<input type="hidden" name="kind" value="gold">
|
||||
<div class="form-grid">
|
||||
<label>Name<input name="name" required placeholder="Gold bar 100g / Krugerrand"></label>
|
||||
<label>Unit<select name="unit"><option value="gram">gram</option><option value="oz">troy ounce</option></select></label>
|
||||
<label>Purity<select name="purity"><option value="0.9999">24k · 999,9</option><option value="0.9167">22k · 916 (Krugerrand, Sovereign)</option>
|
||||
<option value="0.900">900 (Gulden/Napoleon)</option><option value="0.750">18k · 750</option><option value="0.585">14k · 585</option><option value="0.333">8k · 333</option></select></label>
|
||||
<label>Price source<input name="symbol" value="GC=F" title="Yahoo symbol, USD/oz. GC=F = gold, SI=F = silver"></label>
|
||||
<div><button>Add</button></div>
|
||||
</div>
|
||||
<p class="small muted">Quantity is the item's total weight in the chosen unit; value = weight × purity × spot. Spot is the COMEX gold price
|
||||
converted to EUR; dealers usually buy back 1–3 % below spot (set a manual price per item if you want to be conservative).</p>
|
||||
{% else %}
|
||||
<div class="form-grid">
|
||||
<label>Name<input name="name" required placeholder="Vanguard FTSE All-World"></label>
|
||||
<label>Type<select name="kind"><option value="stock">Stock / ETF</option><option value="crypto">Crypto</option></select></label>
|
||||
<label>Symbol<input name="symbol" required placeholder="VWRL.AS · bitcoin"></label>
|
||||
<div><button>Add</button></div>
|
||||
</div>
|
||||
<p class="small muted"><strong>Stocks/ETFs:</strong> Yahoo Finance ticker incl. exchange suffix (VWRL.AS, IWDA.AS, ASML.AS, AAPL), converted to EUR.
|
||||
<strong>Crypto:</strong> CoinGecko id (bitcoin, ethereum, solana, cardano…) — find it in the coin's URL on coingecko.com.</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>{{ icon('clock') }} History</h2>
|
||||
<div class="table-wrap"><table>
|
||||
<thead><tr><th>Date</th><th>Asset</th><th>Side</th><th class="num">Qty</th><th class="num">Price</th><th class="num">Fees</th><th class="num">Total</th><th>Note</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for tr in trades %}
|
||||
<tr><td>{{ tr.date.strftime('%d-%m-%Y') }}</td><td>{{ tr.asset.name }}</td><td><span class="badge {{ 'good' if tr.side == 'buy' else 'warn' }}">{{ tr.side }}</span></td>
|
||||
<td class="num">{{ tr.quantity|num }}</td><td class="num">{{ tr.price|eur }}</td><td class="num">{{ tr.fees|eur }}</td>
|
||||
<td class="num">{{ (tr.quantity * tr.price + (tr.fees if tr.side == 'buy' else -tr.fees))|eur }}</td><td class="small">{{ tr.notes }}</td>
|
||||
<td><form method="post" action="/trades/{{ tr.id }}/delete" data-confirm="Delete this trade?"><button class="sm ghost icon" title="Delete">{{ icon('trash-2', 'sm') }}</button></form></td></tr>
|
||||
{% else %}<tr><td colspan="9" class="muted">No trades yet.</td></tr>{% endfor %}
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user