postgres

package
v0.0.0-...-a01f418 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package postgres is the valuation context's store and job queue in PostgreSQL (docs/DESIGN.md D-14, D-36): prices, FX rates, period index readings, bond series terms and tax wrappers; the stored valuations and each account's valued-through date; and the River queue that revalues accounts.

The valuation context owns the valuation schema, and River's tables live in the river schema; Migrate creates and upgrades both. Accounts and instruments refer to the ledger by value only.

Every write of an input enqueues the revaluations it causes in the same database transaction, and so does every ledger import, through Store.ImportHook on the import's own transaction (D-36). Pending revaluations coalesce per account: River keeps at most one RevalueAccount job per account waiting or running (unique by args), and valuation.dirty holds the earliest affected date, lowered with LEAST() by every enqueue. RevalueWorker claims that date, revalues, and clears it in the same transaction that completes the job, under a per-account advisory lock that enqueueing takes too, so a change that arrives during a run is never left without a job.

Index

Constants

View Source
const Queue = "valuation"

Queue is the River queue revaluation jobs run on.

View Source
const RiverSchema = "river"

RiverSchema is the schema River's tables live in, apart from every context's own.

Variables

View Source
var ErrBadMigration = errors.New("bad migration")

ErrBadMigration reports an embedded migration whose name does not start with a version number, or two migrations with one number.

View Source
var ErrCorrupt = errors.New("corrupt valuation data")

ErrCorrupt reports a stored row that does not decode.

View Source
var ErrInvalidConfig = errors.New("invalid revaluation settings")

ErrInvalidConfig reports revaluation settings that cannot be used.

View Source
var ErrNoBondTerms = errors.New("no stored terms of the bond")

ErrNoBondTerms reports a change to the terms of a bond whose terms are not stored.

View Source
var ErrNoLedgerTx = errors.New("ledger store has no database transaction to enqueue in")

ErrNoLedgerTx reports an import hook called with a ledger store that cannot hand over its database transaction.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate applies every embedded valuation migration that the database has not applied yet, in version order, in one database transaction: on any error none of them is applied. An advisory lock makes concurrent calls, such as two replicas starting at once, apply each migration once. It is the ledger store's runner (internal/ledger/postgres), copied so the contexts share no adapter code, with its own version table and lock key. Then it applies River's own migrations into RiverSchema with rivermigrate, which runs each in a transaction of its own, as River requires, under an advisory lock of their own (migrateRiver), so the core and the demo loader can migrate one database at the same moment.

func NewClient

func NewClient(pool *pgxpool.Pool, store *Store, l Ledger, cfg *Config) (*river.Client[pgx.Tx], error)

NewClient returns a River client that works revaluations on Queue with cfg.Concurrency workers and inserts the end-of-day job on cfg.EndOfDay. Start it to run them; enqueueing needs only the Store.

func TodayIn

func TodayIn(loc *time.Location, now func() time.Time) func() kernel.Date

TodayIn returns the current date in loc, read from now.

Types

type Config

type Config struct {
	// Concurrency is how many revaluations run at once: the MaxWorkers of
	// Queue in this process.
	Concurrency int
	// EndOfDay is when the end-of-day revaluation of every account runs.
	EndOfDay DailyAt
	// Pack is the jurisdiction pack that computes each holding's three
	// values (D-70, D-77). Record its rules version with
	// app.InputRecorder.ApplyRules at start-up, which revalues everything
	// when it changed.
	Pack jurisdiction.Pack
	// Today returns the date revaluations value through.
	Today func() kernel.Date
	// Logger receives River's logs; nil is slog's default.
	Logger *slog.Logger
	// Attention raises and clears the attention items revaluations find,
	// such as a gap in a series' market data (D-94); nil raises none.
	Attention app.AttentionRaiser
	// Plugins are River plugins the client installs, such as the core's
	// job tracing; none by default.
	Plugins []rivertype.Plugin
	// Jobs are other contexts' jobs that run on this client. River elects one
	// leader among the clients of a schema, and only it enqueues periodic
	// jobs, so a job that is periodic joins the client that runs the
	// end-of-day one instead of starting a client of its own.
	Jobs []Job
}

Config is what D-36 makes configurable. What triggers a revaluation is not.

type DB

type DB interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

DB is what Store runs its statements on: a *pgxpool.Pool, or anything that answers as one, such as the core's pool that joins the transaction a context carries (see Store.On).

type DailyAt

type DailyAt struct {
	Hour, Minute int
	Location     *time.Location
}

DailyAt is a River schedule that fires once a day at Hour:Minute in Location.

func (DailyAt) Next

func (d DailyAt) Next(current time.Time) time.Time

Next returns the first time after current at Hour:Minute in Location.

type EndOfDay

type EndOfDay struct{}

EndOfDay is the periodic job that revalues every account from its valued-through date.

func (EndOfDay) InsertOpts

func (EndOfDay) InsertOpts() river.InsertOpts

InsertOpts puts the job on Queue.

func (EndOfDay) Kind

func (EndOfDay) Kind() string

Kind names the job kind.

type EndOfDayWorker

type EndOfDayWorker struct {
	river.WorkerDefaults[EndOfDay]
	// contains filtered or unexported fields
}

EndOfDayWorker works EndOfDay jobs: it enqueues the revaluation of every account (app.InputRecorder.EndOfDay).

func (*EndOfDayWorker) Work

func (w *EndOfDayWorker) Work(ctx context.Context, _ *river.Job[EndOfDay]) error

Work enqueues the end-of-day revaluations. A failure reaches River as a *JobError, without the values it carried (GR-12).

type Job

type Job struct {
	// Queue names the job's queue, which must differ from Queue and from
	// every other job's.
	Queue string
	// MaxWorkers is how many of its jobs run at once.
	MaxWorkers int
	// Register adds the job's workers.
	Register func(*river.Workers) error
	// Periodic are the job's periodic inserts.
	Periodic []*river.PeriodicJob
}

Job is a job of another context that runs on the revaluation client: its workers, its own queue so it never waits behind a revaluation, and its periodic schedule, if any.

type JobError

type JobError struct {
	// Job names the job, such as "revaluation job".
	Job string
	// Safe is kernel.LogSafe's description of the failure: the known
	// errors in its chain, or the innermost error's type.
	Safe string
}

JobError is what a worker hands River for a failed job: the job's kind and the failure described without any value it carried (GR-12). River logs a failed job's error in full and keeps it in river_job.errors, and a revaluation's failure can quote a lot's cost and quantity, a transaction's sums or an ISIN, so neither ever sees more than this.

func (*JobError) Error

func (e *JobError) Error() string

Error names the job and the failure by its kind only.

type Ledger

type Ledger interface {
	app.AccountLister
	app.TransactionLog
}

Ledger is what the workers read from the ledger context: its accounts and their logs. ledger/app.Ledger and the ledger's store provide them.

type RevalueAccount

type RevalueAccount struct {
	Account string `json:"account" river:"unique"`
}

RevalueAccount is the job that revalues one account. Its args name only the account: River keeps at most one such job per account waiting or running (unique by args), and the date to revalue from is in valuation.dirty, where every enqueue lowers it to the earliest (D-36).

func (RevalueAccount) InsertOpts

func (RevalueAccount) InsertOpts() river.InsertOpts

InsertOpts puts the job on Queue, unique per account among jobs waiting or running. Completed jobs don't count, so a change after a run enqueues a new one.

func (RevalueAccount) Kind

func (RevalueAccount) Kind() string

Kind names the job kind.

type RevalueWorker

type RevalueWorker struct {
	river.WorkerDefaults[RevalueAccount]
	// contains filtered or unexported fields
}

RevalueWorker works RevalueAccount jobs: it revalues the account from its pending from-date until no change is left, then completes the job in the same transaction that clears the pending date, so that no change is ever left without a job.

func (*RevalueWorker) Work

Work revalues job's account. A failure reaches River as a *JobError, without the values it carried (GR-12).

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the valuation context's store in PostgreSQL, in the valuation schema that Migrate creates: inputs, stored valuations and pending revaluations. Every write of an input enqueues its revaluations in the same database transaction, through River (D-36).

func NewStore

func NewStore(pool *pgxpool.Pool, plugins ...rivertype.Plugin) (*Store, error)

NewStore returns the store over pool. Run Migrate first. Its River client, which only enqueues, installs plugins, such as the core's job tracing.

func (*Store) AccountForm

func (s *Store) AccountForm(ctx context.Context, account ledger.AccountID) (jurisdiction.AccountForm, bool, error)

AccountForm returns account's form (D-147), and false when none is stored.

func (*Store) AllBondTerms

func (s *Store) AllBondTerms(ctx context.Context) (map[ledger.ISIN]pl.Terms, error)

AllBondTerms returns every stored series' terms by ISIN.

func (*Store) AppendPriceCheckAcknowledgement

func (s *Store) AppendPriceCheckAcknowledgement(ctx context.Context, ack *valuation.PriceCheckAcknowledgement) error

AppendPriceCheckAcknowledgement records an acknowledgement; the table refuses any change to one recorded (D-112).

func (*Store) AvailableSources

func (s *Store) AvailableSources(ctx context.Context, series valuation.Series) ([]string, error)

AvailableSources returns the sources with a value of series, by name.

func (*Store) BondTerms

func (s *Store) BondTerms(ctx context.Context, isin ledger.ISIN) (pl.Terms, bool, error)

BondTerms returns the series terms of the bond with isin, with their attribution when they were read from published data and where their fee came from (D-97), and false when none are stored.

func (*Store) ChartStart

func (s *Store) ChartStart(ctx context.Context, account ledger.AccountID) (kernel.Date, error)

ChartStart returns the charts' start the owner stored for account, or for the portfolio when account is empty (D-167), and the zero date when none is stored.

func (*Store) CrossCheckedPrices

func (s *Store) CrossCheckedPrices(ctx context.Context) ([]valuation.Price, []valuation.CrossCheckPrice, error)

CrossCheckedPrices returns the prices to compare and what to compare them with (D-22, D-94, D-111): the prices of each instrument's one source (SourceOf) for every instrument that has a cross-check price or prices from more than one source, in instrument then date order; and every cross-check price with every other source's price as one (valuation.OtherSourceChecks), in instrument, date and source order.

func (*Store) EarlierPayments

func (s *Store) EarlierPayments(ctx context.Context, account ledger.AccountID) (kernel.Money, bool, error)

EarlierPayments returns the total paid into account before its history is known, as the owner entered it (D-149), and false when none is stored.

func (*Store) Enqueue

func (s *Store) Enqueue(ctx context.Context, revals []valuation.Revaluation) error

Enqueue enqueues revals in a database transaction of its own.

func (*Store) ExemptionClasses

func (s *Store) ExemptionClasses(ctx context.Context) (map[string]jurisdiction.ExemptionClass, error)

ExemptionClasses returns the owner's class of each instrument they classified for a yearly tax (D-132), by instrument.

func (*Store) FXRates

func (s *Store) FXRates(ctx context.Context, currency kernel.Currency, through kernel.Date) ([]valuation.FXRate, error)

FXRates returns the rates of currency dated on or before through from its one source (SourceOf), in date order: never another source's (D-94). None when no source has a rate of it.

func (*Store) FeeRule

func (s *Store) FeeRule(ctx context.Context, account ledger.AccountID) (jurisdiction.FeeRule, error)

FeeRule returns account's fee rule, the zero rule unless one is stored.

func (*Store) ForgetAccount

func (s *Store) ForgetAccount(ctx context.Context, account ledger.AccountID) error

ForgetAccount removes what the valuation schema holds of a deleted account (D-120), in one transaction: its tax wrapper and fee rule, its form and earlier payments (D-147, D-149), its charts' start (D-167), its stored valuations, its valuation status and any pending revaluation. An account the ledger deleted held no transactions, so its valuations are derived from nothing (D-36). Forgetting it again changes nothing.

func (*Store) GapThresholds

func (s *Store) GapThresholds(ctx context.Context) (valuation.GapThresholds, error)

GapThresholds returns the owner's gap threshold of each kind that has one (D-94).

func (*Store) ImportHook

func (s *Store) ImportHook() ledgerapp.ImportHook

ImportHook returns the ledger import hook that enqueues a revaluation of every account an import changed, from its earliest affected date, in the import's own database transaction (D-36). The ledger store must hand that transaction over with WithTx, as ledger/postgres.Store does.

func (*Store) IndexLevels

func (s *Store) IndexLevels(ctx context.Context, index string, through kernel.Date) ([]valuation.IndexLevel, error)

IndexLevels returns every level of the market index named index dated on or before through, in date order.

func (*Store) IndexReadings

func (s *Store) IndexReadings(ctx context.Context) ([]valuation.IndexReading, error)

IndexReadings returns the readings of each index kind from its one source (SourceOf), in kind, year and month order: never another source's (D-94).

func (*Store) JobsFailedAtLeast

func (s *Store) JobsFailedAtLeast(ctx context.Context, kind string, failures int) (int, error)

JobsFailedAtLeast returns how many jobs of kind are still waiting to run again after failing at least failures attempts: a job that River keeps retrying and that has not got through. It reads the job queue valuation owns (D-36) for the audit outbox's check (D-211); a finished job, completed, cancelled or discarded, counts for none.

func (*Store) LatestPrices

func (s *Store) LatestPrices(ctx context.Context, isin string) ([]valuation.Price, error)

LatestPrices returns the latest stored price of each listing of the instrument with ISIN isin from each source, in listing then source order: what the instrument page shows next to each listing's price source (D-195).

func (*Store) NumberFormat

func (s *Store) NumberFormat(ctx context.Context) (jurisdiction.NumberFormat, bool, error)

NumberFormat returns the owner's number format, and false unless one is stored.

func (*Store) On

func (s *Store) On(db DB) *Store

On returns the store running its statements on db, which must be over the pool the store was made with, sharing its River client.

func (*Store) PriceCheckAcknowledgements

func (s *Store) PriceCheckAcknowledgements(ctx context.Context) ([]valuation.PriceCheckAcknowledgement, error)

PriceCheckAcknowledgements returns every acknowledgement recorded, the oldest first.

func (*Store) PriceCheckThresholds

func (s *Store) PriceCheckThresholds(ctx context.Context) (valuation.Thresholds, error)

PriceCheckThresholds returns the owner's threshold of each instrument that has one (D-110).

func (*Store) PriceHistory

func (s *Store) PriceHistory(ctx context.Context, isin string, from, to kernel.Date) ([]valuation.Price, error)

PriceHistory returns every stored price of the instruments with ISIN isin, each listing written as ledger.Instrument.String() ("<ISIN>/<symbol>"), dated in the range from through to, both inclusive, from every source (D-94), in instrument, date and source order: the instrument page's price history with its sources (D-195). Which source values each listing is its series' (SourceOf).

func (*Store) Prices

func (s *Store) Prices(ctx context.Context, instrument string, through kernel.Date) ([]valuation.Price, error)

Prices returns the prices of instrument dated on or before through from its one source (SourceOf), in date order: never another source's, which only cross-check them (D-94, valuation.PricesBySource). None when no source has a price of it.

func (*Store) RekeyInstrument

func (s *Store) RekeyInstrument(ctx context.Context, from, to ledger.Instrument) error

RekeyInstrument moves what the valuation schema keeps of from to to, in one database transaction, when the registry's ISIN replaces a provisional one (D-214): a treasury bond series' terms, with their source and attribution, the owner's exemption class (D-132), and its prices, cross-check prices, price check threshold and prices source, should it have any. Where to already has its own, to's stay and from's go. The stored valuations stay: the ledger's re-key enqueues the revaluation that replaces them from the first day re-keyed (D-36). The owner's acknowledgements of price checks are append-only and stay with from; treasury bonds have no price checks. With nothing under from, it changes nothing.

func (*Store) ReplaceValuations

func (s *Store) ReplaceValuations(ctx context.Context, account ledger.AccountID, from kernel.Date, rows []valuation.HoldingValuation, through kernel.Date) error

ReplaceValuations removes account's valuations dated on or after from, upserts rows, keyed by account, instrument, date and basis, and records through as the account's valued-through date, in one database transaction.

func (*Store) SaveAccountForm

func (s *Store) SaveAccountForm(ctx context.Context, account ledger.AccountID, form jurisdiction.AccountForm) error

SaveAccountForm records account's form, replacing any earlier one. No stored valuation depends on it, so nothing is revalued.

func (*Store) SaveBondFee

func (s *Store) SaveBondFee(ctx context.Context, isin ledger.ISIN, fee kernel.Money, source pl.FeeSource, revals []valuation.Revaluation) error

SaveBondFee stores fee as the early-redemption fee of the bond with isin, from source, keeping its other terms, and enqueues revals in one transaction (D-97). Terms that are not stored fail with ErrNoBondTerms.

func (*Store) SaveBondTerms

func (s *Store) SaveBondTerms(ctx context.Context, isin ledger.ISIN, terms *pl.Terms, source string, revals []valuation.Revaluation) error

SaveBondTerms upserts the series terms of the bond with isin, with the connector instance source that delivered them (D-179) and their attribution, if any, and where their fee came from (D-97), and enqueues revals in one transaction. The latest terms replace the row whole, so terms the owner entered after published ones drop the attribution.

func (*Store) SaveBondTermsChanged

func (s *Store) SaveBondTermsChanged(ctx context.Context, isin ledger.ISIN, terms *pl.Terms, source string, revals []valuation.Revaluation) (bool, error)

SaveBondTermsChanged is SaveBondTerms that also reports whether the terms were new or differed in anything from those stored: the same terms from the same source, sent again, change nothing.

func (*Store) SaveChartStart

func (s *Store) SaveChartStart(ctx context.Context, account ledger.AccountID, start kernel.Date) error

SaveChartStart stores start as the charts' start of account, or of the portfolio when account is empty; a zero start removes the setting.

func (*Store) SaveCrossCheckPrices

func (s *Store) SaveCrossCheckPrices(ctx context.Context, prices []valuation.CrossCheckPrice) error

SaveCrossCheckPrices upserts cross-check prices in one transaction, keyed by instrument, date and source. They cause no revaluation.

func (*Store) SaveEarlierPayments

func (s *Store) SaveEarlierPayments(ctx context.Context, account ledger.AccountID, paid kernel.Money) error

SaveEarlierPayments records the total paid into account before its history is known, replacing any earlier one. Totals are taxed when read, so nothing is revalued.

func (*Store) SaveExemptionClass

func (s *Store) SaveExemptionClass(ctx context.Context, instrument string, class jurisdiction.ExemptionClass) error

SaveExemptionClass sets instrument's class, replacing any earlier one.

func (*Store) SaveFXRates

func (s *Store) SaveFXRates(ctx context.Context, rates []valuation.FXRate, revals []valuation.Revaluation) error

SaveFXRates upserts rates and enqueues revals in one transaction.

func (*Store) SaveFXRatesChanged

func (s *Store) SaveFXRatesChanged(ctx context.Context, rates []valuation.FXRate, revals []valuation.Revaluation) (int, error)

SaveFXRatesChanged is SaveFXRates that also returns how many rates were new or differed from the stored one.

func (*Store) SaveFeeRule

func (s *Store) SaveFeeRule(ctx context.Context, account ledger.AccountID, rule *jurisdiction.FeeRule, revals []valuation.Revaluation) error

SaveFeeRule records account's fee rule and enqueues revals in one transaction.

func (*Store) SaveGapThreshold

func (s *Store) SaveGapThreshold(ctx context.Context, kind valuation.MarketDataKind, days int) error

SaveGapThreshold sets kind's gap threshold to days.

func (*Store) SaveIndexLevels

func (s *Store) SaveIndexLevels(ctx context.Context, levels []valuation.IndexLevel) error

SaveIndexLevels upserts market index levels in one transaction. They cause no revaluation.

func (*Store) SaveIndexLevelsChanged

func (s *Store) SaveIndexLevelsChanged(ctx context.Context, levels []valuation.IndexLevel) (int, error)

SaveIndexLevelsChanged is SaveIndexLevels that also returns how many levels were new or differed, in their level or their source, from the stored one: levels sent again unchanged are none.

func (*Store) SaveIndexReadings

func (s *Store) SaveIndexReadings(ctx context.Context, readings []valuation.IndexReading, revals []valuation.Revaluation) error

SaveIndexReadings upserts readings and enqueues revals in one transaction.

func (*Store) SaveIndexReadingsChanged

func (s *Store) SaveIndexReadingsChanged(ctx context.Context, readings []valuation.IndexReading, revals []valuation.Revaluation) (int, error)

SaveIndexReadingsChanged is SaveIndexReadings that also returns how many readings were new or differed from the stored one.

func (*Store) SaveMarginalRate

func (s *Store) SaveMarginalRate(ctx context.Context, rate kernel.Decimal, revals []valuation.Revaluation) error

SaveMarginalRate records the owner's marginal income tax rate and enqueues revals in one transaction.

func (*Store) SaveNumberFormat

func (s *Store) SaveNumberFormat(ctx context.Context, format jurisdiction.NumberFormat) error

SaveNumberFormat records the owner's number format.

func (*Store) SavePriceCheckThreshold

func (s *Store) SavePriceCheckThreshold(ctx context.Context, instrument string, threshold *kernel.Decimal) error

SavePriceCheckThreshold sets instrument's threshold, or removes it when threshold is nil.

func (*Store) SavePrices

func (s *Store) SavePrices(ctx context.Context, prices []valuation.Price, revals []valuation.Revaluation) error

SavePrices upserts prices and enqueues revals in one transaction.

func (*Store) SavePricesChanged

func (s *Store) SavePricesChanged(ctx context.Context, prices []valuation.Price, revals []valuation.Revaluation) (int, error)

SavePricesChanged is SavePrices that also returns how many prices were new or differed from the stored one: prices sent again unchanged are none.

func (*Store) SaveRulesVersion

func (s *Store) SaveRulesVersion(ctx context.Context, version string, revals []valuation.Revaluation) (bool, error)

SaveRulesVersion records version and, only when the recorded version differs or none was recorded, enqueues revals, in one transaction. It reports whether it enqueued them.

func (*Store) SaveSeriesSource

func (s *Store) SaveSeriesSource(ctx context.Context, ss *valuation.SeriesSource, revals []valuation.Revaluation) (bool, error)

SaveSeriesSource records ss.Source as the owner's choice of ss.Series' source and, only when the source changed, enqueues revals in the same transaction (D-36). It reports whether the source changed.

func (*Store) SaveSourceRanking

func (s *Store) SaveSourceRanking(ctx context.Context, kind valuation.MarketDataKind, placed []string, revals []valuation.Revaluation) (bool, error)

SaveSourceRanking replaces the owner's order of kind's sources with placed and, only when it differs from the stored one, enqueues revals in the same transaction (D-36). It reports whether it changed.

func (*Store) SaveSources

func (s *Store) SaveSources(ctx context.Context, sources []valuation.Source) error

SaveSources records sources in valuation.sources, each kind and source once, with the institution it last named.

func (*Store) SaveTaxWrapper

func (s *Store) SaveTaxWrapper(ctx context.Context, account ledger.AccountID, wrapper jurisdiction.Wrapper, revals []valuation.Revaluation) error

SaveTaxWrapper records account's tax wrapper and enqueues revals in one transaction.

func (*Store) SeriesSources

func (s *Store) SeriesSources(ctx context.Context) ([]valuation.SeriesSource, error)

SeriesSources returns every series with a recorded source, in kind then key order, each with the sources that have a value of it.

func (*Store) SourceOf

func (s *Store) SourceOf(ctx context.Context, series valuation.Series) (valuation.SeriesSource, bool, error)

SourceOf returns the source series takes its values from (D-94). A series without one gets it now, when it first needs a value: the source with a value of it that its kind's ranking places highest (valuation.ChooseSource), recorded so it never changes unless the owner changes it. It returns false when no source has a value of series yet. Two callers choosing at once record one choice: the first.

func (*Store) SourceRanking

func (s *Store) SourceRanking(ctx context.Context, kind valuation.MarketDataKind) (valuation.Ranking, error)

SourceRanking returns the ranking of kind's sources: the owner's order, then every other source that delivered kind in its default place (valuation.RankSources).

func (*Store) Status

func (s *Store) Status(ctx context.Context, account ledger.AccountID) (app.ValuationStatus, error)

Status returns account's valuation status, as Statuses does; an account never revalued and with nothing pending has a zero date and neither flag.

func (*Store) Statuses

func (s *Store) Statuses(ctx context.Context) ([]app.ValuationStatus, error)

Statuses returns the valuation status of every account that was ever revalued or has a revaluation pending or running, in account order (D-36): its valued-through date, zero if never valued; Pending when a change is not yet picked up, a job is waiting, or pending work has no running job (such as a failed one); Running when a job runs now.

func (*Store) TaxWrapper

func (s *Store) TaxWrapper(ctx context.Context, account ledger.AccountID) (jurisdiction.Wrapper, bool, error)

TaxWrapper returns account's recorded tax wrapper, and false when none is stored.

func (*Store) Valuations

func (s *Store) Valuations(ctx context.Context, account ledger.AccountID, from, to kernel.Date) ([]valuation.HoldingValuation, error)

Valuations returns account's stored valuations dated on or after from and on or before to, in date, instrument and basis order.

func (*Store) ValueSettings

func (s *Store) ValueSettings(ctx context.Context) (jurisdiction.Settings, error)

ValueSettings returns the owner's marginal income tax rate, unset unless one is stored.

func (*Store) ValuedThrough

func (s *Store) ValuedThrough(ctx context.Context, account ledger.AccountID) (kernel.Date, bool, error)

ValuedThrough returns account's valued-through date, and false when the account was never revalued.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL