Skip to contents

Imports instrument metadata into snapshot_instruments for a snapshot in status CREATED (snapshot mutability rule).

Usage

ledgr_snapshot_import_instruments_csv(
  con,
  snapshot_id,
  instruments_csv_path,
  encoding = "UTF-8",
  strict = TRUE
)

Arguments

con

A DBI connection to DuckDB.

snapshot_id

Snapshot id (must exist and be status CREATED).

instruments_csv_path

Path to instruments CSV.

encoding

File encoding (default "UTF-8").

strict

If TRUE, fail loud on any contract violation.

Value

Invisibly returns TRUE on success.

Details

CSV contract (v0.1.1 spec section 6.2):

  • Required columns: instrument_id, symbol

  • Optional columns (defaults): currency ("USD"), asset_class ("EQUITY"), multiplier (1.0), tick_size (0.01)

  • Encoding: UTF-8 (BOM tolerated and stripped)

Errors:

  • LEDGR_SNAPSHOT_NOT_FOUND if snapshot_id does not exist.

  • LEDGR_SNAPSHOT_NOT_MUTABLE if snapshot status is not CREATED.

  • LEDGR_CSV_FORMAT_ERROR on CSV contract/parse violations or duplicate PKs.

Examples

db_path <- tempfile(fileext = ".duckdb")
con <- ledgr_db_init(db_path)
snapshot_id <- ledgr_snapshot_create(
  con,
  snapshot_id = "snapshot_20200101_000000_abcd"
)
instruments_csv <- tempfile(fileext = ".csv")
utils::write.csv(data.frame(
  instrument_id = "AAA",
  symbol = "AAA"
), instruments_csv, row.names = FALSE)
ledgr_snapshot_import_instruments_csv(con, snapshot_id, instruments_csv)
DBI::dbDisconnect(con, shutdown = TRUE)