Skip to main content

cointoss

CI Docs

Crypto and stock portfolio tracker and research platform.

Built on lythonic (SQLite ORM, DAG composition, CLI) and woodglue (async server, Caddy integration).

Documentation (design records and API reference) | Privacy

A running instance sweeps CoinGecko markets once a day, shortly after 00:00 UTC, records the configured universes (by default cg-top-100: enter at rank 100, exit at 120) and the day's bar per coin (close, volume, market cap), and serves the result over JSON-RPC on 127.0.0.1.

Install

From a checkout, with uv:

uv sync --all-extras

This puts cointoss and woodglue's wgl in .venv/bin. Run them with uv run, or by absolute path, as the systemd unit does.

From PyPI, uv tool install 'cointoss[ui]'. The ui extra (pandas and Streamlit) is what the Dataset explorer needs; without it the API is served as before.

Initialize

uv run cointoss init --systemd

This creates the data directory and writes into it:

  • cointoss.yaml: the declared universes; top_n, the width of the listing each sweep fetches; and bar_window_hours (default 3), how long after 00:00 UTC a sweep still writes the day's bars.
  • woodglue.yaml: the cointoss namespace with its API exposed and its engine running, the daily sweep trigger (5 0 * * *, UTC), host 127.0.0.1, port 5321, and auth on. When Streamlit is installed, also the Dataset explorer as uis.explore (see Explore).
  • cointoss.db, with the declared universes stored.
  • auth.db, holding the bearer token.

With --systemd it also writes ~/.config/systemd/user/cointoss.service, pointing at this checkout's .venv/bin. The template is src/cointoss/cointoss.service.

init is idempotent. It never overwrites a config or unit file that already exists, so edit them freely, and re-run init to validate them. Changes take effect when the service restarts.

A second instance on the same host

--unit NAME installs the unit as NAME.service (only with --systemd). --port N and --schedule CRON (5-field, UTC) set the port and the daily_sweep schedule in a newly written woodglue.yaml. For example, a dev checkout beside an instance installed from PyPI, each with its own virtualenv:

cointoss init --systemd                                  # the installed instance: cointoss.service
uv run cointoss init --systemd --data-dir ~/.local/share/cointoss-dev \
  --unit cointoss-dev --port 5322 --schedule "35 0 * * *"
systemctl --user daemon-reload && systemctl --user enable --now cointoss-dev

Give each instance its own --data-dir, unit name and port. A different schedule keeps the two from calling CoinGecko at the same minute. A schedule that first fires later than bar_window_hours after 00:00 UTC is accepted with a warning: those sweeps record membership but no bars. If woodglue.yaml already exists, init keeps it and says which of --port and --schedule it differs from.

Start

systemctl --user daemon-reload && systemctl --user enable --now cointoss
loginctl enable-linger "$USER"    # keep it running while you are logged out

The unit runs wgl --data=<data dir> start in the foreground and restarts it on failure. If the daily sweep was missed while the service was down, it fires once when the server starts. The sweep does nothing if today is already swept.

Without systemd, run make serve or uv run wgl --data ~/.local/share/cointoss start.

Check

uv run cointoss status             # server, last Evaluation Run per universe, last bar
journalctl --user -u cointoss -e   # service log (without systemd: wgl.log in the data dir)

The API needs the bearer token:

TOKEN=$(uv run cointoss token)
curl -s http://127.0.0.1:5321/rpc \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"cointoss.data:universes","params":{}}'

The other methods are cointoss.data:members (universe, date), changes (universe, start, end), bars (instrument_id, start, end), universes_of (instrument_id, start, end) and runs (universe, limit). Dates are YYYY-MM-DD. A request the store cannot answer is a JSON-RPC error: -32001 for an unknown universe or Instrument, or a date with nothing stored; -32002 before init; -32602 for a malformed parameter.

For exploring, cointoss.data:datasets lists the Datasets -- instruments, bars, returns, membership, changes, runs -- each with its typed columns and the JSON Schema of its params, and cointoss.data:frame (dataset, params) returns one as a long table (columns plus row-major data), at most 250,000 rows:

curl -s http://127.0.0.1:5321/rpc \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"cointoss.data:frame","params":{"dataset":"returns",
       "params":{"start":"2026-10-01","end":"2026-10-31","universe":"cg-top-10"}}}'

From Python, with the ui extra, await cointoss.datasets.load(client, "bars", start=..., end=...) returns a pandas DataFrame with its date columns typed.

To replace the token with a new one (the old one stops working at once):

uv run wgl --data ~/.local/share/cointoss token --new

Explore

With the ui extra, woodglue serves a Streamlit Dataset explorer at /ui/explore/, e.g. http://127.0.0.1:5321/ui/explore/. Sign in to woodglue, pick a Dataset, set its parameters and press Load; it shows the table, a chart (one line per Instrument, cumulative for returns), a pivot of dates by Instrument, and CSV downloads. It reads only through datasets and frame, as the signed-in User, so it shows what their Grants allow and never opens cointoss.db.

init adds it to a new woodglue.yaml:

uis:
  explore:
    kind: streamlit
    app: /path/to/site-packages/cointoss/explorer_app.py
    label: Explore
    grants: [call cointoss]

app is the absolute path of the script in the environment that runs wgl, which woodglue runs it with (python -m streamlit run). init never edits an existing woodglue.yaml: if it has no explore UI, init prints the entry to paste in; if its app no longer exists (say, after reinstalling under another Python), init names this install's script. Restart the service after editing.

The admin can open it. Anyone else needs a Role with view ui:explore and call cointoss. grants limits what the app can do as any viewer to calling the cointoss namespace. call cointoss reaches only the namespace's read nodes: the sweep is not callable over JSON-RPC, and firing its trigger needs trigger cointoss.

Pause the daily sweep

curl -s http://127.0.0.1:5321/rpc \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"system.deactivate_trigger",
       "params":{"namespace":"cointoss","name":"daily_sweep"}}'

The trigger stays paused across restarts. Resume it with system.activate_trigger and the same params. A sweep missed while paused is not caught up.

Sweep by hand

uv run cointoss sweep            # today's (UTC) sweep; a no-op if already done
uv run cointoss sweep --force    # re-fetch today's listing anyway

A sweep records CoinGecko's current listing for today (UTC), so it cannot run for a past date. A day's bar is its price at 00:00 UTC, so bars are written only by a sweep within bar_window_hours of midnight; a later sweep records membership and says no bars. A re-sweep never replaces a bar already stored for the day. Days without bars are left for a future backfill.

Only one sweep runs at a time per data directory, and cointoss backup holds the same lock while it copies. A manual sweep that finds the lock held exits at once with another sweep holds .../sweep.lock. The scheduled sweep waits up to 10 minutes for it instead, so a backup taken at sweep time delays the day's sweep rather than skipping it.

Where the data lives

The data directory is --data-dir, else $COINTOSS_HOME, else ~/.local/share/cointoss. The server takes it from wgl --data, which the unit sets, along with COINTOSS_HOME. If you move the directory, delete the unit and re-run init --data-dir NEW --systemd. A woodglue.yaml written before woodglue 0.0.7 names the directory in the fragment's init.data_dir. That still works, but it overrides wgl --data, so remove it before moving.

File What
cointoss.db Everything cointoss knows: Instruments, universes, membership, runs, bars.
cointoss.yaml, woodglue.yaml Configuration.
auth.db API tokens.
mounts/ woodglue engine state: triggers, DAG runs, cache. Rebuildable.
wgl.log, wgl.pid Server log (only when not under systemd, which logs to the journal) and pid.
sweep.lock Held while a sweep or a backup runs. Safe to delete when neither is.

Backup

cointoss.db is the only file that cannot be rebuilt. cointoss backup copies it, with cointoss.yaml and woodglue.yaml, into a new directory, while the service runs:

uv run cointoss backup /path/to/backups/$(date -u +%Y%m%dT%H%M%SZ)

It copies the database with SQLite's online backup, so the copy is consistent even with writes in flight, and waits up to 10 minutes for a sweep in progress to finish. It writes a manifest.json recording the cointoss version, the database's schema version and the UTC time. It never copies auth.db: a backup is data, not credentials. Naming and pruning backups is up to you.

To restore, into a data directory whose server is stopped and which has no cointoss.db (move an existing one aside first):

systemctl --user stop cointoss
uv run cointoss restore /path/to/backups/20261023T120000Z
uv run cointoss init             # creates a token if the directory has no auth.db
systemctl --user start cointoss

restore replaces the configs with the backup's and removes init.data_dir from a woodglue.yaml written before woodglue 0.0.7, so the restored instance serves its own directory. It refuses a backup whose schema is newer than the installed cointoss reads; to roll back an upgrade, restore a backup taken before it with the older version installed.

Development

make install   # Install dependencies
make lint      # Run linters
make test      # Run tests
make serve     # Run woodglue in the foreground against $COINTOSS_HOME

Metadata

Release files for cointoss 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cointoss 0.0.3
File Size Uploaded Provenance Actions
cointoss-0.0.3.tar.gz 3.2 MB Without provenance Details for cointoss-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cointoss 0.0.3
File Interpreter ABI Platform Actions
cointoss-0.0.3-py3-none-any.whl Python 3 none any Details for cointoss-0.0.3-py3-none-any.whl

Total release size: 3.4 MB

Release files / cointoss-0.0.3.tar.gz

Download URL cointoss-0.0.3.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
8ae210c1a5ed784ece83c60eb053d8f133412989cc5dd2109d4a4992046a71f2
BLAKE2b-256 checksum
How to use checksums
17547545c11a30abd1e5e21f82791e4eda31f8fe2283dcf9dd3488c2873a90f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.13

Release files / cointoss-0.0.3-py3-none-any.whl

Download URL cointoss-0.0.3-py3-none-any.whl
Size 135.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6856584145af68b57f36ce4d8d54791ac8641952d0277afa50912b73f133b962
BLAKE2b-256 checksum
How to use checksums
73d4280c1e548378611423dced8ee33ba1374b128ed7608cb49e0ee0ff09aa0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.13

Security for cointoss 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page