dot-make_parser: Build a typed OKX JSON response parser (named or positional)...

.make_parserR Documentation

Build a typed OKX JSON response parser (named or positional) to data.table

Description

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.

Usage

.make_parser(schema, mode = c("named", "positional", "vector"))

Arguments

schema

A data.frame with okx, formal, and type columns. Supported types are time, numeric, integer, string, and logical.

mode

Parser mode: "named", "positional", or "vector".

Details

  • 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.

Value

A function with signature function(res, tz) where:

res

An httr::response. The body must decode to a list with $code, $msg, and $data.

tz

Time 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.

Errors & warnings

If parsed$code != "0", a warning with parsed$msg is emitted and NULL is returned.


okxr documentation built on May 8, 2026, 5:09 p.m.