Import snapshot instruments from CSV (v0.1.1)
Source:R/snapshots-import-instruments.R
ledgr_snapshot_import_instruments_csv.RdImports 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
)Details
CSV contract (v0.1.1 spec section 6.2):
Required columns:
instrument_id,symbolOptional 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_FOUNDifsnapshot_iddoes not exist.LEDGR_SNAPSHOT_NOT_MUTABLEif snapshot status is notCREATED.LEDGR_CSV_FORMAT_ERRORon 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)