Value positions from a daily price feed

A position was a share count. An instrument now carries a market symbol and
the last close fetched for it, so Wealth and the dashboard report cash plus
market value instead of cash alone.

The symbol is chosen by hand and never derived: one ISIN lists on several
exchanges in different currencies, and a price from the wrong listing misstates
wealth without failing any check. The refresh refuses a quote whose currency
differs from the instrument's, keeps the previous quote when a symbol cannot be
priced, and counts an instrument with no symbol as unpriced - naming it in a
check and leaving it out of every total, because cost is not value. The quote
belongs to the job: saving an instrument can neither set nor erase it, and
changing the symbol discards it.

Two things the provider forced. It answers HTTP 429 to every request whose
User-Agent names a programming language, so the client identifies as a browser;
without that header the first call of the day fails. Its closes are 32-bit
floats widened to 64 - 165.26 arrives as 165.25999450683594 - so a figure is
rounded to seven significant digits, which is what 24 mantissa bits carry;
eight would have stored 165.25999 as a price.

Accepted quotes are written in one commit against a revision re-read after the
fetches, and nothing is committed when no quote changed. The automatic run
starts shortly after launch and repeats daily on its own timer, so a sync
backoff cannot delay it and prices arrive with no bank connected.

Verified against live quotes end to end: 80 shares at 125.45 and 40 at 165.26
on 6000.00 cash report 22646.40 with one holding named as unpriced; giving that
holding a symbol through the UI moves the figure to 23530.50, and a second
refresh leaves the revision untouched.
This commit is contained in:
Lars Nolden
2026-09-12 18:42:07 +02:00
parent 2373790be3
commit 588c16ad19
19 changed files with 1580 additions and 55 deletions
+87
View File
@@ -23,6 +23,7 @@ import type {
Group,
MonthlyPoint,
Total,
Wealth,
} from "./api";
import { compactMoney, money, request } from "./api";
import { Empty, ErrorMessage, Filters } from "./ui";
@@ -394,6 +395,7 @@ export function Overview({
))}
</div>
)}
<WealthStrip revision={revision} currency={currency} />
{total ? (
<StatStrip
total={total}
@@ -547,6 +549,91 @@ function Trend({
);
}
// WealthStrip is what you own, not what you spent: the dashboard's flow figures
// come from the analytics index, while this comes from the journal, so it is
// fetched separately rather than joined into a filtered query. The filters do
// not apply - a balance has no date range.
function WealthStrip({
revision,
currency,
}: {
revision: string;
currency: string;
}) {
const [wealth, setWealth] = useState<Wealth | null>(null);
const [error, setError] = useState("");
useEffect(() => {
const controller = new AbortController();
request<Wealth>("/api/wealth", undefined, controller.signal)
.then((value) => {
for (const account of value.accounts ?? []) account.checks ??= [];
setWealth({
...value,
accounts: value.accounts ?? [],
totals: value.totals ?? [],
});
setError("");
})
.catch((e) => {
if (e.name !== "AbortError") setError(String(e.message || e));
});
return () => controller.abort();
}, [revision]);
if (error)
return (
<section className="panel">
<div className="panel-heading">
<div>
<h3>
<PiggyBank size={17} />
Wealth
</h3>
<p>Could not be computed: {error}</p>
</div>
</div>
</section>
);
if (!wealth || wealth.totals.length === 0) return null;
// The selected currency when it has a balance, otherwise the first one: a
// figure in the wrong currency is worse than a figure in another tab.
const total =
wealth.totals.find((t) => t.currency === currency) ?? wealth.totals[0];
const positions = wealth.accounts.filter(
(account) => account.holdings.length > 0,
).length;
const failing = wealth.accounts.filter((account) =>
account.checks.some((check) => check.failed),
).length;
return (
<section className="panel">
<div className="panel-heading">
<div>
<h3>
<PiggyBank size={17} />
Wealth today
</h3>
<p>
{money(total.cash, total.currency)} cash ·{" "}
{money(total.positions, total.currency)} in positions across{" "}
{positions} investment account
{positions === 1 ? "" : "s"}
{total.unpriced > 0 &&
` · ${total.unpriced} holding${total.unpriced === 1 ? "" : "s"} without a quote, excluded`}
{failing > 0 &&
` · ${failing} account${failing === 1 ? "" : "s"} disagree with their own records`}
</p>
</div>
<div className="figure">
<span className="eyebrow">{total.currency}</span>
<span className="large-money money">
{money(total.wealth, total.currency)}
</span>
</div>
</div>
</section>
);
}
function StatStrip({
total,
previous,
+25 -2
View File
@@ -79,7 +79,7 @@ export function Registry({
use_defaults: false,
}
: entity === "instrument"
? { id: "", isin: "", name: "", currency: "EUR" }
? { id: "", isin: "", name: "", currency: "EUR", symbol: "" }
: { id: "", name: "" },
);
const row = (item: Item, depth = 0) => (
@@ -114,7 +114,12 @@ export function Registry({
{"hint" in item && item.hint && <small>{item.hint}</small>}
{"isin" in item && (
<small>
{item.isin} · {item.currency}
{item.isin} · {item.currency} ·{" "}
{item.symbol
? item.quote
? `${item.symbol} at ${item.quote} on ${item.quoted_at}`
: `${item.symbol}, not yet quoted`
: "No market symbol, so unpriced"}
</small>
)}
</div>
@@ -434,6 +439,7 @@ function RegistryEditor({
const instrument = "isin" in item ? item : null;
const [isin, setIsin] = useState(instrument?.isin || "");
const [currency, setCurrency] = useState(instrument?.currency || "EUR");
const [symbol, setSymbol] = useState(instrument?.symbol || "");
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
const descendants = new Set([item.id]);
@@ -489,6 +495,7 @@ function RegistryEditor({
isin: isin.replaceAll(" ", "").toUpperCase(),
name: name.trim(),
currency: currency.toUpperCase(),
symbol: symbol.trim(),
}
: { id: item.id, name: name.trim(), hint: hint.trim() };
await mutate(
@@ -628,6 +635,22 @@ function RegistryEditor({
onChange={(e) => setCurrency(e.target.value.toUpperCase())}
/>
</Field>
<Field
label="Market symbol"
hint="The listing the daily price job quotes this security under, for example EUNL.DE. One ISIN lists on several exchanges in different currencies, so the listing has to match the currency above; the wrong one misstates your wealth. Leave it empty and the holding is reported as unpriced rather than guessed at cost."
>
<input
value={symbol}
placeholder="Unpriced"
onChange={(e) => setSymbol(e.target.value.trim())}
/>
</Field>
{instrument?.quote && (
<p className="muted">
Last quote {instrument.quote} {instrument.currency} from{" "}
{instrument.quoted_at}.
</p>
)}
<p className="muted">
The broker's own description for one ISIN changes over time, so
the name is display text you can correct. Renaming does not
+193 -24
View File
@@ -6,7 +6,7 @@ import {
Landmark,
PiggyBank,
} from "lucide-react";
import type { Wealth, WealthAccount } from "./api";
import type { QuoteResult, State, Wealth, WealthAccount } from "./api";
import { money, request } from "./api";
import { Empty, ErrorMessage } from "./ui";
@@ -14,11 +14,19 @@ import { Empty, ErrorMessage } from "./ui";
// never cached: it exists to be compared with a bank or broker's own screen.
// Renaming a security lives in the Instruments registry, beside every other
// registry entity, rather than being a second editor here.
export default function WealthPage({ revision }: { revision: string }) {
export default function WealthPage({
revision,
acceptState,
}: {
revision: string;
acceptState: (state: State, message?: string) => void;
}) {
const [wealth, setWealth] = useState<Wealth | null>(null);
const [error, setError] = useState("");
const [loading, setLoading] = useState(true);
const [retry, setRetry] = useState(0);
const [pricing, setPricing] = useState(false);
const [priced, setPriced] = useState<QuoteResult | null>(null);
useEffect(() => {
const controller = new AbortController();
setLoading(true);
@@ -31,6 +39,7 @@ export default function WealthPage({ revision }: { revision: string }) {
if (value[key] === null) Object.assign(value, { [key]: [] });
}
for (const account of value.accounts) {
account.flows ??= [];
account.holdings ??= [];
account.checks ??= [];
}
@@ -65,15 +74,79 @@ export default function WealthPage({ revision }: { revision: string }) {
that decide whether the figures can be trusted.
</p>
</div>
<button
className="button secondary"
onClick={() => setRetry(retry + 1)}
disabled={loading}
>
Recheck figures
</button>
<div className="row-actions">
<button
className="button secondary"
onClick={async () => {
setPricing(true);
setError("");
try {
// The run commits quotes to the journal, so the new revision
// has to reach the shell: it is what every other page reads,
// and what re-runs the report below.
const result = await request<QuoteResult>(
"/api/quotes/refresh",
{ method: "POST" },
);
setPriced(result);
acceptState(
result.state,
`${result.updated} quote${result.updated === 1 ? "" : "s"} updated`,
);
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
} finally {
setPricing(false);
}
}}
disabled={pricing || loading}
>
{pricing ? "Fetching prices…" : "Refresh prices"}
</button>
<button
className="button secondary"
onClick={() => setRetry(retry + 1)}
disabled={loading}
>
Recheck figures
</button>
</div>
</div>
<ErrorMessage error={error} />
{priced && (
<div
className={`alert ${priced.failures.length > 0 ? "warning" : ""}`}
role="status"
>
<CandlestickChart size={19} />
<div>
<strong>
{priced.updated} quote{priced.updated === 1 ? "" : "s"} updated,{" "}
{priced.unchanged} already current, {priced.skipped} without a
market symbol.
</strong>
{priced.failures.length > 0 && (
<p>
{priced.failures.map((failure) => (
<span key={failure.instrument_id}>
{failure.symbol || failure.isin}: {failure.error}
<br />
</span>
))}
A symbol that cannot be priced keeps its last quote rather than
losing it. Correct the symbol in Instruments if the listing is
wrong.
</p>
)}
{priced.skipped > 0 && priced.failures.length === 0 && (
<p>
Set a market symbol on each unpriced instrument in Instruments
to bring it into the wealth figure.
</p>
)}
</div>
</div>
)}
{loading ? (
<div className="loading-block" role="status">
<span className="spinner" />
@@ -105,26 +178,49 @@ export default function WealthPage({ revision }: { revision: string }) {
<div>
<h3>
<PiggyBank size={17} />
Total cash
Total wealth
</h3>
<p>
Every recorded movement summed per currency, across all{" "}
{wealth.accounts.length} account
Cash plus the market value of every priced holding, per
currency, across all {wealth.accounts.length} account
{wealth.accounts.length === 1 ? "" : "s"}.
</p>
</div>
</div>
<div className="registry">
<div className="preview-summary">
<div className="figure">
{wealth.totals.map((total) => (
<span key={total.currency}>
<span className="eyebrow">{total.currency}</span>
<span className="large-money money">
{money(total.wealth, total.currency)}
</span>
</span>
))}
</div>
</div>
<div className="registry">
{wealth.totals.map((total) => (
<div className="preview-summary" key={total.currency}>
<span>
<strong className="money">
{money(total.cash, total.currency)}
</strong>{" "}
in cash
</span>
))}
</div>
<span>
<strong className="money">
{money(total.positions, total.currency)}
</strong>{" "}
in positions
</span>
{total.unpriced > 0 && (
<span>
<strong>{total.unpriced}</strong> holding
{total.unpriced === 1 ? "" : "s"} without a quote,
excluded
</span>
)}
</div>
))}
</div>
</section>
)}
@@ -219,13 +315,61 @@ function AccountReport({ account }: { account: WealthAccount }) {
{!account.active && " · archived"}
</p>
</div>
<div>
<span className="eyebrow">Cash balance</span>
<span className="large-money money">
{money(account.cash, account.currency)}
<div className="figure">
<span className="eyebrow">
{investing ? "Cash and positions" : "Cash balance"}
</span>
<span className="large-money money">
{money(account.wealth, account.currency)}
</span>
{investing && (
<small className="muted">
{money(account.cash, account.currency)} cash ·{" "}
{money(account.positions, account.currency)} positions
{account.unpriced > 0 &&
` · ${account.unpriced} unpriced, excluded`}
</small>
)}
</div>
</div>
{(account.flows ?? []).length > 0 && (
<div className="table-scroll">
<table>
<thead>
<tr>
<th>What moved the cash</th>
<th className="numeric">Records</th>
<th className="numeric">Cash</th>
</tr>
</thead>
<tbody>
{account.flows.map((flow) => (
<tr key={flow.event}>
<td>{flow.label}</td>
<td className="numeric">{flow.records}</td>
<td className="numeric money">
{money(flow.cash, account.currency)}
</td>
</tr>
))}
<tr>
<td>
<strong>Balance</strong>
</td>
<td className="numeric">{account.records}</td>
<td className="numeric money">
<strong>{money(account.cash, account.currency)}</strong>
</td>
</tr>
</tbody>
</table>
<p className="hint">
Compare each line against your broker&rsquo;s own screen. A total
that disagrees points at one kind of record, not at the whole
history.
</p>
</div>
)}
{account.holdings.length > 0 && (
<div className="table-scroll">
<table>
@@ -234,8 +378,10 @@ function AccountReport({ account }: { account: WealthAccount }) {
<th>Instrument</th>
<th>ISIN</th>
<th className="numeric">Quantity</th>
<th className="numeric">Quote</th>
<th className="numeric">Value</th>
<th className="numeric">Invested</th>
<th className="numeric">Received</th>
<th className="numeric">Result</th>
<th className="numeric">Records</th>
</tr>
</thead>
@@ -263,10 +409,33 @@ function AccountReport({ account }: { account: WealthAccount }) {
)}
</td>
<td className="numeric money">
{money(holding.invested, account.currency)}
{holding.quote ? (
<>
{holding.quote}
<small className="muted">{holding.quoted_at}</small>
</>
) : (
<span className="muted">no quote</span>
)}
</td>
<td className="numeric money">
{money(holding.received, account.currency)}
{holding.priced ? (
money(holding.value ?? "0.00", account.currency)
) : (
<span className="muted">&mdash;</span>
)}
</td>
<td className="numeric money">
{money(holding.invested, account.currency)}
</td>
<td
className={`numeric money ${holding.result?.startsWith("-") ? "text-danger" : holding.priced ? "positive" : ""}`}
>
{holding.result ? (
money(holding.result, account.currency)
) : (
<span className="muted">&mdash;</span>
)}
</td>
<td className="numeric">{holding.records}</td>
</tr>
+49
View File
@@ -20,6 +20,12 @@ export interface Instrument {
isin: string;
name: string;
currency: string;
// symbol is the market listing this security is quoted under, chosen once by
// hand: one ISIN lists in several currencies and the wrong one misstates
// wealth. quote is the last price the daily job fetched for it.
symbol?: string;
quote?: string;
quoted_at?: string;
}
// Investment is the broker-native leg of a fact. Cash movement always stays in
// Facts.amount, so a position-only event carries a zero amount. Quantity is an
@@ -298,6 +304,15 @@ export interface WealthHolding {
quantity: string;
invested: string;
received: string;
// value is the holding at its own quote. priced is false when no quote is
// known, and then value and result are absent rather than guessed from cost.
quote?: string;
quoted_at?: string;
value?: string;
priced: boolean;
// result is the value now plus everything the position returned, less
// everything put into it: the outcome to date, realised and not.
result?: string;
records: number;
}
// WealthCheck is one named verification with its evidence. failed marks a
@@ -307,6 +322,15 @@ export interface WealthCheck {
detail: string;
failed: boolean;
}
// WealthFlow is the cash one kind of record moved. Every flow sums to the
// account's balance, so a total that disagrees with a broker's own figure
// localises to one class of row.
export interface WealthFlow {
event: string;
label: string;
cash: string;
records: number;
}
export interface WealthAccount {
account_id: string;
display_name: string;
@@ -320,12 +344,37 @@ export interface WealthAccount {
// cash is every recorded movement summed. It equals the real balance only
// when the journal holds that account's complete history.
cash: string;
// positions is the market value of every priced holding, and wealth the two
// together. unpriced counts the holdings left out for want of a quote.
positions: string;
wealth: string;
unpriced: number;
flows: WealthFlow[];
holdings: WealthHolding[];
checks: WealthCheck[];
}
// QuoteResult is what one run of the price job did. A failure names the
// instrument it could not price and leaves that instrument's last quote alone,
// so one unreachable listing never blanks a whole portfolio.
export interface QuoteFailure {
instrument_id: string;
isin: string;
symbol: string;
error: string;
}
export interface QuoteResult {
updated: number;
unchanged: number;
skipped: number;
failures: QuoteFailure[];
state: State;
}
export interface WealthTotal {
currency: string;
cash: string;
positions: string;
wealth: string;
unpriced: number;
}
// Wealth is a reconciliation report computed from the journal rather than the
// analytics index, so it can be checked against a bank or broker's own screen.
+3 -1
View File
@@ -401,7 +401,9 @@ function App() {
acceptState={acceptState}
/>
)}
{page === "wealth" && <Wealth revision={state.revision} />}
{page === "wealth" && (
<Wealth revision={state.revision} acceptState={acceptState} />
)}
{page === "classification" && (
<Classification state={state} acceptState={acceptState} />
)}
+11
View File
@@ -1060,6 +1060,17 @@ tbody tr:hover {
color: #8b98a5;
font-size: 11px;
}
/* A headline figure with the split that produced it underneath: the smaller
line has to leave the money's line rather than flow beside it. */
.figure {
text-align: right;
}
.figure small {
display: block;
margin-top: 5px;
color: #8b95a2;
font-size: 11px;
}
.large-money {
font-size: 22px;
font-weight: 600;