Skip to contents

Validates schema, normalizes timestamps, creates a snapshot, imports bars, seals the snapshot, and returns a lazy snapshot object.

Usage

ledgr_snapshot_from_df(
  bars_df,
  instruments_df = NULL,
  db_path = NULL,
  snapshot_id = NULL,
  facts = NULL,
  invalid_observations = c("error", "quarantine"),
  price_basis = NULL
)

Arguments

bars_df

data.frame with required columns: ts_utc, instrument_id, open, high, low, close. Optional: volume. Extra columns are ignored; only canonical bar columns are persisted and hashed.

instruments_df

Optional data.frame with instrument metadata.

db_path

Optional DuckDB file path (default: tempfile).

snapshot_id

Optional snapshot id. When NULL, ledgr generates one.

facts

Optional point-in-time facts created by ledgr_facts().

invalid_observations

Either "error" (the default) or the explicit "quarantine" acknowledgement. Quarantine requires declared sessions in facts.

price_basis

Optional declaration of the economic basis of the bars. Supported values are "split_adjusted" and "distribution_adjusted". NULL leaves the basis undeclared. Distribution-adjusted bars can be sealed for inspection but are refused by ledgr_experiment().

Value

A ledgr_snapshot object.

Articles

Durable experiment stores: vignette("experiment-store", package = "ledgr") system.file("doc", "experiment-store.html", package = "ledgr") Point-in-time facts and quarantine: vignette("survivorship-bias", package = "ledgr") system.file("doc", "survivorship-bias.html", package = "ledgr")

Examples

bars <- data.frame(
  ts_utc = as.POSIXct("2020-01-01", tz = "UTC") + 86400 * 0:2,
  instrument_id = "AAA",
  open = c(100, 101, 102),
  high = c(101, 102, 103),
  low = c(99, 100, 101),
  close = c(100, 101, 102),
  volume = 1000
)
snapshot <- ledgr_snapshot_from_df(bars)
ledgr_snapshot_info(snapshot)
#> # A tibble: 1 × 14
#>   snapshot_id                  status created_at_utc sealed_at_utc snapshot_hash
#>   <chr>                        <chr>  <chr>          <chr>         <chr>        
#> 1 snapshot_20261027_174440_d8… SEALED 2026-10-27T17… 2026-10-27T1… 0152b9a0e0b2…
#> # ℹ 9 more variables: hash_rule_version <int>, verified_in_process <lgl>,
#> #   bar_count <int>, instrument_count <int>, off_session_bar_count <int>,
#> #   start_date <chr>, end_date <chr>, meta_json <chr>, error_msg <chr>
ledgr_snapshot_close(snapshot)