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
+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.