Skip to contents

Computes a deterministic SHA-256 hash over:

  • ordered instrument_ids (order-sensitive)

  • canonical UTC start_ts_utc and end_ts_utc (ISO8601 with trailing Z)

  • a bars fingerprint for the subset ordered by (instrument_id, ts_utc)

Usage

ledgr_data_hash(con, instrument_ids, start_ts_utc, end_ts_utc)

Arguments

con

A DBI connection to DuckDB. This legacy helper does not accept a data frame directly.

instrument_ids

Character vector of instrument ids (order-sensitive).

start_ts_utc

Start timestamp (character ISO8601 ...Z or POSIXt).

end_ts_utc

End timestamp (character ISO8601 ...Z or POSIXt).

Value

A SHA-256 hex string.

Details

Numeric OHLCV values are rounded to 8 decimal places before hashing. Missing values are represented as the literal string NA.

This is a legacy v0.1.0 helper that hashes rows from the raw bars table or a compatible temporary view. It remains exported for compatibility with old low-level workflows, but modern snapshot-backed workflows should use ledgr_snapshot_from_df() or ledgr_snapshot_from_csv() and inspect the sealed snapshot hash with ledgr_snapshot_info().

Examples

db_path <- tempfile(fileext = ".duckdb")
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 = c(1000, 1000, 1000)
)
snapshot <- ledgr_snapshot_from_df(bars, db_path = db_path)
ledgr_snapshot_info(snapshot)$snapshot_hash
#> [1] "4d7d3b7dda8014942878a5b5c89d2ca925bfcee864a038e034e951700a9a4fe6"
ledgr_snapshot_close(snapshot)

if (FALSE) {
  # Legacy v0.1.0 workflows require rows in the raw bars table.
  legacy_path <- tempfile(fileext = ".duckdb")
  con <- ledgr_db_init(legacy_path)
  DBI::dbAppendTable(con, "bars", bars)
  ledgr_data_hash(con, "AAA", "2020-01-01", "2020-01-03")
  DBI::dbDisconnect(con, shutdown = TRUE)
}