A zero dependency javascript Node.js package to interface with kdb+/q (v2.6+).
npm install --save-dev jkdb
const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800 });
q.connect((err) => {
if (err) throw err;
console.log("connected");
// send query from here
});
const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800, useTLS: true });
q.connect((err) => {
if (err) throw err;
console.log("connected");
// send query from here
});
const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800, user: "user", password: "password" });
q.connect((err) => {
if (err) throw err;
console.log("connected");
// send query from here
});
q.sync("(+/) til 10", (err, res) => {
if (err) throw err;
console.log("result: ", res);
// result: 45
});
q.sync(["(*/)", [22, 27, 45]], (err, res) => {
if (err) throw err;
console.log("result: ", res);
// result: 26730
});
q.sync(
[
"mmu",
[1, 2, 3],
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
],
(err, res) => {
if (err) throw err;
console.log("result: ", res);
// result: 30,36,42
}
);
q.asyn("show 99", (err) => {
if (err) throw err;
});
q.asyn(["show", 99], (err) => {
if (err) throw err;
});
q.on("upd", (table, data) => {
console.log(table, data);
});
q.sync(".u.sub[`trade;`7203.T]", (err, _res) => {
if (err) throw err;
});
q.close(() => {
console.log("closed");
});
Deserialization of long and timestamp can be controlled by QConnection arguments useBigInt
and includeNanosecond
.
k type | argument | javascript type | k null | infinity | -infinity |
---|---|---|---|---|---|
boolean | Boolean | ||||
guid | String | 00000000000000000000000000000000 | |||
byte | Number | ||||
short | Number | NaN | Infinity | -Infinity | |
int | Number | NaN | Infinity | -Infinity | |
long | Number | NaN | Infinity | -Infinity | |
long | useBigInt | BigInt | NaN | Infinity | -Infinity |
real | Number | NaN | Infinity | -Infinity | |
float | Number | NaN | Infinity | -Infinity | |
char | String | ' ' | |||
symbol | String | '' | |||
timestamp | Date | null | null | null | |
timestamp | includeNanosecond | String | '' | '' | '' |
month | String | null | null | null | |
date | Date | null | null | null | |
date | dateToMillisecond | Number | NaN | Infinity | -Infinity |
datetime | Date | null | null | null | |
datetime | dateToMillisecond | Number | NaN | Infinity | -Infinity |
timespan | String | null | null | null | |
minute | String | null | null | null | |
second | String | null | null | null | |
time | String | null | null | null | |
dict | Object | ||||
list | Array | ||||
table | Object | ||||
lambda | String | ||||
projection | Array |
javascript type | k type |
---|---|
Boolean | boolean |
Number | float |
String | chars |
Date | timestamp |
javascript type | Symbol.for('kType') | k type |
---|---|---|
Boolean Array | b | boolean |
String Array | g | guid |
Number Array | i | int |
Number Array | j | long |
Number Array | f | float |
String Array | c | char |
String Array | s | symbol |
Date Array | p | timestamp |
Date Array | d | date |
Date Array | z | datetime |
Use Symbol.for('kType')
to specify k type for the array, e.g.
const ints = [99, 11, 3, 3];
ints[Symbol.for("kType")] = "j";
Convert to a dictionary, keys are symbols, e.g.
const dict = { sym: "8306.T", price: 668.2 };
Convert to a table, e.g.
const table = {
sym: ["AXJO", "AXJO"],
date: [new Date("2021-05-13"), new Date("2021-05-14")],
open: [7000, 6000],
};
table[Symbol.for("meta")] = {
c: ["sym", "date", "open"],
t: ["s", "d", "f"],
};