cointoss.config¶
config
¶
cointoss's own configuration, and reconciling what it declares into the store.
A Universe Definition is revision-logged (ADR-0007), so configuration cannot simply be the
Definition: editing a YAML file would otherwise either rewrite history or be ignored. A
UniverseDeclaration declares the rank band a Definition should have now, and ensure_universes
brings the store up to it by the only move the log allows, appending a revision.
What reconciliation owns is deliberately narrow: whether a Definition exists, and its rank band.
Inclusions and Exclusions are hand-pinned through cointoss.ingest.pin_member, carry
provenance that a config file has no way to express, and are never touched here.
portfolio-held (cointoss.portfolio.PORTFOLIO_HELD) is never declared: trades add its
Inclusions and it has no band, so a declaration is refused rather than left to give it one. The
sweep evaluates it beside the declared Definitions once a trade has created it. Nor is
yahoo-industries (cointoss.stocks.YAHOO_INDUSTRIES), a Listing Rule the stock sweep creates
and evaluates on its own.
A Definition removed from the config is simply not reconciled. There is no "retired" flag: the stored Definition, its revisions and its members stay exactly as they were, and anything that decides which Definitions to evaluate reads the declarations rather than the store.
A declaration names no source. Every declared universe is a CoinGecko rank band while the instance is crypto-only, and the Definition itself stores no source (ADR-0007's recipe has none), so a source here would be a field nothing reads. Unknown fields are refused, so a config that does name one fails loudly rather than being silently ignored.
Settings is where a running instance finds all of this. An instance lives in one data
directory, named by --data-dir, else COINTOSS_HOME, else ~/.local/share/cointoss; it holds
cointoss.db and an optional cointoss.yaml declaring the universes and how wide a listing each
sweep fetches, and the bar window: how long after 00:00 UTC a sweep may still record the day's
bars. A missing file means the defaults. The file is validated when loaded, so a config that
could not sweep is refused at startup rather than at the next scheduled run.
ConfigError
¶
DuplicateUniverse
¶
Bases: ConfigError, ValueError
Two declarations name the same Universe Definition.
A ValueError too, so pydantic reports it as a ValidationError when Settings loads.
ReservedUniverse
¶
Bases: ConfigError
A declaration names a Universe Definition that configuration does not own.
UniverseDeclaration
¶
Bases: BaseModel
A Universe Definition as declared in configuration: its name and its rank band.
The band is checked by building the UniverseParameters it stands for, so a bad band is
refused when the config is read, by the same rule that refuses it anywhere else, and raises
that rule's RaggedRule rather than a pydantic ValidationError.
Source code in src/cointoss/config.py
parameters
property
¶
The parameters of a newly created Definition: the band and no pinned members.
Settings
¶
Bases: BaseModel
What a running instance needs to know: where its store is, and what to sweep.
universes are the declared Definitions, reconciled and evaluated by every sweep; top_n is
how many coins the sweep lists, and must reach every declared exit rank. bar_window_hours
is how long after 00:00 UTC a sweep still writes the day's bars; a later sweep records
membership only, since its price is no longer the day's 00:00 price.
Source code in src/cointoss/config.py
load(data_dir=None)
classmethod
¶
The settings of the instance in data_dir, resolved by resolve_data_dir.
Source code in src/cointoss/config.py
Reconciliation
¶
UniverseReconciled
¶
Bases: BaseModel
The outcome for one declaration, and the Definition's latest revision afterwards.
Source code in src/cointoss/config.py
check_unique_names(declarations)
¶
Refuse a name declared twice, since which band would win would depend on list order.
Source code in src/cointoss/config.py
resolve_data_dir(data_dir=None)
¶
The instance's data directory: the one given, else $COINTOSS_HOME, else the XDG default.
Source code in src/cointoss/config.py
ensure_universes(store, declarations, at)
¶
Bring each declared Definition's rank band in the store up to its declaration.
A missing Definition is created at revision 1 dated at. One whose band differs gets one
more revision dated at, carrying its Inclusions and Exclusions forward unchanged; one whose
band matches is left alone. Nothing is deleted or rewritten, and stored Definitions absent
from declarations are not read. Results are in declaration order.
A name declared twice raises DuplicateUniverse before anything is written.