diff --git a/R/download_stock_directory.R b/R/download_stock_directory.R index 399229c..7542667 100644 --- a/R/download_stock_directory.R +++ b/R/download_stock_directory.R @@ -37,7 +37,7 @@ download_stock_directory <- function(exchange, date, quiet = FALSE) { url <- paste0(base_url, exchange, "_stocklocate_", format(date, "%Y%m%d"), ".txt") d <- data.table::fread(url, showProgress = !quiet) - data.table::setnames(d, c("ticker", "locate_code")) + data.table::setnames(d, c("ticker", "stock_locate")) d[, ':=' (exchange = toupper(exchange), date = date)] } diff --git a/R/read_functions.R b/R/read_functions.R index 6e0dac9..6853950 100644 --- a/R/read_functions.R +++ b/R/read_functions.R @@ -46,7 +46,7 @@ #' tries to find the stock_locate based on the \code{stock_directory} argument, #' if this is not found, it will try to extract the stock directory from the file, #' else an error is thrown. -#' @param stock_directory A data.frame containing the stock-locate_code relationship. +#' @param stock_directory A data.frame containing the stock-locate code relationship. #' As outputted by \code{\link{read_stock_directory}}. #' Only used if \code{filter_stock} is set. To download the stock directory from #' NASDAQs FTP server, use \code{\link{download_stock_directory}}. @@ -213,7 +213,7 @@ read_ITCH <- function(file, type, skip = 0, n_max = -1, if (!(length(filter_stock) == 1 && is.na(filter_stock))) { if (length(stock_directory) == 1 && is.na(stock_directory)) { warning("filter_stock is given, but no stock_directory is specified. Trying to extract stock directory from file\n") - stock_directory <- RITCH::read_stock_directory(file, quiet = TRUE) + stock_directory <- read_stock_directory(file, quiet = TRUE) } if (!all(filter_stock %chin% stock_directory$stock)) { @@ -224,7 +224,7 @@ read_ITCH <- function(file, type, skip = 0, n_max = -1, } # extend locate code by the stocks: filter_stock_locate <- c(filter_stock_locate, - stock_directory[stock %chin%filter_stock, locate_code]) + stock_directory[stock %chin%filter_stock, stock_locate]) } if (!quiet && length(filter_stock_locate) > 0) diff --git a/README.Rmd b/README.Rmd index 96aae50..c5b7e3e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -162,7 +162,7 @@ while (n_parsed < n_messages) { } ``` -You can also filter a dataset directly while reading messages for `msg_type`, `locate_code`, `timestamp` range, as well as `stock`. Note that filtering for a specific stock, is just a shorthand lookup for the stocks `locate_code`s, therefore a `stock_directory` needs to be supplied (either by providing the output from `read_stock_directory()` or `download_locate_code()`) or the function will try to extract the stock directory from the file. +You can also filter a dataset directly while reading messages for `msg_type`, `stock_locate`, `timestamp` range, as well as `stock`. Note that filtering for a specific stock, is just a shorthand lookup for the stocks `stock_locate`s, therefore a `stock_directory` needs to be supplied (either by providing the output from `read_stock_directory()` or `download_stock_locate()`) or the function will try to extract the stock directory from the file. ```{r} # read in the stock directory as we filter for stock names later on diff --git a/README.md b/README.md index 3013032..4f73d70 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ orders <- read_orders(file) str(orders) #> Classes 'data.table' and 'data.frame': 5000 obs. of 13 variables: #> $ msg_type : chr "A" "A" "F" "A" ... -#> $ locate_code : int 2 2 2 2 2 2 2 2 2 2 ... +#> $ stock_locate : int 2 2 2 2 2 2 2 2 2 2 ... #> $ tracking_number: int 0 0 0 0 0 0 0 0 0 0 ... #> $ timestamp :integer64 31139052372053 31141354532167 32813425752711 32826656500150 32827351405783 32893988026867 33067242028997 33300886636321 ... #> $ order_ref :integer64 0 100 84836 87020 87040 93032 105532 121012 ... @@ -96,7 +96,7 @@ trades <- read_trades(file, n_max = 100) str(trades) #> Classes 'data.table' and 'data.frame': 100 obs. of 14 variables: #> $ msg_type : chr "P" "P" "P" "P" ... -#> $ locate_code : int 2 2 2 2 2 3 3 3 3 3 ... +#> $ stock_locate : int 2 2 2 2 2 3 3 3 3 3 ... #> $ tracking_number: int 2 2 2 2 2 2 4 2 2 2 ... #> $ timestamp :integer64 34210128591201 34210355475120 34210767188977 34211127433476 34212046014088 34235711475708 34239928637481 34239928703094 ... #> $ order_ref :integer64 0 0 0 0 0 0 0 0 ... @@ -256,11 +256,11 @@ while (n_parsed < n_messages) { ``` You can also filter a dataset directly while reading messages for -`msg_type`, `locate_code`, `timestamp` range, as well as `stock`. Note +`msg_type`, `stock_locate`, `timestamp` range, as well as `stock`. Note that filtering for a specific stock, is just a shorthand lookup for the -stocks `locate_code`s, therefore a `stock_directory` needs to be +stocks `stock_locate`s, therefore a `stock_directory` needs to be supplied (either by providing the output from `read_stock_directory()` -or `download_locate_code()`) or the function will try to extract the +or `download_stock_locate()`) or the function will try to extract the stock directory from the file. ``` r @@ -274,11 +274,12 @@ od <- read_orders( max_timestamp = 55800000000000, # end at 15:30:00.000000 filter_stock_locate = 1, # take only stock with code 1 filter_stock = "CHAR", # but also take stock CHAR - stock_directory = sdir # provide the stock_directory to match stock names to locate_codes + stock_directory = sdir # provide the stock_directory to match stock names to stock_locates ) -#> [Filter] 'msg_type': 'A' -#> [Filter] 'timestamp': 43200000000000 - 55800000000000 -#> [Filter] 'stock_locate': '1', '3' +#> [Filter] msg_type: 'A' +#> [Filter] timestamp: 43200000000000 - 55800000000000 +#> [Filter] stock_locate: '1', '3' +#> NOTE: as filter arguments were given, the number of messages may be off #> [Counting] 5,000 messages found #> [Loading] . #> [Converting] to data.table @@ -290,10 +291,10 @@ od[, .(n = .N), by = msg_type] range(od$timestamp) #> integer64 #> [1] 43235810473334 55792143963723 -od[, .(n = .N), by = .(locate_code, stock)] -#> locate_code stock n -#> 1: 3 CHAR 574 -#> 2: 1 ALC 508 +od[, .(n = .N), by = .(stock_locate, stock)] +#> stock_locate stock n +#> 1: 3 CHAR 574 +#> 2: 1 ALC 508 ``` If you are interested in writing `ITCH_50` files or gaining a better diff --git a/debug/README.Rmd b/debug/README.Rmd index d025ada..4eff6c7 100644 --- a/debug/README.Rmd +++ b/debug/README.Rmd @@ -125,7 +125,7 @@ dbg_hex_to_orders(hex_string) ```{r} od <- data.table::data.table( msg_type = "F", - locate_code = 8236L, + stock_locate = 8236L, tracking_number = 0L, timestamp = bit64::as.integer64(25200002107428), order_ref = bit64::as.integer64(4), diff --git a/debug/debug_tools.cpp b/debug/debug_tools.cpp index bc32bbe..4f8cee8 100644 --- a/debug/debug_tools.cpp +++ b/debug/debug_tools.cpp @@ -534,7 +534,7 @@ uint64_t parse_orders_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::NumericVector order_ref = df["order_ref"]; @@ -549,7 +549,7 @@ uint64_t parse_orders_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -572,7 +572,7 @@ uint64_t parse_trades_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::NumericVector order_ref = df["order_ref"]; @@ -588,7 +588,7 @@ uint64_t parse_trades_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -636,7 +636,7 @@ uint64_t parse_modifications_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::NumericVector order_ref = df["order_ref"]; @@ -651,7 +651,7 @@ uint64_t parse_modifications_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -697,7 +697,7 @@ uint64_t parse_system_events_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector event_code = df["event_code"]; @@ -707,7 +707,7 @@ uint64_t parse_system_events_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -722,7 +722,7 @@ uint64_t parse_stock_directory_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -745,7 +745,7 @@ uint64_t parse_stock_directory_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -774,7 +774,7 @@ uint64_t parse_trading_status_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -789,7 +789,7 @@ uint64_t parse_trading_status_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -820,7 +820,7 @@ uint64_t parse_reg_sho_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -831,7 +831,7 @@ uint64_t parse_reg_sho_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -847,7 +847,7 @@ uint64_t parse_market_participants_states_at(unsigned char * buf, Rcpp::DataFram uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector mpid = df["mpid"]; @@ -861,7 +861,7 @@ uint64_t parse_market_participants_states_at(unsigned char * buf, Rcpp::DataFram const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -880,7 +880,7 @@ uint64_t parse_mwcb_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::NumericVector level1 = df["level1"]; @@ -893,7 +893,7 @@ uint64_t parse_mwcb_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -921,7 +921,7 @@ uint64_t parse_ipo_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -934,7 +934,7 @@ uint64_t parse_ipo_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -952,7 +952,7 @@ uint64_t parse_luld_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -966,7 +966,7 @@ uint64_t parse_luld_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -986,7 +986,7 @@ uint64_t parse_noii_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::NumericVector paired_shares = df["paired_shares"]; @@ -1004,7 +1004,7 @@ uint64_t parse_noii_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); @@ -1030,7 +1030,7 @@ uint64_t parse_rpii_at(unsigned char * buf, Rcpp::DataFrame df, uint64_t msg_num) { Rcpp::CharacterVector msg_type = df["msg_type"]; - Rcpp::IntegerVector locate_code = df["locate_code"]; + Rcpp::IntegerVector stock_locate = df["stock_locate"]; Rcpp::IntegerVector tracking_number = df["tracking_number"]; Rcpp::NumericVector timestamp = df["timestamp"]; Rcpp::CharacterVector stock = df["stock"]; @@ -1041,7 +1041,7 @@ uint64_t parse_rpii_at(unsigned char * buf, Rcpp::DataFrame df, const char msg = Rcpp::as(msg_type[msg_num]); buf[i++] = msg; - i += set2bytes(&buf[i], locate_code[msg_num]); + i += set2bytes(&buf[i], stock_locate[msg_num]); i += set2bytes(&buf[i], tracking_number[msg_num]); std::memcpy(&val64, &(timestamp[msg_num]), sizeof(int64_t)); diff --git a/debug/test_debug.R b/debug/test_debug.R index 92f40d7..d6129a3 100644 --- a/debug/test_debug.R +++ b/debug/test_debug.R @@ -72,7 +72,7 @@ test_hex_to_dt <- function(hex = NA, dt = NA, hex_to_dt_func) { # create an order dt_f <- data.table( - msg_type = "F", locate_code = 8236L, tracking_number = 0L, + msg_type = "F", stock_locate = 8236L, tracking_number = 0L, timestamp = as.int64(25200002107428), order_ref = as.int64(4), buy = TRUE, shares = 11900L, stock = "USO", price = 12.96, mpid = "VIRT" ) @@ -153,7 +153,7 @@ hex_p <- paste( ) dt_p <- data.table( msg_type = "P", - locate_code = 8124, + stock_locate = 8124, tracking_number = 2, timestamp = as.int64(26366446396437), order_ref = as.int64(0), @@ -209,7 +209,7 @@ hex_mod_all <- paste(hex_e, hex_c, hex_x, hex_d, hex_u) # Modification E dt_e <- data.table( - msg_type = "E", locate_code = 8124, tracking_number = 2, + msg_type = "E", stock_locate = 8124, tracking_number = 2, timestamp = as.int64(25200013663284), order_ref = as.int64(56), shares = 100, match_number = as.int64(17795), printable = NA, price = NA_real_, new_order_ref = as.int64(NA) @@ -218,7 +218,7 @@ test_hex_to_dt(hex_e, dt_e, dbg_hex_to_modifications) # Modification C dt_c <- data.table( - msg_type = "C", locate_code = 8028, tracking_number = 2, + msg_type = "C", stock_locate = 8028, tracking_number = 2, timestamp = as.int64(34200139258315), order_ref = as.int64(969072), shares = 100, match_number = as.int64(18524), printable = FALSE, price = 53.0, new_order_ref = as.int64(NA) @@ -227,7 +227,7 @@ test_hex_to_dt(hex_c, dt_c, dbg_hex_to_modifications) # Modification X dt_x <- data.table( - msg_type = "X", locate_code = 5114, tracking_number = 0, + msg_type = "X", stock_locate = 5114, tracking_number = 0, timestamp = as.int64(34200145463453), order_ref = as.int64(288739), shares = 100, match_number = as.int64(NA), printable = NA, price = NA_real_, new_order_ref = as.int64(NA) @@ -236,7 +236,7 @@ test_hex_to_dt(hex_x, dt_x, dbg_hex_to_modifications) # Modification D dt_d <- data.table( - msg_type = "D", locate_code = 8755, tracking_number = 0, + msg_type = "D", stock_locate = 8755, tracking_number = 0, timestamp = as.int64(34200145864224), order_ref = as.int64(957328), shares = NA_integer_, match_number = as.int64(NA), printable = NA, price = NA_real_, new_order_ref = as.int64(NA) @@ -245,7 +245,7 @@ test_hex_to_dt(hex_d, dt_d, dbg_hex_to_modifications) # Modification U dt_u <- data.table( - msg_type = "U", locate_code = 8124, tracking_number = 0, + msg_type = "U", stock_locate = 8124, tracking_number = 0, timestamp = as.int64(34200151720294), order_ref = as.int64(959728), shares = 100, match_number = as.int64(NA), printable = NA, price = 77.63, new_order_ref = as.int64(969648) @@ -271,7 +271,7 @@ test_hex_to_dt(dt = dt_mods_all, hex_to_dt_func = dbg_hex_to_modifications) #' 05 1 event code 4f O hex_s <- "00 00 53 00 00 00 00 0a 2d f4 92 1d 67 4f" -dt_s <- data.table(msg_type = "S", locate_code = 0, tracking_number = 0, +dt_s <- data.table(msg_type = "S", stock_locate = 0, tracking_number = 0, timestampt = as.int64(11192493022567), event_code = "O") test_hex_to_dt(hex_s, dt_s, dbg_hex_to_system_events) @@ -306,7 +306,7 @@ hex_r <- paste( "00 64 4e 43 5a 20 50 4e 20 31 4e 00 00 00 00 4e" ) dt_r <- data.table( - msg_type = "R", locate_code = 1L, tracking_number = 0L, + msg_type = "R", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902032964), stock = "A", market_category = "N", financial_status = " ", lot_size = 100L, round_lots_only = FALSE, issue_classification = "C", issue_subtype = "Z", authentic = TRUE, @@ -334,7 +334,7 @@ test_hex_to_dt(hex_r, dt_r, dbg_hex_to_stock_directory) hex_h <- "00 00 48 00 01 00 00 0a 66 a0 e4 ff bd 41 20 20 20 20 20 20 20 54 20 20 20 20 20" dt_h <- data.table( - msg_type = "H", locate_code = 1L, tracking_number = 0L, + msg_type = "H", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902304189), stock = "A", trading_state = "T", reserved = " ", reason = "", market_code = NA_character_, operation_halted = NA ) @@ -358,7 +358,7 @@ test_hex_to_dt(hex_h, dt_h, dbg_hex_to_trading_status) hex_y <- "00 00 59 00 01 00 00 0a 66 a0 e5 4a a2 41 20 20 20 20 20 20 20 30" dt_y <- data.table( - msg_type = "Y", locate_code = 1L, tracking_number = 0L, + msg_type = "Y", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902323362), stock = "A", regsho_action = "0" ) test_hex_to_dt(hex_y, dt_y, dbg_hex_to_reg_sho) @@ -383,7 +383,7 @@ test_hex_to_dt(hex_y, dt_y, dbg_hex_to_reg_sho) hex_l <- "00 00 4c 00 01 00 00 0a 67 e1 75 f8 65 43 44 52 47 41 20 20 20 20 20 20 20 59 4e 41" dt_l <- data.table( - msg_type = "L", locate_code = 1L, tracking_number = 0L, + msg_type = "L", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902304189), mpid = "CDRG", stock = "A", primary_mm = TRUE, mm_mode = "N", participant_state = "A" ) @@ -411,7 +411,7 @@ hex_v <- paste( "a1 6a b8 40 00 00 00 3c 59 95 62 40" ) dt_v <- data.table( - msg_type = "V", locate_code = 0L, tracking_number = 0L, + msg_type = "V", stock_locate = 0L, tracking_number = 0L, timestamp = as.int64(11435902304189), level1 = 3013.21, level2 = 2818.81, level3 = 2592.01, breached_level = NA_integer_ ) @@ -435,7 +435,7 @@ test_hex_to_dt(hex_v, dt_v, dbg_hex_to_mwcb) hex_k <- "00 00 4b 00 01 00 00 0a 66 a0 e4 ff bd 41 20 20 20 20 20 20 20 00 ca 1c ee 41 00 01 fa 40" dt_k <- data.table( - msg_type = "K", locate_code = 1L, tracking_number = 0L, + msg_type = "K", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902304189), stock = "A", release_time = 13245678L, release_qualifier = "A", ipo_price = 12.96 ) @@ -461,7 +461,7 @@ test_hex_to_dt(hex_k, dt_k, dbg_hex_to_ipo) hex_j <- paste("00 00 4a 00 01 00 00 0a 66 a0 e4 ff bd 41 20 20 20 20 20 20 20", "00 0b 9a b4 00 0b f2 1e 00 0b 1e 5a 00 00 00 10") dt_j <- data.table( - msg_type = "J", locate_code = 1L, tracking_number = 0L, + msg_type = "J", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902304189), stock = "A", reference_price = 76.05, upper_price = 78.2878, lower_price = 72.8666, extension = 16L ) @@ -495,7 +495,7 @@ hex_i <- paste( "43 35" ) dt_i <- data.table( - msg_type = "I", locate_code = 1L, tracking_number = 0L, + msg_type = "I", stock_locate = 1L, tracking_number = 0L, timestamp = as.int64(11435902304189), paired_shares = as.int64(990721), imbalance_shares = as.int64(3830096), imbalance_direction = "B", stock = "A", far_price = 78.2878, near_price = 72.8666, reference_price = 76.05, @@ -520,7 +520,7 @@ test_hex_to_dt(hex_i, dt_i, dbg_hex_to_noii) hex_n <- "00 00 4e 02 9c 00 00 1a 31 a5 21 99 bc 41 58 53 4d 20 20 20 20 42" dt_n <- data.table( - msg_type = "N", locate_code = 668L, tracking_number = 0L, + msg_type = "N", stock_locate = 668L, tracking_number = 0L, timestamp = as.int64(28800526162364), stock = "AXSM", interest_flag = "B" ) diff --git a/inst/tinytest/test_read_functions.R b/inst/tinytest/test_read_functions.R index bd9d171..81889c0 100644 --- a/inst/tinytest/test_read_functions.R +++ b/inst/tinytest/test_read_functions.R @@ -53,7 +53,7 @@ od <- read_orders(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", order_ref = "integer64", @@ -94,7 +94,7 @@ tr <- read_trades(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", order_ref = "integer64", @@ -124,7 +124,7 @@ md <- read_modifications(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", order_ref = "integer64", @@ -156,7 +156,7 @@ sys <- read_system_events(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", event_code = "character", @@ -179,7 +179,7 @@ sdir <- read_stock_directory(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", stock = "character", @@ -206,7 +206,7 @@ expect_equal(nrow(sdir), 3) expect_equal(names(sdir), names(classes_exp)) expect_equal(lapply(sdir, class), classes_exp) expect_equal(table(sdir$msg_type), c("R" = 3)) -expect_equal(sdir$locate_code, 1:3) +expect_equal(sdir$stock_locate, 1:3) expect_equal(unique(sdir$date), as.POSIXct("2010-12-24", "GMT")) expect_equal(unique(sdir$exchange), "TEST") @@ -215,7 +215,7 @@ tstat <- read_trading_status(file, quiet = TRUE) classes_exp <- list( msg_type = "character", - locate_code = "integer", + stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", stock = "character", @@ -234,7 +234,7 @@ expect_equal(nrow(tstat), 3) expect_equal(names(tstat), names(classes_exp)) expect_equal(lapply(tstat, class), classes_exp) expect_equal(table(tstat$msg_type), c("H" = 3)) -expect_equal(tstat$locate_code, 1:3) +expect_equal(tstat$stock_locate, 1:3) expect_equal(unique(tstat$trading_state), "T") expect_equal(unique(tstat$operation_halted), NA) expect_equal(unique(tstat$date), as.POSIXct("2010-12-24", "GMT")) @@ -246,7 +246,7 @@ expect_equal(unique(tstat$exchange), "TEST") rs <- read_reg_sho(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", stock = "character", regsho_action = "character", date = c("POSIXct", "POSIXt"), datetime = structure("nanotime", package = "nanotime"), exchange = "character" @@ -261,7 +261,7 @@ expect_equal(lapply(rs, class), classes_exp) ## Market Participant States mps <- read_market_participant_states(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", mpid = "character", stock = "character", primary_mm = "logical", mm_mode = "character", participant_state = "character", date = c("POSIXct", "POSIXt"), datetime = structure("nanotime", package = "nanotime"), @@ -277,7 +277,7 @@ expect_equal(lapply(mps, class), classes_exp) ## MWCB mwcb <- read_mwcb(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", level1 = "numeric", level2 = "numeric", level3 = "numeric", breached_level = "integer", date = c("POSIXct", "POSIXt"), datetime = structure("nanotime", package = "nanotime"), exchange = "character" @@ -291,7 +291,7 @@ expect_equal(lapply(mwcb, class), classes_exp) ## IPO ipo <- read_ipo(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", stock = "character", release_time = "integer", release_qualifier = "character", ipo_price = "numeric", date = c("POSIXct", "POSIXt"), datetime = structure("nanotime", package = "nanotime"), exchange = "character" @@ -305,7 +305,7 @@ expect_equal(lapply(ipo, class), classes_exp) ## NOII noii <- read_noii(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", paired_shares = "integer64", imbalance_shares = "integer64", imbalance_direction = "character", stock = "character", far_price = "numeric", near_price = "numeric", reference_price = "numeric", cross_type = "character", @@ -321,7 +321,7 @@ expect_equal(lapply(noii, class), classes_exp) # RPII rpii <- read_rpii(file, quiet = TRUE) classes_exp <- list( - msg_type = "character", locate_code = "integer", tracking_number = "integer", + msg_type = "character", stock_locate = "integer", tracking_number = "integer", timestamp = "integer64", stock = "character", interest_flag = "character", date = c("POSIXct", "POSIXt"), datetime = structure("nanotime", package = "nanotime"), exchange = "character" @@ -357,13 +357,13 @@ expect_equal(orders, check.attributes = FALSE) # test locate code -expect_equal(orders[locate_code == 1], +expect_equal(orders[stock_locate == 1], read_orders(file, quiet = TRUE, filter_stock_locate = 1)) -expect_equal(orders[locate_code == 2], +expect_equal(orders[stock_locate == 2], read_orders(file, quiet = TRUE, filter_stock_locate = 2)) -expect_equal(orders[locate_code %in% 1:3], +expect_equal(orders[stock_locate %in% 1:3], read_orders(file, quiet = TRUE, filter_stock_locate = 1:3)) -expect_equal(orders[locate_code %in% c(1, 3)], +expect_equal(orders[stock_locate %in% c(1, 3)], read_orders(file, quiet = TRUE, filter_stock_locate = c(1, NA, 3))) # test timestamp diff --git a/man/read_functions.Rd b/man/read_functions.Rd index e52d4a3..d744eff 100644 --- a/man/read_functions.Rd +++ b/man/read_functions.Rd @@ -103,7 +103,7 @@ tries to find the stock_locate based on the \code{stock_directory} argument, if this is not found, it will try to extract the stock directory from the file, else an error is thrown.} -\item{stock_directory}{A data.frame containing the stock-locate_code relationship. +\item{stock_directory}{A data.frame containing the stock-locate code relationship. As outputted by \code{\link{read_stock_directory}}. Only used if \code{filter_stock} is set. To download the stock directory from NASDAQs FTP server, use \code{\link{download_stock_directory}}.} diff --git a/simulate_dataset.R b/simulate_dataset.R index 45cb677..db3ba88 100644 --- a/simulate_dataset.R +++ b/simulate_dataset.R @@ -2,8 +2,6 @@ #' This script takes an existing dataset and samples and obfuscates the data #' to create a smaller testing/example dataset. #' -#' -#' #' Messages that are sampled are: #' - System Event Messages #' - Stock Directory @@ -35,7 +33,7 @@ names_mods <- names(mods) orders[, .(n = .N), by = stock][order(-n)][1:3] trades[, .(n = .N), by = stock][order(-n)][1:3] merge( - mods[, .(n = .N), by = locate_code][order(-n)][1:3], + mods[, .(n = .N), by = stock_locate][order(-n)][1:3], loc_code, by = "locate_code", all.x = TRUE ) @@ -46,7 +44,7 @@ loc_codes <- loc_code[ ticker %chin% names(stock_select) ][, .(stock_old = ticker, - old_loc_code = locate_code, + old_loc_code = stock_locate, stock = stock_select[ticker]) ][order(stock), locate_code := 1:.N][] @@ -107,10 +105,12 @@ sdir[, ':='( ipo_flag = FALSE, luld_price_tier = 2, etp_leverage = 0, - locate_code = NULL + stock_locate = NULL )] -sdir <- sdir[loc_codes[, .(stock, locate_code)], on = "stock"] +sdir <- sdir[loc_codes[, .(stock, stock_locate)], on = "stock"] setorder(sdir, stock) +# rearrange timestamp to fit alphabetic stock names +sdir[, timestamp := sort(timestamp)] setcolorder(sdir, names_dir) ###################### @@ -121,20 +121,20 @@ trad_stat <- read_trading_status(file, add_meta = FALSE, quiet = TRUE) names_stat <- names(trad_stat) # shuffle the timestamps and rename the stocks -trstat <- trad_stat[locate_code %in% loc_codes$old_loc_code][ +trstat <- trad_stat[stock_locate %in% loc_codes$old_loc_code][ , ':='( timestamp = timestamp + rnorm(.N, 0, 1e8), stock = stock_select[stock] ) ][] -# add the new locate_codes -trstat <- merge(trstat[, -c("locate_code")], - loc_codes[, .(stock, locate_code)], +# add the new stock_locates +trstat <- merge(trstat[, -c("stock_locate")], + loc_codes[, .(stock, stock_locate)], by = "stock", all.x = TRUE) # order the timestamps by locate code... -trstat[, timestamp := timestamp[order(-locate_code)]] +trstat[, timestamp := timestamp[order(-stock_locate)]] setcolorder(trstat, names_stat) @@ -143,9 +143,9 @@ setcolorder(trstat, names_stat) set.seed(654918413) N_ORDERS <- 5000 -# rename the stock and locate_codes +# rename the stock and stock_locates or <- orders[stock %chin% names(stock_select)][, stock := stock_select[stock]] -or <- merge(or[, -c("locate_code")], loc_codes[, .(stock, locate_code)]) +or <- merge(or[, -c("stock_locate")], loc_codes[, .(stock, stock_locate)]) or <- remove_price_outliers(or, 2) @@ -169,7 +169,7 @@ set.seed(7451984) N_TRADES <- 1000 tr <- trades[stock %chin% names(stock_select)][, stock := stock_select[stock]] -tr <- merge(tr[, -c("locate_code")], loc_codes[, .(stock, locate_code)]) +tr <- merge(tr[, -c("stock_locate")], loc_codes[, .(stock, stock_locate)]) tr <- remove_price_outliers(tr, 2) @@ -187,9 +187,9 @@ setcolorder(tr, names_trades) set.seed(78632176) N_MODS <- 2000 -md <- mods[locate_code %in% loc_codes$old_loc_code][, old_loc_code := locate_code] -md <- merge(md[, -c("locate_code")], - loc_codes[, .(stock, locate_code, old_loc_code)], +md <- mods[stock_locate %in% loc_codes$old_loc_code][, old_loc_code := stock_locate] +md <- merge(md[, -c("stock_locate")], + loc_codes[, .(stock, stock_locate, old_loc_code)], by = "old_loc_code")[, -c("old_loc_code")] # subset only for stocks that are also in the orders diff --git a/src/MessageTypes.cpp b/src/MessageTypes.cpp index 9423c87..1291360 100644 --- a/src/MessageTypes.cpp +++ b/src/MessageTypes.cpp @@ -115,7 +115,7 @@ bool Orders::loadMessage(unsigned char* buf) { // begin parsing the messages // else, we can continue to parse the message to the content vectors msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); int64_t ts = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &ts, sizeof(double)); @@ -173,7 +173,7 @@ void Orders::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); order_ref = data["order_ref"] = Rcpp::NumericVector(size); @@ -224,7 +224,7 @@ bool Trades::loadMessage(unsigned char* buf) { int64_t tmp; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -322,7 +322,7 @@ void Trades::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); order_ref = data["order_ref"] = Rcpp::NumericVector(size); @@ -374,7 +374,7 @@ bool Modifications::loadMessage(unsigned char* buf) { int64_t tmp; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -471,7 +471,7 @@ void Modifications::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); order_ref = data["order_ref"] = Rcpp::NumericVector(size); @@ -523,7 +523,7 @@ bool SystemEvents::loadMessage(unsigned char* buf) { int64_t tmp; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -556,7 +556,7 @@ void SystemEvents::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); event_code = data["event_code"] = Rcpp::CharacterVector(size); @@ -604,7 +604,7 @@ bool StockDirectory::loadMessage(unsigned char* buf) { std::string stock_string, issue_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -655,7 +655,7 @@ void StockDirectory::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); @@ -716,7 +716,7 @@ bool TradingStatus::loadMessage(unsigned char* buf) { std::string stock_string, reas; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -780,7 +780,7 @@ void TradingStatus::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); @@ -833,7 +833,7 @@ bool RegSHO::loadMessage(unsigned char* buf) { std::string stock_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -871,7 +871,7 @@ void RegSHO::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); @@ -919,7 +919,7 @@ bool ParticipantStates::loadMessage(unsigned char* buf) { std::string stock_string, mp; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -963,7 +963,7 @@ void ParticipantStates::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); mpid = data["mpid"] = Rcpp::CharacterVector(size); @@ -1012,7 +1012,7 @@ bool MWCB::loadMessage(unsigned char* buf) { int64_t tmp; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -1066,7 +1066,7 @@ void MWCB::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); level1 = data["level1"] = Rcpp::NumericVector(size); @@ -1117,7 +1117,7 @@ bool IPO::loadMessage(unsigned char* buf) { std::string stock_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -1158,7 +1158,7 @@ void IPO::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); @@ -1208,7 +1208,7 @@ bool LULD::loadMessage(unsigned char* buf) { std::string stock_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -1249,7 +1249,7 @@ void LULD::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); @@ -1301,7 +1301,7 @@ bool NOII::loadMessage(unsigned char* buf) { std::string stock_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -1354,7 +1354,7 @@ void NOII::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); paired_shares = data["paired_shares"] = Rcpp::NumericVector(size); @@ -1409,7 +1409,7 @@ bool RPII::loadMessage(unsigned char* buf) { std::string stock_string; msg_type[current_idx] = std::string(1, buf[0]); - locate_code[current_idx] = get2bytes(&buf[1]); + stock_locate[current_idx] = get2bytes(&buf[1]); tracking_number[current_idx] = get2bytes(&buf[3]); tmp = get6bytes(&buf[5]); std::memcpy(&(timestamp[current_idx]), &tmp, sizeof(double)); @@ -1447,7 +1447,7 @@ void RPII::reserve(int64_t size) { data = Rcpp::List(colnames.size()); data.names() = colnames; msg_type = data["msg_type"] = Rcpp::CharacterVector(size); - locate_code = data["locate_code"] = Rcpp::IntegerVector(size); + stock_locate = data["stock_locate"] = Rcpp::IntegerVector(size); tracking_number = data["tracking_number"] = Rcpp::IntegerVector(size); timestamp = data["timestamp"] = Rcpp::NumericVector(size); stock = data["stock"] = Rcpp::CharacterVector(size); diff --git a/src/MessageTypes.h b/src/MessageTypes.h index bc64a05..0941eac 100644 --- a/src/MessageTypes.h +++ b/src/MessageTypes.h @@ -67,7 +67,7 @@ class Orders : public MessageType { Orders() : MessageType( {'A', 'F'}, {ITCH::POS::A, ITCH::POS::F}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "order_ref", "buy", "shares", "stock", "price", "mpid"} + {"msg_type", "stock_locate", "tracking_number", "timestamp", "order_ref", "buy", "shares", "stock", "price", "mpid"} ) {} // Functions bool loadMessage(unsigned char* buf); @@ -77,7 +77,7 @@ class Orders : public MessageType { // Members // The references to the data vectors Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::NumericVector order_ref; @@ -96,7 +96,7 @@ class Trades : public MessageType { Trades() : MessageType( {'P', 'Q', 'B'}, {ITCH::POS::P, ITCH::POS::Q, ITCH::POS::B}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "order_ref", "buy", "shares", "stock", "price", "match_number", "cross_type"} + {"msg_type", "stock_locate", "tracking_number", "timestamp", "order_ref", "buy", "shares", "stock", "price", "match_number", "cross_type"} ) {} // Functions bool loadMessage(unsigned char* buf); @@ -106,7 +106,7 @@ class Trades : public MessageType { // Members // The references to the data vectors Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::NumericVector order_ref; @@ -127,7 +127,7 @@ class Modifications : public MessageType { Modifications() : MessageType( {'E', 'C', 'X', 'D', 'U'}, {ITCH::POS::E, ITCH::POS::C, ITCH::POS::X, ITCH::POS::D, ITCH::POS::U}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "order_ref", "shares", "match_number", "printable", "price", "new_order_ref"} + {"msg_type", "stock_locate", "tracking_number", "timestamp", "order_ref", "shares", "match_number", "printable", "price", "new_order_ref"} ) {} // Functions @@ -137,7 +137,7 @@ class Modifications : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::NumericVector order_ref; @@ -163,7 +163,7 @@ class SystemEvents : public MessageType { SystemEvents() : MessageType( {'S'}, {ITCH::POS::S}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "event_code"} + {"msg_type", "stock_locate", "tracking_number", "timestamp", "event_code"} ) {} // Functions @@ -173,7 +173,7 @@ class SystemEvents : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector event_code; @@ -188,7 +188,7 @@ class StockDirectory : public MessageType { StockDirectory() : MessageType( {'R'}, {ITCH::POS::R}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", "market_category", "financial_status", "lot_size", "round_lots_only", "issue_classification", "issue_subtype", "authentic", "short_sell_closeout", "ipo_flag", "luld_price_tier", "etp_flag", "etp_leverage", "inverse"} @@ -201,7 +201,7 @@ class StockDirectory : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock; @@ -229,7 +229,7 @@ class TradingStatus : public MessageType { TradingStatus() : MessageType( {'H', 'h'}, {ITCH::POS::H, ITCH::POS::h}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", // type H "trading_state", "reserved", "reason", // type h" @@ -244,7 +244,7 @@ class TradingStatus : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock; @@ -263,7 +263,7 @@ class RegSHO : public MessageType { RegSHO() : MessageType( {'Y'}, {ITCH::POS::Y}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", "regsho_action" + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", "regsho_action" } ) {} @@ -274,7 +274,7 @@ class RegSHO : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock; @@ -289,7 +289,7 @@ class ParticipantStates : public MessageType { ParticipantStates() : MessageType( {'L'}, {ITCH::POS::L}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "mpid", "stock", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "mpid", "stock", "primary_mm", "mm_mode", "participant_state" } ) {} @@ -301,7 +301,7 @@ class ParticipantStates : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector mpid; @@ -318,7 +318,7 @@ class MWCB : public MessageType { MWCB() : MessageType( {'V', 'W'}, {ITCH::POS::V, ITCH::POS::W}, - {"msg_type", "locate_code", "tracking_number", "timestamp", + {"msg_type", "stock_locate", "tracking_number", "timestamp", // message type 'V' "level1", "level2", "level3", // message type 'W' @@ -333,7 +333,7 @@ class MWCB : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::NumericVector level1; @@ -350,7 +350,7 @@ class IPO : public MessageType { IPO() : MessageType( {'K'}, {ITCH::POS::K}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", "release_time", "release_qualifier", "ipo_price" } ) {} @@ -362,7 +362,7 @@ class IPO : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock; @@ -379,7 +379,7 @@ class LULD : public MessageType { LULD() : MessageType( {'J'}, {ITCH::POS::J}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", "reference_price", "upper_price", "lower_price", "extension" } ) {} @@ -391,7 +391,7 @@ class LULD : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock; @@ -410,7 +410,7 @@ class NOII : public MessageType { NOII() : MessageType( {'I'}, {ITCH::POS::I}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "paired_shares", + {"msg_type", "stock_locate", "tracking_number", "timestamp", "paired_shares", "imbalance_shares", "imbalance_direction", "stock", "far_price", "near_price", "reference_price", "cross_type", "variation_indicator" } @@ -423,7 +423,7 @@ class NOII : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::NumericVector paired_shares; @@ -445,7 +445,7 @@ class RPII : public MessageType { RPII() : MessageType( {'N'}, {ITCH::POS::N}, - {"msg_type", "locate_code", "tracking_number", "timestamp", "stock", "interest_flag" + {"msg_type", "stock_locate", "tracking_number", "timestamp", "stock", "interest_flag" } ) {} @@ -456,7 +456,7 @@ class RPII : public MessageType { // Members Rcpp::CharacterVector msg_type; - Rcpp::IntegerVector locate_code; + Rcpp::IntegerVector stock_locate; Rcpp::IntegerVector tracking_number; Rcpp::NumericVector timestamp; Rcpp::CharacterVector stock;