Skip to contents

Validates schema, normalizes timestamps, creates a snapshot via v0.1.1 functions, 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
)

Arguments

bars_df

data.frame with required columns: ts_utc, instrument_id, open, high, low, close. Optional: volume.

instruments_df

Optional data.frame with instrument metadata.

db_path

Optional DuckDB file path (default: tempfile).

snapshot_id

Optional snapshot id (default: v0.1.1 canonical generation).

Value

A ledgr_snapshot object.

Articles

Durable experiment stores: vignette("experiment-store", package = "ledgr") system.file("doc", "experiment-store.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 × 11
#>   snapshot_id        status created_at_utc sealed_at_utc snapshot_hash bar_count
#>   <chr>              <chr>  <chr>          <chr>         <chr>             <int>
#> 1 snapshot_20260515… SEALED 2026-05-15T16… 2026-05-15T1… 4d7d3b7dda80…         3
#> # ℹ 5 more variables: instrument_count <int>, start_date <chr>, end_date <chr>,
#> #   meta_json <chr>, error_msg <chr>
ledgr_snapshot_close(snapshot)