| .make_parser | R Documentation |
Constructs and returns a parser function that converts an OKX REST API JSON
response into a typed data.table, using a provided field schema and a
parsing mode. Supports both key-based ("named") and index-based
("positional") endpoints. For "named" endpoints returning a
single object, the parser wraps it as a one-row table.
.make_parser(schema, mode = c("named", "positional", "vector"))
schema |
A |
mode |
Parser mode: |
Typing: Columns are preallocated per schema$type. Time fields
are interpreted as UNIX milliseconds.
Modes:
"named" - fields accessed via okx keys; a single object
in $data is wrapped to one row.
"positional" - fields accessed by index order of schema.
"vector" - scalar or vector payloads returned in one column.
Attributes: attr(DT, "var_labels") maps okx to formal.
A function with signature function(res, tz) where:
resAn httr::response. The body must decode to a list
with $code, $msg, and $data.
tzTime zone for "time" fields. Millisecond values
are converted with as.POSIXct().
The returned parser yields a data.table with column names from
schema$okx and attaches variable labels as
attr(DT, "var_labels") (a named character vector formal by okx).
Returns NULL if the API code is not "0" or if $data
is empty.
If parsed$code != "0", a warning with parsed$msg is emitted and
NULL is returned.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.