@xbbg/core 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +83 -16
- package/dist/index.d.ts +694 -0
- package/dist/index.js +1996 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -21
- package/errors.js +0 -160
- package/index.d.ts +0 -792
- package/index.js +0 -1427
- package/lib/platform-map.js +0 -14
- package/lib/resolve-native.js +0 -49
package/dist/index.js
ADDED
|
@@ -0,0 +1,1996 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs2 = require('fs');
|
|
4
|
+
var path2 = require('path');
|
|
5
|
+
var module$1 = require('module');
|
|
6
|
+
var apacheArrow = require('apache-arrow');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
11
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
12
|
+
|
|
13
|
+
// src/index.ts
|
|
14
|
+
|
|
15
|
+
// src/errors.ts
|
|
16
|
+
var BlpError = class extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = new.target.name;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var BlpSessionError = class extends BlpError {
|
|
23
|
+
};
|
|
24
|
+
var BlpRequestError = class extends BlpError {
|
|
25
|
+
service;
|
|
26
|
+
operation;
|
|
27
|
+
request_id;
|
|
28
|
+
code;
|
|
29
|
+
constructor(message, options = {}) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.service = options.service;
|
|
32
|
+
this.operation = options.operation;
|
|
33
|
+
this.request_id = options.request_id;
|
|
34
|
+
this.code = options.code;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var BlpValidationError = class extends BlpError {
|
|
38
|
+
element;
|
|
39
|
+
suggestion;
|
|
40
|
+
constructor(message, options = {}) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.element = options.element;
|
|
43
|
+
this.suggestion = options.suggestion;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var BlpTimeoutError = class extends BlpError {
|
|
47
|
+
};
|
|
48
|
+
var BlpInternalError = class extends BlpError {
|
|
49
|
+
};
|
|
50
|
+
function wrapError(napiError) {
|
|
51
|
+
const msg = napiError instanceof Error ? napiError.message : typeof napiError === "string" ? napiError : "";
|
|
52
|
+
if (msg.includes("Session start failed") || msg.includes("session start failed") || msg.includes("Failed to start session") || msg.includes("Failed to open service") || msg.includes("failed to spawn worker") || msg.includes("connect event failed")) {
|
|
53
|
+
return new BlpSessionError(msg);
|
|
54
|
+
}
|
|
55
|
+
if (msg.includes("Request failed") || msg.includes("Subscription failed")) {
|
|
56
|
+
const options = parseRequestOptions(msg);
|
|
57
|
+
return new BlpRequestError(msg, options);
|
|
58
|
+
}
|
|
59
|
+
if (msg.includes("Invalid argument") || msg.includes("Configuration error") || msg.includes("Operation not found") || msg.includes("Schema element not found") || msg.includes("Schema type mismatch") || msg.includes("Unsupported schema") || msg.includes("invalid extractor") || msg.includes("(did you mean")) {
|
|
60
|
+
const options = parseValidationOptions(msg);
|
|
61
|
+
return new BlpValidationError(msg, options);
|
|
62
|
+
}
|
|
63
|
+
if (msg.includes("Request timed out")) {
|
|
64
|
+
return new BlpTimeoutError(msg);
|
|
65
|
+
}
|
|
66
|
+
if (msg.includes("Internal error") || msg.includes("Channel closed") || msg.includes("Stream buffer full") || msg.includes("Request was cancelled")) {
|
|
67
|
+
return new BlpInternalError(msg);
|
|
68
|
+
}
|
|
69
|
+
return new BlpError(msg);
|
|
70
|
+
}
|
|
71
|
+
function parseRequestOptions(msg) {
|
|
72
|
+
const options = {};
|
|
73
|
+
const serviceOpMatch = /on ([^:]+)::([^ (]+)/.exec(msg);
|
|
74
|
+
if (serviceOpMatch !== null) {
|
|
75
|
+
options.service = serviceOpMatch[1];
|
|
76
|
+
options.operation = serviceOpMatch[2];
|
|
77
|
+
}
|
|
78
|
+
const requestIdMatch = /\[request_id=([^\]]+)\]/.exec(msg);
|
|
79
|
+
if (requestIdMatch !== null) {
|
|
80
|
+
options.request_id = requestIdMatch[1];
|
|
81
|
+
}
|
|
82
|
+
return options;
|
|
83
|
+
}
|
|
84
|
+
function parseValidationOptions(msg) {
|
|
85
|
+
const options = {};
|
|
86
|
+
const suggestionMatch = /\(did you mean '([^']+)'\?\)/.exec(msg);
|
|
87
|
+
if (suggestionMatch !== null) {
|
|
88
|
+
options.suggestion = suggestionMatch[1];
|
|
89
|
+
}
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
var NATIVE_ARROW_BUFFERS = /* @__PURE__ */ Symbol("@xbbg/nativeArrowBuffers");
|
|
93
|
+
function tableFromNativeArrowBatch(batch) {
|
|
94
|
+
const retainedBuffers = [];
|
|
95
|
+
const fields = batch.columns.map((column) => {
|
|
96
|
+
const type = arrowType(column);
|
|
97
|
+
return new apacheArrow.Field(column.name, type, column.nullable);
|
|
98
|
+
});
|
|
99
|
+
const children = batch.columns.map((column) => dataFromColumn(column, retainedBuffers));
|
|
100
|
+
const schema = new apacheArrow.Schema(fields);
|
|
101
|
+
const structData = apacheArrow.makeData({
|
|
102
|
+
type: new apacheArrow.Struct(fields),
|
|
103
|
+
length: batch.numRows,
|
|
104
|
+
children
|
|
105
|
+
});
|
|
106
|
+
const table = new apacheArrow.Table(schema, new apacheArrow.RecordBatch(schema, structData));
|
|
107
|
+
Object.defineProperty(table, NATIVE_ARROW_BUFFERS, {
|
|
108
|
+
value: retainedBuffers,
|
|
109
|
+
enumerable: false
|
|
110
|
+
});
|
|
111
|
+
return table;
|
|
112
|
+
}
|
|
113
|
+
function dataFromColumn(column, retainedBuffers) {
|
|
114
|
+
const nullBitmap = optionalUint8View(column.nullBitmap, retainedBuffers);
|
|
115
|
+
switch (column.type) {
|
|
116
|
+
case "bool":
|
|
117
|
+
return apacheArrow.makeData({
|
|
118
|
+
type: new apacheArrow.Bool(),
|
|
119
|
+
length: column.length,
|
|
120
|
+
nullCount: column.nullCount,
|
|
121
|
+
nullBitmap,
|
|
122
|
+
data: requiredUint8View(column, retainedBuffers, Math.ceil(column.length / 8))
|
|
123
|
+
});
|
|
124
|
+
case "binary":
|
|
125
|
+
return apacheArrow.makeData({
|
|
126
|
+
type: new apacheArrow.Binary(),
|
|
127
|
+
length: column.length,
|
|
128
|
+
nullCount: column.nullCount,
|
|
129
|
+
nullBitmap,
|
|
130
|
+
valueOffsets: requiredOffsets(column, retainedBuffers),
|
|
131
|
+
data: requiredUint8View(column, retainedBuffers)
|
|
132
|
+
});
|
|
133
|
+
case "date32":
|
|
134
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.DateDay(), Int32Array);
|
|
135
|
+
case "date64":
|
|
136
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.DateMillisecond(), BigInt64Array);
|
|
137
|
+
case "float32":
|
|
138
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Float32(), Float32Array);
|
|
139
|
+
case "float64":
|
|
140
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Float64(), Float64Array);
|
|
141
|
+
case "int8":
|
|
142
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Int8(), Int8Array);
|
|
143
|
+
case "int16":
|
|
144
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Int16(), Int16Array);
|
|
145
|
+
case "int32":
|
|
146
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Int32(), Int32Array);
|
|
147
|
+
case "int64":
|
|
148
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Int64(), BigInt64Array);
|
|
149
|
+
case "large_binary":
|
|
150
|
+
return apacheArrow.makeData({
|
|
151
|
+
type: new apacheArrow.LargeBinary(),
|
|
152
|
+
length: column.length,
|
|
153
|
+
nullCount: column.nullCount,
|
|
154
|
+
nullBitmap,
|
|
155
|
+
valueOffsets: requiredLargeOffsets(column, retainedBuffers),
|
|
156
|
+
data: requiredUint8View(column, retainedBuffers)
|
|
157
|
+
});
|
|
158
|
+
case "large_utf8":
|
|
159
|
+
return apacheArrow.makeData({
|
|
160
|
+
type: new apacheArrow.LargeUtf8(),
|
|
161
|
+
length: column.length,
|
|
162
|
+
nullCount: column.nullCount,
|
|
163
|
+
nullBitmap,
|
|
164
|
+
valueOffsets: requiredLargeOffsets(column, retainedBuffers),
|
|
165
|
+
data: requiredUint8View(column, retainedBuffers)
|
|
166
|
+
});
|
|
167
|
+
case "null":
|
|
168
|
+
return apacheArrow.makeData({
|
|
169
|
+
type: new apacheArrow.Null(),
|
|
170
|
+
length: column.length
|
|
171
|
+
});
|
|
172
|
+
case "time32_ms":
|
|
173
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.TimeMillisecond(), Int32Array);
|
|
174
|
+
case "time32_s":
|
|
175
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.TimeSecond(), Int32Array);
|
|
176
|
+
case "time64_us":
|
|
177
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.TimeMicrosecond(), BigInt64Array);
|
|
178
|
+
case "time64_ns":
|
|
179
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.TimeNanosecond(), BigInt64Array);
|
|
180
|
+
case "timestamp_ms":
|
|
181
|
+
return scalarData(
|
|
182
|
+
column,
|
|
183
|
+
retainedBuffers,
|
|
184
|
+
nullBitmap,
|
|
185
|
+
new apacheArrow.TimestampMillisecond(column.timezone),
|
|
186
|
+
BigInt64Array
|
|
187
|
+
);
|
|
188
|
+
case "timestamp_ns":
|
|
189
|
+
return scalarData(
|
|
190
|
+
column,
|
|
191
|
+
retainedBuffers,
|
|
192
|
+
nullBitmap,
|
|
193
|
+
new apacheArrow.TimestampNanosecond(column.timezone),
|
|
194
|
+
BigInt64Array
|
|
195
|
+
);
|
|
196
|
+
case "timestamp_s":
|
|
197
|
+
return scalarData(
|
|
198
|
+
column,
|
|
199
|
+
retainedBuffers,
|
|
200
|
+
nullBitmap,
|
|
201
|
+
new apacheArrow.TimestampSecond(column.timezone),
|
|
202
|
+
BigInt64Array
|
|
203
|
+
);
|
|
204
|
+
case "timestamp_us":
|
|
205
|
+
return scalarData(
|
|
206
|
+
column,
|
|
207
|
+
retainedBuffers,
|
|
208
|
+
nullBitmap,
|
|
209
|
+
new apacheArrow.TimestampMicrosecond(column.timezone),
|
|
210
|
+
BigInt64Array
|
|
211
|
+
);
|
|
212
|
+
case "uint8":
|
|
213
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Uint8(), Uint8Array);
|
|
214
|
+
case "uint16":
|
|
215
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Uint16(), Uint16Array);
|
|
216
|
+
case "uint32":
|
|
217
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Uint32(), Uint32Array);
|
|
218
|
+
case "uint64":
|
|
219
|
+
return scalarData(column, retainedBuffers, nullBitmap, new apacheArrow.Uint64(), BigUint64Array);
|
|
220
|
+
case "utf8":
|
|
221
|
+
return apacheArrow.makeData({
|
|
222
|
+
type: new apacheArrow.Utf8(),
|
|
223
|
+
length: column.length,
|
|
224
|
+
nullCount: column.nullCount,
|
|
225
|
+
nullBitmap,
|
|
226
|
+
valueOffsets: requiredOffsets(column, retainedBuffers),
|
|
227
|
+
data: requiredUint8View(column, retainedBuffers)
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function arrowType(column) {
|
|
232
|
+
switch (column.type) {
|
|
233
|
+
case "bool":
|
|
234
|
+
return new apacheArrow.Bool();
|
|
235
|
+
case "binary":
|
|
236
|
+
return new apacheArrow.Binary();
|
|
237
|
+
case "date32":
|
|
238
|
+
return new apacheArrow.DateDay();
|
|
239
|
+
case "date64":
|
|
240
|
+
return new apacheArrow.DateMillisecond();
|
|
241
|
+
case "float32":
|
|
242
|
+
return new apacheArrow.Float32();
|
|
243
|
+
case "float64":
|
|
244
|
+
return new apacheArrow.Float64();
|
|
245
|
+
case "int8":
|
|
246
|
+
return new apacheArrow.Int8();
|
|
247
|
+
case "int16":
|
|
248
|
+
return new apacheArrow.Int16();
|
|
249
|
+
case "int32":
|
|
250
|
+
return new apacheArrow.Int32();
|
|
251
|
+
case "int64":
|
|
252
|
+
return new apacheArrow.Int64();
|
|
253
|
+
case "large_binary":
|
|
254
|
+
return new apacheArrow.LargeBinary();
|
|
255
|
+
case "large_utf8":
|
|
256
|
+
return new apacheArrow.LargeUtf8();
|
|
257
|
+
case "null":
|
|
258
|
+
return new apacheArrow.Null();
|
|
259
|
+
case "time32_ms":
|
|
260
|
+
return new apacheArrow.TimeMillisecond();
|
|
261
|
+
case "time32_s":
|
|
262
|
+
return new apacheArrow.TimeSecond();
|
|
263
|
+
case "time64_us":
|
|
264
|
+
return new apacheArrow.TimeMicrosecond();
|
|
265
|
+
case "time64_ns":
|
|
266
|
+
return new apacheArrow.TimeNanosecond();
|
|
267
|
+
case "timestamp_ms":
|
|
268
|
+
return new apacheArrow.TimestampMillisecond(column.timezone);
|
|
269
|
+
case "timestamp_ns":
|
|
270
|
+
return new apacheArrow.TimestampNanosecond(column.timezone);
|
|
271
|
+
case "timestamp_s":
|
|
272
|
+
return new apacheArrow.TimestampSecond(column.timezone);
|
|
273
|
+
case "timestamp_us":
|
|
274
|
+
return new apacheArrow.TimestampMicrosecond(column.timezone);
|
|
275
|
+
case "uint8":
|
|
276
|
+
return new apacheArrow.Uint8();
|
|
277
|
+
case "uint16":
|
|
278
|
+
return new apacheArrow.Uint16();
|
|
279
|
+
case "uint32":
|
|
280
|
+
return new apacheArrow.Uint32();
|
|
281
|
+
case "uint64":
|
|
282
|
+
return new apacheArrow.Uint64();
|
|
283
|
+
case "utf8":
|
|
284
|
+
return new apacheArrow.Utf8();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function scalarData(column, retainedBuffers, nullBitmap, type, ctor) {
|
|
288
|
+
return apacheArrow.makeData({
|
|
289
|
+
type,
|
|
290
|
+
length: column.length,
|
|
291
|
+
nullCount: column.nullCount,
|
|
292
|
+
nullBitmap,
|
|
293
|
+
data: requiredTypedView(column, ctor, retainedBuffers)
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function requiredTypedView(column, ctor, retainedBuffers) {
|
|
297
|
+
const buffer = requireBuffer(column, "data");
|
|
298
|
+
retainedBuffers.push(buffer);
|
|
299
|
+
return new ctor(buffer.buffer, buffer.byteOffset, column.length);
|
|
300
|
+
}
|
|
301
|
+
function requiredOffsets(column, retainedBuffers) {
|
|
302
|
+
const buffer = requireBuffer(column, "offsets");
|
|
303
|
+
retainedBuffers.push(buffer);
|
|
304
|
+
return new Int32Array(buffer.buffer, buffer.byteOffset, column.length + 1);
|
|
305
|
+
}
|
|
306
|
+
function requiredLargeOffsets(column, retainedBuffers) {
|
|
307
|
+
const buffer = requireBuffer(column, "offsets");
|
|
308
|
+
retainedBuffers.push(buffer);
|
|
309
|
+
return new BigInt64Array(buffer.buffer, buffer.byteOffset, column.length + 1);
|
|
310
|
+
}
|
|
311
|
+
function requiredUint8View(column, retainedBuffers, byteLength) {
|
|
312
|
+
const buffer = requireBuffer(column, "data");
|
|
313
|
+
retainedBuffers.push(buffer);
|
|
314
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, byteLength ?? buffer.byteLength);
|
|
315
|
+
}
|
|
316
|
+
function optionalUint8View(buffer, retainedBuffers) {
|
|
317
|
+
if (buffer === void 0) {
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
retainedBuffers.push(buffer);
|
|
321
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
322
|
+
}
|
|
323
|
+
function requireBuffer(column, property) {
|
|
324
|
+
const buffer = column[property];
|
|
325
|
+
if (buffer === void 0) {
|
|
326
|
+
throw new Error(`native Arrow column ${column.name} is missing ${property} buffer`);
|
|
327
|
+
}
|
|
328
|
+
return buffer;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/dates.ts
|
|
332
|
+
var ISO_DATE_RE = /^\d{4}[-/]\d{2}[-/]\d{2}$/;
|
|
333
|
+
var BBG_DATE_RE = /^\d{8}$/;
|
|
334
|
+
var AMBIGUOUS_DATE_RE = /^\d{1,2}[-/]\d{1,2}[-/]\d{2,4}([T \D]|$)/;
|
|
335
|
+
function hasToJSDate(value) {
|
|
336
|
+
return typeof value === "object" && value !== null && "toJSDate" in value && typeof value.toJSDate === "function";
|
|
337
|
+
}
|
|
338
|
+
function rejectAmbiguousString(value) {
|
|
339
|
+
if (AMBIGUOUS_DATE_RE.test(value) && !ISO_DATE_RE.test(value.trim())) {
|
|
340
|
+
throw new TypeError(
|
|
341
|
+
`Ambiguous date format ${JSON.stringify(value)}: month/day order cannot be inferred. Use ISO 8601 (YYYY-MM-DD), Bloomberg-native (YYYYMMDD), or pass a Date / Luxon DateTime.`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function dateLikeToJSDate(value) {
|
|
346
|
+
if (value instanceof Date) {
|
|
347
|
+
return value;
|
|
348
|
+
}
|
|
349
|
+
if (typeof value === "number") {
|
|
350
|
+
return new Date(value);
|
|
351
|
+
}
|
|
352
|
+
if (hasToJSDate(value)) {
|
|
353
|
+
return value.toJSDate();
|
|
354
|
+
}
|
|
355
|
+
if (typeof value === "string") {
|
|
356
|
+
const text = value.trim();
|
|
357
|
+
rejectAmbiguousString(text);
|
|
358
|
+
if (BBG_DATE_RE.test(text)) {
|
|
359
|
+
const year = Number(text.slice(0, 4));
|
|
360
|
+
const month = Number(text.slice(4, 6)) - 1;
|
|
361
|
+
const day = Number(text.slice(6, 8));
|
|
362
|
+
const dt2 = new Date(Date.UTC(year, month, day));
|
|
363
|
+
if (Number.isNaN(dt2.getTime())) {
|
|
364
|
+
throw new TypeError(`Invalid Bloomberg-native date ${JSON.stringify(value)}`);
|
|
365
|
+
}
|
|
366
|
+
return dt2;
|
|
367
|
+
}
|
|
368
|
+
const normalized = text.replace(" ", "T");
|
|
369
|
+
const dt = new Date(normalized);
|
|
370
|
+
if (Number.isNaN(dt.getTime())) {
|
|
371
|
+
throw new TypeError(
|
|
372
|
+
`Cannot parse ${JSON.stringify(value)} as a date. Expected ISO 8601, Bloomberg-native YYYYMMDD, Date, epoch ms, or Luxon DateTime.`
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
return dt;
|
|
376
|
+
}
|
|
377
|
+
throw new TypeError(
|
|
378
|
+
`Cannot convert ${typeof value} value ${String(value)} to a Date.`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
function formatDate(value) {
|
|
382
|
+
if (value === void 0 || value === null) {
|
|
383
|
+
return void 0;
|
|
384
|
+
}
|
|
385
|
+
if (typeof value === "string") {
|
|
386
|
+
const text = value.trim();
|
|
387
|
+
if (text.length === 0) {
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
if (BBG_DATE_RE.test(text)) {
|
|
391
|
+
return text;
|
|
392
|
+
}
|
|
393
|
+
rejectAmbiguousString(text);
|
|
394
|
+
if (ISO_DATE_RE.test(text)) {
|
|
395
|
+
return text.replace(/[-/]/g, "");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const date = dateLikeToJSDate(value);
|
|
399
|
+
const y = String(date.getUTCFullYear()).padStart(4, "0");
|
|
400
|
+
const m = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
401
|
+
const d = String(date.getUTCDate()).padStart(2, "0");
|
|
402
|
+
return `${y}${m}${d}`;
|
|
403
|
+
}
|
|
404
|
+
function formatDateTime(value) {
|
|
405
|
+
if (value === void 0 || value === null) {
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
if (typeof value === "string") {
|
|
409
|
+
const text = value.trim();
|
|
410
|
+
if (text.length === 0) {
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
rejectAmbiguousString(text);
|
|
414
|
+
if (BBG_DATE_RE.test(text)) {
|
|
415
|
+
return `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}T00:00:00`;
|
|
416
|
+
}
|
|
417
|
+
return text.replace(" ", "T");
|
|
418
|
+
}
|
|
419
|
+
const date = dateLikeToJSDate(value);
|
|
420
|
+
return date.toISOString();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/native/platform-map.ts
|
|
424
|
+
var platformPackages = Object.freeze({
|
|
425
|
+
"darwin-arm64": "@xbbg/core-darwin-arm64",
|
|
426
|
+
"linux-x64": "@xbbg/core-linux-x64",
|
|
427
|
+
"win32-x64": "@xbbg/core-win32-x64"
|
|
428
|
+
});
|
|
429
|
+
function platformKey(platform = process.platform, arch = process.arch) {
|
|
430
|
+
return `${platform}-${arch}`;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/native/resolve-native.ts
|
|
434
|
+
var nodeRequire = module$1.createRequire(__filename);
|
|
435
|
+
function exists(target) {
|
|
436
|
+
try {
|
|
437
|
+
fs2__default.default.accessSync(target);
|
|
438
|
+
return true;
|
|
439
|
+
} catch {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function isResolutionObject(value) {
|
|
444
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
445
|
+
}
|
|
446
|
+
function validateNativePackage(packageName, resolved) {
|
|
447
|
+
if (!isResolutionObject(resolved)) {
|
|
448
|
+
throw new Error(`Invalid native package ${packageName}: expected an object with binaryPath`);
|
|
449
|
+
}
|
|
450
|
+
if (!("binaryPath" in resolved)) {
|
|
451
|
+
throw new Error(`Invalid native package ${packageName}: missing binaryPath`);
|
|
452
|
+
}
|
|
453
|
+
if (typeof resolved.binaryPath !== "string") {
|
|
454
|
+
throw new Error(`Invalid native package ${packageName}: binaryPath must be a string`);
|
|
455
|
+
}
|
|
456
|
+
return resolved;
|
|
457
|
+
}
|
|
458
|
+
function localPackageIndex(repoRoot, packageName) {
|
|
459
|
+
const dirName = packageName.replace("@xbbg/", "xbbg-");
|
|
460
|
+
return path2__default.default.join(repoRoot, "packages", dirName, "index.js");
|
|
461
|
+
}
|
|
462
|
+
function isOptionalPackageMissing(err, packageName) {
|
|
463
|
+
if (!(err instanceof Error)) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
const code = "code" in err ? err.code : void 0;
|
|
467
|
+
if (code !== "MODULE_NOT_FOUND") {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return err.message.includes(`Cannot find module '${packageName}'`) || err.message.includes(`Cannot find module "${packageName}"`) || err.message.includes(`Cannot find package '${packageName}'`) || err.message.includes(`Cannot find package "${packageName}"`);
|
|
471
|
+
}
|
|
472
|
+
function resolveInstalledPackage(packageName, requirePackage, existsFile) {
|
|
473
|
+
try {
|
|
474
|
+
const resolved = validateNativePackage(packageName, requirePackage(packageName));
|
|
475
|
+
if (!existsFile(resolved.binaryPath)) {
|
|
476
|
+
throw new Error(
|
|
477
|
+
`Invalid native package ${packageName}: binaryPath does not exist: ${resolved.binaryPath}`
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
return resolved;
|
|
481
|
+
} catch (err) {
|
|
482
|
+
if (isOptionalPackageMissing(err, packageName)) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
throw err;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function resolveLocalPackage(repoRoot, packageName, requirePackage, existsFile) {
|
|
489
|
+
const localIndex = localPackageIndex(repoRoot, packageName);
|
|
490
|
+
if (!existsFile(localIndex)) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
const resolved = validateNativePackage(packageName, requirePackage(localIndex));
|
|
494
|
+
if (!existsFile(resolved.binaryPath)) {
|
|
495
|
+
throw new Error(
|
|
496
|
+
`Invalid native package ${packageName}: binaryPath does not exist: ${resolved.binaryPath}`
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
return resolved;
|
|
500
|
+
}
|
|
501
|
+
function resolveNativeAddonCore(options) {
|
|
502
|
+
const { key, packageName, repoRoot, requirePackage, exists: existsFile } = options;
|
|
503
|
+
if (packageName === null) {
|
|
504
|
+
return { key, packageName: null, binaryPath: null };
|
|
505
|
+
}
|
|
506
|
+
const installed = resolveInstalledPackage(packageName, requirePackage, existsFile);
|
|
507
|
+
if (installed !== null) {
|
|
508
|
+
return { key, packageName, binaryPath: installed.binaryPath };
|
|
509
|
+
}
|
|
510
|
+
const local = resolveLocalPackage(repoRoot, packageName, requirePackage, existsFile);
|
|
511
|
+
if (local !== null) {
|
|
512
|
+
return { key, packageName, binaryPath: local.binaryPath };
|
|
513
|
+
}
|
|
514
|
+
return { key, packageName, binaryPath: null };
|
|
515
|
+
}
|
|
516
|
+
function resolveNativeAddon(repoRoot) {
|
|
517
|
+
const key = platformKey();
|
|
518
|
+
const packageName = platformPackages[key] ?? null;
|
|
519
|
+
return resolveNativeAddonCore({
|
|
520
|
+
key,
|
|
521
|
+
packageName,
|
|
522
|
+
repoRoot,
|
|
523
|
+
requirePackage: (id) => nodeRequire(id),
|
|
524
|
+
exists
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/index.ts
|
|
529
|
+
var nodeRequire2 = module$1.createRequire(__filename);
|
|
530
|
+
var packageJson = nodeRequire2("../package.json");
|
|
531
|
+
function containsBlpapiRuntime(dir) {
|
|
532
|
+
if (dir.length === 0 || !fs2__default.default.existsSync(dir)) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
return [
|
|
536
|
+
"blpapi3_64.dll",
|
|
537
|
+
"blpapi3_32.dll",
|
|
538
|
+
"libblpapi3.dylib",
|
|
539
|
+
"libblpapi3_64.so",
|
|
540
|
+
"libblpapi3.so"
|
|
541
|
+
].some((name) => fs2__default.default.existsSync(path2__default.default.join(dir, name)));
|
|
542
|
+
}
|
|
543
|
+
function parseVersionParts(name) {
|
|
544
|
+
const parts = name.split(".").map((part) => Number(part));
|
|
545
|
+
return parts.every((part) => Number.isInteger(part) && part >= 0) ? parts : null;
|
|
546
|
+
}
|
|
547
|
+
function compareSdkRoots(left, right) {
|
|
548
|
+
const leftParts = parseVersionParts(path2__default.default.basename(left));
|
|
549
|
+
const rightParts = parseVersionParts(path2__default.default.basename(right));
|
|
550
|
+
if (leftParts !== null && rightParts !== null) {
|
|
551
|
+
const length = Math.max(leftParts.length, rightParts.length);
|
|
552
|
+
for (let index = 0; index < length; index += 1) {
|
|
553
|
+
const leftPart = leftParts[index] ?? 0;
|
|
554
|
+
const rightPart = rightParts[index] ?? 0;
|
|
555
|
+
if (leftPart !== rightPart) {
|
|
556
|
+
return rightPart - leftPart;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (leftParts !== null) return -1;
|
|
561
|
+
if (rightParts !== null) return 1;
|
|
562
|
+
return right.localeCompare(left);
|
|
563
|
+
}
|
|
564
|
+
function pushSdkRuntimeCandidates(candidates, sdkRoot) {
|
|
565
|
+
const resolved = path2__default.default.resolve(sdkRoot);
|
|
566
|
+
candidates.push(resolved, path2__default.default.join(resolved, "bin"), path2__default.default.join(resolved, "lib"));
|
|
567
|
+
}
|
|
568
|
+
function resolveVendorSdkRoot(repoRoot) {
|
|
569
|
+
const vendorDir = path2__default.default.join(repoRoot, "vendor", "blpapi-sdk");
|
|
570
|
+
if (!fs2__default.default.existsSync(vendorDir)) {
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
const candidates = [vendorDir];
|
|
574
|
+
for (const entry of fs2__default.default.readdirSync(vendorDir, { withFileTypes: true })) {
|
|
575
|
+
if (entry.isDirectory()) {
|
|
576
|
+
candidates.push(path2__default.default.join(vendorDir, entry.name));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
candidates.sort(compareSdkRoots);
|
|
580
|
+
return candidates.find((candidate) => {
|
|
581
|
+
const dirs = [candidate, path2__default.default.join(candidate, "bin"), path2__default.default.join(candidate, "lib")];
|
|
582
|
+
return dirs.some(containsBlpapiRuntime);
|
|
583
|
+
}) ?? null;
|
|
584
|
+
}
|
|
585
|
+
function configureRuntimeSearchPath() {
|
|
586
|
+
if (process.platform !== "win32") {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const candidates = [];
|
|
590
|
+
const libDir = process.env.BLPAPI_LIB_DIR;
|
|
591
|
+
if (libDir !== void 0 && libDir.length > 0) {
|
|
592
|
+
candidates.push(path2__default.default.resolve(libDir));
|
|
593
|
+
}
|
|
594
|
+
const root = process.env.BLPAPI_ROOT;
|
|
595
|
+
if (root !== void 0 && root.length > 0) {
|
|
596
|
+
pushSdkRuntimeCandidates(candidates, root);
|
|
597
|
+
}
|
|
598
|
+
const repoRoot = path2__default.default.resolve(__dirname, "..", "..");
|
|
599
|
+
const devRoot = process.env.XBBG_DEV_SDK_ROOT;
|
|
600
|
+
if (devRoot !== void 0 && devRoot.length > 0) {
|
|
601
|
+
pushSdkRuntimeCandidates(
|
|
602
|
+
candidates,
|
|
603
|
+
path2__default.default.isAbsolute(devRoot) ? devRoot : path2__default.default.resolve(repoRoot, devRoot)
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
const vendorRoot = resolveVendorSdkRoot(repoRoot);
|
|
607
|
+
if (vendorRoot !== null) {
|
|
608
|
+
pushSdkRuntimeCandidates(candidates, vendorRoot);
|
|
609
|
+
}
|
|
610
|
+
for (const candidate of candidates) {
|
|
611
|
+
if (!containsBlpapiRuntime(candidate)) {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
const currentPath = process.env.PATH ?? "";
|
|
615
|
+
const parts = currentPath.split(";").filter((part) => part.length > 0);
|
|
616
|
+
if (!parts.includes(candidate)) {
|
|
617
|
+
process.env.PATH = currentPath.length > 0 ? `${candidate};${currentPath}` : candidate;
|
|
618
|
+
}
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
configureRuntimeSearchPath();
|
|
623
|
+
function loadNative() {
|
|
624
|
+
const root = path2__default.default.resolve(__dirname, "..", "..");
|
|
625
|
+
const candidates = [
|
|
626
|
+
path2__default.default.join(__dirname, "napi_xbbg.node"),
|
|
627
|
+
path2__default.default.join(__dirname, "..", "napi_xbbg.node"),
|
|
628
|
+
path2__default.default.join(__dirname, "napi-xbbg.node")
|
|
629
|
+
];
|
|
630
|
+
for (const candidate of candidates) {
|
|
631
|
+
if (fs2__default.default.existsSync(candidate)) {
|
|
632
|
+
return nodeRequire2(candidate);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const { key, packageName, binaryPath } = resolveNativeAddon(root);
|
|
636
|
+
if (binaryPath !== null) {
|
|
637
|
+
return nodeRequire2(binaryPath);
|
|
638
|
+
}
|
|
639
|
+
if (packageName === null) {
|
|
640
|
+
throw new Error(
|
|
641
|
+
`No packaged @xbbg/core native addon is available for ${key}. Build it locally with "npm run build" from js-xbbg.`
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
throw new Error(
|
|
645
|
+
`Unable to load native napi-xbbg module for ${key}. Install ${packageName} via Bun/npm, or build it locally with "npm run build" from js-xbbg.`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
var native = loadNative();
|
|
649
|
+
var Backend = Object.freeze({
|
|
650
|
+
ARROW: "arrow",
|
|
651
|
+
JSON: "json",
|
|
652
|
+
POLARS: "polars"
|
|
653
|
+
});
|
|
654
|
+
var Format = Object.freeze({
|
|
655
|
+
LONG: "long",
|
|
656
|
+
LONG_TYPED: "long_typed",
|
|
657
|
+
LONG_WITH_METADATA: "long_with_metadata",
|
|
658
|
+
SEMI_LONG: "semi_long"
|
|
659
|
+
});
|
|
660
|
+
var CDX_INFO_FIELDS = Object.freeze([
|
|
661
|
+
"ROLLING_SERIES",
|
|
662
|
+
"VERSION",
|
|
663
|
+
"ON_THE_RUN_CURRENT_BD_INDICATOR",
|
|
664
|
+
"CDS_FIRST_ACCRUAL_START_DATE",
|
|
665
|
+
"NAME",
|
|
666
|
+
"NUM_CURRENT_COMPANIES_CCY_TKR",
|
|
667
|
+
"NUM_ORIG_COMPANIES_CRNCY_TKR",
|
|
668
|
+
"PX_LAST"
|
|
669
|
+
]);
|
|
670
|
+
var CDX_PRICING_FIELDS = Object.freeze([
|
|
671
|
+
"PX_LAST",
|
|
672
|
+
"PX_BID",
|
|
673
|
+
"PX_ASK",
|
|
674
|
+
"UPFRONT_LAST",
|
|
675
|
+
"UPFRONT_BID",
|
|
676
|
+
"UPFRONT_ASK",
|
|
677
|
+
"CDS_FLAT_SPREAD",
|
|
678
|
+
"UPFRONT_FEE",
|
|
679
|
+
"PV_CDS_PREMIUM_LEG",
|
|
680
|
+
"PV_CDS_DEFAULT_LEG"
|
|
681
|
+
]);
|
|
682
|
+
var CDX_RISK_FIELDS = Object.freeze([
|
|
683
|
+
"SW_CNV_BPV",
|
|
684
|
+
"SW_EQV_BPV",
|
|
685
|
+
"CDS_SPREAD_MID_MODIFIED_DURATION",
|
|
686
|
+
"CDS_SPREAD_MID_CONVEXITY",
|
|
687
|
+
"RECOVERY_RATE_SEN",
|
|
688
|
+
"CDS_RECOVERY_RT"
|
|
689
|
+
]);
|
|
690
|
+
var TA_STUDIES = Object.freeze({
|
|
691
|
+
smavg: "smavgStudyAttributes",
|
|
692
|
+
sma: "smavgStudyAttributes",
|
|
693
|
+
emavg: "emavgStudyAttributes",
|
|
694
|
+
ema: "emavgStudyAttributes",
|
|
695
|
+
wmavg: "wmavgStudyAttributes",
|
|
696
|
+
wma: "wmavgStudyAttributes",
|
|
697
|
+
vmavg: "vmavgStudyAttributes",
|
|
698
|
+
vma: "vmavgStudyAttributes",
|
|
699
|
+
tmavg: "tmavgStudyAttributes",
|
|
700
|
+
tma: "tmavgStudyAttributes",
|
|
701
|
+
ipmavg: "ipmavgStudyAttributes",
|
|
702
|
+
rsi: "rsiStudyAttributes",
|
|
703
|
+
macd: "macdStudyAttributes",
|
|
704
|
+
mao: "maoStudyAttributes",
|
|
705
|
+
momentum: "momentumStudyAttributes",
|
|
706
|
+
mom: "momentumStudyAttributes",
|
|
707
|
+
roc: "rocStudyAttributes",
|
|
708
|
+
boll: "bollStudyAttributes",
|
|
709
|
+
bb: "bollStudyAttributes",
|
|
710
|
+
kltn: "kltnStudyAttributes",
|
|
711
|
+
keltner: "kltnStudyAttributes",
|
|
712
|
+
mae: "maeStudyAttributes",
|
|
713
|
+
te: "teStudyAttributes",
|
|
714
|
+
al: "alStudyAttributes",
|
|
715
|
+
dmi: "dmiStudyAttributes",
|
|
716
|
+
adx: "dmiStudyAttributes",
|
|
717
|
+
tas: "tasStudyAttributes",
|
|
718
|
+
stoch: "tasStudyAttributes",
|
|
719
|
+
trender: "trenderStudyAttributes",
|
|
720
|
+
ptps: "ptpsStudyAttributes",
|
|
721
|
+
parabolic: "ptpsStudyAttributes",
|
|
722
|
+
sar: "ptpsStudyAttributes",
|
|
723
|
+
chko: "chkoStudyAttributes",
|
|
724
|
+
ado: "adoStudyAttributes",
|
|
725
|
+
vat: "vatStudyAttributes",
|
|
726
|
+
tvat: "tvatStudyAttributes",
|
|
727
|
+
atr: "atrStudyAttributes",
|
|
728
|
+
hurst: "hurstStudyAttributes",
|
|
729
|
+
fg: "fgStudyAttributes",
|
|
730
|
+
fear_greed: "fgStudyAttributes",
|
|
731
|
+
goc: "gocStudyAttributes",
|
|
732
|
+
ichimoku: "gocStudyAttributes",
|
|
733
|
+
cmci: "cmciStudyAttributes",
|
|
734
|
+
wlpr: "wlprStudyAttributes",
|
|
735
|
+
williams: "wlprStudyAttributes",
|
|
736
|
+
maxmin: "maxminStudyAttributes",
|
|
737
|
+
rex: "rexStudyAttributes",
|
|
738
|
+
etd: "etdStudyAttributes",
|
|
739
|
+
pd: "pdStudyAttributes",
|
|
740
|
+
rv: "rvStudyAttributes",
|
|
741
|
+
pivot: "pivotStudyAttributes",
|
|
742
|
+
or: "orStudyAttributes",
|
|
743
|
+
pcr: "pcrStudyAttributes",
|
|
744
|
+
bs: "bsStudyAttributes"
|
|
745
|
+
});
|
|
746
|
+
var TA_DEFAULTS = Object.freeze({
|
|
747
|
+
smavgStudyAttributes: Object.freeze({ period: 20, priceSourceClose: "PX_LAST" }),
|
|
748
|
+
emavgStudyAttributes: Object.freeze({ period: 20, priceSourceClose: "PX_LAST" }),
|
|
749
|
+
wmavgStudyAttributes: Object.freeze({ period: 20, priceSourceClose: "PX_LAST" }),
|
|
750
|
+
vmavgStudyAttributes: Object.freeze({ period: 20, priceSourceClose: "PX_LAST" }),
|
|
751
|
+
tmavgStudyAttributes: Object.freeze({ period: 20, priceSourceClose: "PX_LAST" }),
|
|
752
|
+
rsiStudyAttributes: Object.freeze({ period: 14, priceSourceClose: "PX_LAST" }),
|
|
753
|
+
macdStudyAttributes: Object.freeze({
|
|
754
|
+
maPeriod1: 12,
|
|
755
|
+
maPeriod2: 26,
|
|
756
|
+
sigPeriod: 9,
|
|
757
|
+
priceSourceClose: "PX_LAST"
|
|
758
|
+
}),
|
|
759
|
+
bollStudyAttributes: Object.freeze({
|
|
760
|
+
period: 20,
|
|
761
|
+
upperBand: 2,
|
|
762
|
+
lowerBand: 2,
|
|
763
|
+
priceSourceClose: "PX_LAST"
|
|
764
|
+
}),
|
|
765
|
+
dmiStudyAttributes: Object.freeze({
|
|
766
|
+
period: 14,
|
|
767
|
+
priceSourceHigh: "PX_HIGH",
|
|
768
|
+
priceSourceLow: "PX_LOW",
|
|
769
|
+
priceSourceClose: "PX_LAST"
|
|
770
|
+
}),
|
|
771
|
+
atrStudyAttributes: Object.freeze({
|
|
772
|
+
maType: "Simple",
|
|
773
|
+
period: 14,
|
|
774
|
+
priceSourceHigh: "PX_HIGH",
|
|
775
|
+
priceSourceLow: "PX_LOW",
|
|
776
|
+
priceSourceClose: "PX_LAST"
|
|
777
|
+
}),
|
|
778
|
+
tasStudyAttributes: Object.freeze({
|
|
779
|
+
periodK: 14,
|
|
780
|
+
periodD: 3,
|
|
781
|
+
periodDS: 3,
|
|
782
|
+
periodDSS: 3,
|
|
783
|
+
priceSourceHigh: "PX_HIGH",
|
|
784
|
+
priceSourceLow: "PX_LOW",
|
|
785
|
+
priceSourceClose: "PX_LAST"
|
|
786
|
+
})
|
|
787
|
+
});
|
|
788
|
+
function toArrowTableFromNative(batch) {
|
|
789
|
+
return tableFromNativeArrowBatch(batch);
|
|
790
|
+
}
|
|
791
|
+
function isPlainObject(value) {
|
|
792
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
793
|
+
}
|
|
794
|
+
function toRequestString(value) {
|
|
795
|
+
return String(value);
|
|
796
|
+
}
|
|
797
|
+
function mapObjectToPairs(obj) {
|
|
798
|
+
if (obj === void 0) {
|
|
799
|
+
return void 0;
|
|
800
|
+
}
|
|
801
|
+
return Object.entries(obj).map(([key, value]) => ({
|
|
802
|
+
key: toRequestString(key),
|
|
803
|
+
value: toRequestString(value)
|
|
804
|
+
}));
|
|
805
|
+
}
|
|
806
|
+
var BDTICK_BOOLEAN_KWARGS = Object.freeze([
|
|
807
|
+
["includeConditionCodes", "includeConditionCodes"],
|
|
808
|
+
["includeExchangeCodes", "includeExchangeCodes"],
|
|
809
|
+
["includeBrokerCodes", "includeBrokerCodes"],
|
|
810
|
+
["includeRpsCodes", "includeRpsCodes"],
|
|
811
|
+
["includeBicMicCodes", "includeBicMicCodes"],
|
|
812
|
+
["includeNonPlottableEvents", "includeNonPlottableEvents"],
|
|
813
|
+
["includeBloombergStandardConditionCodes", "includeBloombergStandardConditionCodes"]
|
|
814
|
+
]);
|
|
815
|
+
function upsertStringPair(pairs, key, value) {
|
|
816
|
+
const existing = pairs.find((pair) => pair.key === key);
|
|
817
|
+
if (existing === void 0) {
|
|
818
|
+
pairs.push({ key, value });
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
existing.value = value;
|
|
822
|
+
}
|
|
823
|
+
function buildBdtickKwargs(options) {
|
|
824
|
+
const pairs = mapObjectToPairs(options.kwargs) ?? [];
|
|
825
|
+
for (const [optionName, requestName] of BDTICK_BOOLEAN_KWARGS) {
|
|
826
|
+
const typedValue = options[optionName];
|
|
827
|
+
if (typedValue !== void 0) {
|
|
828
|
+
upsertStringPair(pairs, requestName, typedValue ? "true" : "false");
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return pairs.length > 0 ? pairs : void 0;
|
|
832
|
+
}
|
|
833
|
+
function toStringArray(value) {
|
|
834
|
+
if (Array.isArray(value)) {
|
|
835
|
+
return value.map((item) => toRequestString(item));
|
|
836
|
+
}
|
|
837
|
+
if (value === null || value === void 0) {
|
|
838
|
+
return [];
|
|
839
|
+
}
|
|
840
|
+
return [toRequestString(value)];
|
|
841
|
+
}
|
|
842
|
+
function normalizeConfigureArgs(configOrHost, port) {
|
|
843
|
+
if (configOrHost === void 0) {
|
|
844
|
+
return void 0;
|
|
845
|
+
}
|
|
846
|
+
if (typeof configOrHost === "string" || port !== void 0) {
|
|
847
|
+
const config = {};
|
|
848
|
+
if (typeof configOrHost === "string") {
|
|
849
|
+
config.host = configOrHost;
|
|
850
|
+
}
|
|
851
|
+
if (port !== void 0) {
|
|
852
|
+
config.port = port;
|
|
853
|
+
}
|
|
854
|
+
return config;
|
|
855
|
+
}
|
|
856
|
+
if (isPlainObject(configOrHost)) {
|
|
857
|
+
return { ...configOrHost };
|
|
858
|
+
}
|
|
859
|
+
throw new TypeError(
|
|
860
|
+
"configure expects either a config object or host/port arguments"
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
function normalizeRecoveryOptions(options = {}) {
|
|
864
|
+
const normalized = { ...options };
|
|
865
|
+
const recoveryRate = normalized.recoveryRate ?? normalized.recovery_rate;
|
|
866
|
+
delete normalized.recoveryRate;
|
|
867
|
+
delete normalized.recovery_rate;
|
|
868
|
+
if (recoveryRate !== void 0) {
|
|
869
|
+
normalized.overrides = {
|
|
870
|
+
...normalized.overrides ?? {},
|
|
871
|
+
CDS_RR: toRequestString(recoveryRate)
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
return normalized;
|
|
875
|
+
}
|
|
876
|
+
function fullDayRange(dt) {
|
|
877
|
+
const formatted = formatDate(dt);
|
|
878
|
+
if (formatted === void 0) {
|
|
879
|
+
throw new TypeError("dt must be a non-empty date-like value");
|
|
880
|
+
}
|
|
881
|
+
const day = `${formatted.slice(0, 4)}-${formatted.slice(4, 6)}-${formatted.slice(6, 8)}`;
|
|
882
|
+
return {
|
|
883
|
+
start: `${day}T00:00:00`,
|
|
884
|
+
end: `${day}T23:59:59`
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
function normalizeDate(value) {
|
|
888
|
+
return formatDate(value);
|
|
889
|
+
}
|
|
890
|
+
function getStudyAttrName(study) {
|
|
891
|
+
const normalized = study.toLowerCase().replace(/-/g, "_").replace(/ /g, "_");
|
|
892
|
+
const mapped = TA_STUDIES[normalized];
|
|
893
|
+
if (mapped !== void 0) {
|
|
894
|
+
return mapped;
|
|
895
|
+
}
|
|
896
|
+
if (normalized.endsWith("studyattributes")) {
|
|
897
|
+
return normalized;
|
|
898
|
+
}
|
|
899
|
+
return `${normalized}StudyAttributes`;
|
|
900
|
+
}
|
|
901
|
+
function buildTaRequest(ticker, study, options = {}) {
|
|
902
|
+
const rawStudy = typeof study === "string" ? { studyType: study } : { ...study };
|
|
903
|
+
const studyType = rawStudy.studyType ?? rawStudy.study ?? (typeof study === "string" ? study : "");
|
|
904
|
+
const attrName = getStudyAttrName(toRequestString(studyType));
|
|
905
|
+
const kwargs = { ...options.kwargs ?? {} };
|
|
906
|
+
const startDate = normalizeDate(
|
|
907
|
+
stringOrUndef(kwargs.startDate) ?? stringOrUndef(kwargs.start_date) ?? options.startDate ?? options.start_date
|
|
908
|
+
);
|
|
909
|
+
const endDate = normalizeDate(
|
|
910
|
+
stringOrUndef(kwargs.endDate) ?? stringOrUndef(kwargs.end_date) ?? options.endDate ?? options.end_date
|
|
911
|
+
);
|
|
912
|
+
const periodicity = toRequestString(stringOrUndef(kwargs.periodicitySelection) ?? stringOrUndef(kwargs.periodicity) ?? rawStudy.calcInterval ?? options.periodicity ?? "DAILY").toUpperCase();
|
|
913
|
+
const interval = kwargs.interval ?? rawStudy.interval ?? options.interval;
|
|
914
|
+
delete kwargs.startDate;
|
|
915
|
+
delete kwargs.start_date;
|
|
916
|
+
delete kwargs.endDate;
|
|
917
|
+
delete kwargs.end_date;
|
|
918
|
+
delete kwargs.periodicitySelection;
|
|
919
|
+
delete kwargs.periodicity;
|
|
920
|
+
delete rawStudy.studyType;
|
|
921
|
+
delete rawStudy.study;
|
|
922
|
+
delete rawStudy.calcInterval;
|
|
923
|
+
if (rawStudy.length !== void 0 && rawStudy.period === void 0) {
|
|
924
|
+
rawStudy.period = rawStudy.length;
|
|
925
|
+
}
|
|
926
|
+
delete rawStudy.length;
|
|
927
|
+
const params = {
|
|
928
|
+
...TA_DEFAULTS[attrName] ?? {},
|
|
929
|
+
...options.studyParams ?? {},
|
|
930
|
+
...rawStudy
|
|
931
|
+
};
|
|
932
|
+
if (params.length !== void 0 && params.period === void 0) {
|
|
933
|
+
params.period = params.length;
|
|
934
|
+
}
|
|
935
|
+
delete params.length;
|
|
936
|
+
delete params.calcInterval;
|
|
937
|
+
const elements = [
|
|
938
|
+
{ key: "priceSource.securityName", value: toRequestString(ticker) }
|
|
939
|
+
];
|
|
940
|
+
if (periodicity === "INTRADAY") {
|
|
941
|
+
const prefix = "priceSource.dataRange.intraday";
|
|
942
|
+
if (startDate !== void 0) {
|
|
943
|
+
elements.push({ key: `${prefix}.startDate`, value: startDate });
|
|
944
|
+
}
|
|
945
|
+
if (endDate !== void 0) {
|
|
946
|
+
elements.push({ key: `${prefix}.endDate`, value: endDate });
|
|
947
|
+
}
|
|
948
|
+
elements.push({ key: `${prefix}.eventType`, value: "TRADE" });
|
|
949
|
+
if (interval !== void 0) {
|
|
950
|
+
elements.push({ key: `${prefix}.interval`, value: toRequestString(interval) });
|
|
951
|
+
}
|
|
952
|
+
} else {
|
|
953
|
+
const prefix = "priceSource.dataRange.historical";
|
|
954
|
+
if (startDate !== void 0) {
|
|
955
|
+
elements.push({ key: `${prefix}.startDate`, value: startDate });
|
|
956
|
+
}
|
|
957
|
+
if (endDate !== void 0) {
|
|
958
|
+
elements.push({ key: `${prefix}.endDate`, value: endDate });
|
|
959
|
+
}
|
|
960
|
+
elements.push({ key: `${prefix}.periodicitySelection`, value: periodicity });
|
|
961
|
+
}
|
|
962
|
+
for (const [key, value] of Object.entries(params)) {
|
|
963
|
+
if (value === void 0) {
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
elements.push({
|
|
967
|
+
key: `studyAttributes.${attrName}.${key}`,
|
|
968
|
+
value: toRequestString(value)
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
for (const [key, value] of Object.entries(kwargs)) {
|
|
972
|
+
elements.push({ key: toRequestString(key), value: toRequestString(value) });
|
|
973
|
+
}
|
|
974
|
+
return elements;
|
|
975
|
+
}
|
|
976
|
+
function stringOrUndef(value) {
|
|
977
|
+
return typeof value === "string" ? value : void 0;
|
|
978
|
+
}
|
|
979
|
+
var polarsModule;
|
|
980
|
+
var polarsLoadError;
|
|
981
|
+
function cachePolarsLoadError(err) {
|
|
982
|
+
const error = new Error(
|
|
983
|
+
"nodejs-polars is required for Polars backend. Install: npm install nodejs-polars"
|
|
984
|
+
);
|
|
985
|
+
Object.defineProperty(error, "cause", { value: err, configurable: true });
|
|
986
|
+
polarsLoadError = error;
|
|
987
|
+
return error;
|
|
988
|
+
}
|
|
989
|
+
function loadPolars() {
|
|
990
|
+
if (polarsModule !== void 0) {
|
|
991
|
+
return polarsModule;
|
|
992
|
+
}
|
|
993
|
+
if (polarsLoadError !== void 0) {
|
|
994
|
+
throw polarsLoadError;
|
|
995
|
+
}
|
|
996
|
+
try {
|
|
997
|
+
polarsModule = nodeRequire2("nodejs-polars");
|
|
998
|
+
return polarsModule;
|
|
999
|
+
} catch (err) {
|
|
1000
|
+
throw cachePolarsLoadError(err);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
function normalizeBackend(backend) {
|
|
1004
|
+
const selected = backend ?? Backend.ARROW;
|
|
1005
|
+
if (selected === Backend.ARROW || selected === Backend.JSON || selected === Backend.POLARS) {
|
|
1006
|
+
return selected;
|
|
1007
|
+
}
|
|
1008
|
+
throw new TypeError(
|
|
1009
|
+
`Unsupported @xbbg/core backend "${toRequestString(selected)}". Expected one of: ${Object.values(
|
|
1010
|
+
Backend
|
|
1011
|
+
).join(", ")}`
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
function ipcToBackend(buffer, backend) {
|
|
1015
|
+
const selected = normalizeBackend(backend);
|
|
1016
|
+
if (selected === Backend.JSON) {
|
|
1017
|
+
return Array.from(apacheArrow.tableFromIPC(buffer));
|
|
1018
|
+
}
|
|
1019
|
+
if (selected === Backend.POLARS) {
|
|
1020
|
+
return loadPolars().readIPC(buffer);
|
|
1021
|
+
}
|
|
1022
|
+
return apacheArrow.tableFromIPC(buffer);
|
|
1023
|
+
}
|
|
1024
|
+
var configuredEngineConfig;
|
|
1025
|
+
var configuredEnginePromise;
|
|
1026
|
+
function clearConfiguredEngine() {
|
|
1027
|
+
const existing = configuredEnginePromise;
|
|
1028
|
+
configuredEnginePromise = void 0;
|
|
1029
|
+
if (existing !== void 0) {
|
|
1030
|
+
existing.then((engine) => {
|
|
1031
|
+
engine.signalShutdown();
|
|
1032
|
+
}).catch(() => {
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
async function getConfiguredEngine() {
|
|
1037
|
+
if (configuredEnginePromise === void 0) {
|
|
1038
|
+
const pending = connect(configuredEngineConfig);
|
|
1039
|
+
pending.catch(() => {
|
|
1040
|
+
if (configuredEnginePromise === pending) {
|
|
1041
|
+
configuredEnginePromise = void 0;
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
configuredEnginePromise = pending;
|
|
1045
|
+
}
|
|
1046
|
+
return await configuredEnginePromise;
|
|
1047
|
+
}
|
|
1048
|
+
var FieldHandle = class {
|
|
1049
|
+
constructor(name) {
|
|
1050
|
+
this.name = name;
|
|
1051
|
+
}
|
|
1052
|
+
name;
|
|
1053
|
+
};
|
|
1054
|
+
var Tick = class {
|
|
1055
|
+
constructor(_update) {
|
|
1056
|
+
this._update = _update;
|
|
1057
|
+
this._positions = new Map(_update.fields.map((field, index) => [field, index]));
|
|
1058
|
+
}
|
|
1059
|
+
_update;
|
|
1060
|
+
_positions;
|
|
1061
|
+
get topic() {
|
|
1062
|
+
return this._update.topic;
|
|
1063
|
+
}
|
|
1064
|
+
get timestampUs() {
|
|
1065
|
+
return this._update.timestampUs;
|
|
1066
|
+
}
|
|
1067
|
+
get layoutVersion() {
|
|
1068
|
+
return this._update.layoutVersion;
|
|
1069
|
+
}
|
|
1070
|
+
get(field) {
|
|
1071
|
+
const name = typeof field === "string" ? field : field.name;
|
|
1072
|
+
const index = this._positions.get(name);
|
|
1073
|
+
if (index === void 0) return null;
|
|
1074
|
+
const value = this._update.values[index] ?? null;
|
|
1075
|
+
const kind = this._update.valueKinds[index] ?? "unknown";
|
|
1076
|
+
if (value === null) return null;
|
|
1077
|
+
if (kind === "i64" || kind === "time64_us" || kind === "timestamp_us") {
|
|
1078
|
+
try {
|
|
1079
|
+
return BigInt(String(value));
|
|
1080
|
+
} catch {
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (kind === "date32" && typeof value === "number") {
|
|
1085
|
+
return new Date(Date.UTC(1970, 0, 1 + value));
|
|
1086
|
+
}
|
|
1087
|
+
return value;
|
|
1088
|
+
}
|
|
1089
|
+
f64(field) {
|
|
1090
|
+
const value = this.get(field);
|
|
1091
|
+
if (value === null) return null;
|
|
1092
|
+
const parsed = Number(value);
|
|
1093
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
1094
|
+
}
|
|
1095
|
+
i64(field) {
|
|
1096
|
+
const value = this.get(field);
|
|
1097
|
+
if (value === null) return null;
|
|
1098
|
+
try {
|
|
1099
|
+
return BigInt(String(value));
|
|
1100
|
+
} catch {
|
|
1101
|
+
return null;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
str(field) {
|
|
1105
|
+
const value = this.get(field);
|
|
1106
|
+
return value === null ? null : String(value);
|
|
1107
|
+
}
|
|
1108
|
+
toObject() {
|
|
1109
|
+
const out = { topic: this.topic, timestampUs: this.timestampUs };
|
|
1110
|
+
for (const field of this._update.fields) {
|
|
1111
|
+
out[field] = this.get(field);
|
|
1112
|
+
}
|
|
1113
|
+
return out;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
var ArrowSubscription = class {
|
|
1117
|
+
constructor(_inner) {
|
|
1118
|
+
this._inner = _inner;
|
|
1119
|
+
}
|
|
1120
|
+
_inner;
|
|
1121
|
+
async next() {
|
|
1122
|
+
try {
|
|
1123
|
+
const batch = await this._inner.nextArrow();
|
|
1124
|
+
if (batch === null) {
|
|
1125
|
+
return { done: true, value: void 0 };
|
|
1126
|
+
}
|
|
1127
|
+
return { done: false, value: toArrowTableFromNative(batch) };
|
|
1128
|
+
} catch (err) {
|
|
1129
|
+
throw wrapError(err);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
async unsubscribe(drain = false) {
|
|
1133
|
+
try {
|
|
1134
|
+
const drained = await this._inner.unsubscribeArrow(drain);
|
|
1135
|
+
return drained?.map(toArrowTableFromNative) ?? [];
|
|
1136
|
+
} catch (err) {
|
|
1137
|
+
throw wrapError(err);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
[Symbol.asyncIterator]() {
|
|
1141
|
+
return this;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
var Subscription = class {
|
|
1145
|
+
_inner;
|
|
1146
|
+
constructor(inner) {
|
|
1147
|
+
this._inner = inner;
|
|
1148
|
+
}
|
|
1149
|
+
async next() {
|
|
1150
|
+
try {
|
|
1151
|
+
const update = await this._inner.nextUpdate();
|
|
1152
|
+
if (update === null) {
|
|
1153
|
+
return { done: true, value: void 0 };
|
|
1154
|
+
}
|
|
1155
|
+
return { done: false, value: new Tick(update) };
|
|
1156
|
+
} catch (err) {
|
|
1157
|
+
throw wrapError(err);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
async add(tickers) {
|
|
1161
|
+
try {
|
|
1162
|
+
await this._inner.add(tickers);
|
|
1163
|
+
} catch (err) {
|
|
1164
|
+
throw wrapError(err);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
async remove(tickers) {
|
|
1168
|
+
try {
|
|
1169
|
+
await this._inner.remove(tickers);
|
|
1170
|
+
} catch (err) {
|
|
1171
|
+
throw wrapError(err);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
async unsubscribe(drain = false) {
|
|
1175
|
+
try {
|
|
1176
|
+
const drained = await this._inner.unsubscribe(drain);
|
|
1177
|
+
if (drained === null) {
|
|
1178
|
+
return [];
|
|
1179
|
+
}
|
|
1180
|
+
return drained.map((update) => new Tick(update));
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
throw wrapError(err);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
field(name) {
|
|
1186
|
+
return new FieldHandle(name);
|
|
1187
|
+
}
|
|
1188
|
+
arrow() {
|
|
1189
|
+
return new ArrowSubscription(this._inner);
|
|
1190
|
+
}
|
|
1191
|
+
get tickers() {
|
|
1192
|
+
return this._inner.tickers;
|
|
1193
|
+
}
|
|
1194
|
+
get fields() {
|
|
1195
|
+
return this._inner.fields;
|
|
1196
|
+
}
|
|
1197
|
+
get isActive() {
|
|
1198
|
+
return this._inner.isActive;
|
|
1199
|
+
}
|
|
1200
|
+
get stats() {
|
|
1201
|
+
return this._inner.stats;
|
|
1202
|
+
}
|
|
1203
|
+
[Symbol.asyncIterator]() {
|
|
1204
|
+
return this;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
var Engine = class _Engine {
|
|
1208
|
+
// Set via constructor or via `withConfig` (which instantiates via Object.create).
|
|
1209
|
+
_inner;
|
|
1210
|
+
constructor(host = "localhost", port = 8194) {
|
|
1211
|
+
try {
|
|
1212
|
+
this._inner = new native.JsEngine(host, port);
|
|
1213
|
+
} catch (err) {
|
|
1214
|
+
throw wrapError(err);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
static withConfig(config = {}) {
|
|
1218
|
+
const engine = Object.create(_Engine.prototype);
|
|
1219
|
+
try {
|
|
1220
|
+
engine._inner = native.JsEngine.withConfig(config);
|
|
1221
|
+
} catch (err) {
|
|
1222
|
+
throw wrapError(err);
|
|
1223
|
+
}
|
|
1224
|
+
return engine;
|
|
1225
|
+
}
|
|
1226
|
+
async request(params) {
|
|
1227
|
+
const backend = normalizeBackend(params.backend);
|
|
1228
|
+
const { backend: _discarded, ...nativeParams } = params;
|
|
1229
|
+
try {
|
|
1230
|
+
const buffer = await this._inner.request(nativeParams);
|
|
1231
|
+
return ipcToBackend(buffer, backend);
|
|
1232
|
+
} catch (err) {
|
|
1233
|
+
throw wrapError(err);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
async requestRaw(params) {
|
|
1237
|
+
try {
|
|
1238
|
+
return await this._inner.request(params);
|
|
1239
|
+
} catch (err) {
|
|
1240
|
+
throw wrapError(err);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
async bdp(tickers, fields, options = {}) {
|
|
1244
|
+
return await this.request({
|
|
1245
|
+
service: "//blp/refdata",
|
|
1246
|
+
operation: "ReferenceDataRequest",
|
|
1247
|
+
securities: tickers,
|
|
1248
|
+
fields,
|
|
1249
|
+
overrides: mapObjectToPairs(options.overrides),
|
|
1250
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1251
|
+
format: options.format,
|
|
1252
|
+
backend: options.backend,
|
|
1253
|
+
includeSecurityErrors: Boolean(options.includeSecurityErrors),
|
|
1254
|
+
validateFields: options.validateFields,
|
|
1255
|
+
extractor: "refdata"
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
async bds(tickers, fields, options = {}) {
|
|
1259
|
+
return await this.request({
|
|
1260
|
+
service: "//blp/refdata",
|
|
1261
|
+
operation: "ReferenceDataRequest",
|
|
1262
|
+
securities: tickers,
|
|
1263
|
+
fields,
|
|
1264
|
+
overrides: mapObjectToPairs(options.overrides),
|
|
1265
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1266
|
+
format: options.format,
|
|
1267
|
+
backend: options.backend,
|
|
1268
|
+
validateFields: options.validateFields,
|
|
1269
|
+
extractor: "bulk"
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
async bdh(tickers, fields, options = {}) {
|
|
1273
|
+
return await this.request({
|
|
1274
|
+
service: "//blp/refdata",
|
|
1275
|
+
operation: "HistoricalDataRequest",
|
|
1276
|
+
securities: tickers,
|
|
1277
|
+
fields,
|
|
1278
|
+
startDate: formatDate(options.start),
|
|
1279
|
+
endDate: formatDate(options.end),
|
|
1280
|
+
overrides: mapObjectToPairs(options.overrides),
|
|
1281
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1282
|
+
format: options.format,
|
|
1283
|
+
backend: options.backend,
|
|
1284
|
+
validateFields: options.validateFields,
|
|
1285
|
+
extractor: "histdata"
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
async bdib(ticker, options = {}) {
|
|
1289
|
+
return await this.request({
|
|
1290
|
+
service: "//blp/refdata",
|
|
1291
|
+
operation: "IntradayBarRequest",
|
|
1292
|
+
security: ticker,
|
|
1293
|
+
eventType: options.eventType ?? "TRADE",
|
|
1294
|
+
interval: options.interval ?? 1,
|
|
1295
|
+
startDatetime: formatDateTime(options.start),
|
|
1296
|
+
endDatetime: formatDateTime(options.end),
|
|
1297
|
+
requestTz: options.requestTz,
|
|
1298
|
+
outputTz: options.outputTz,
|
|
1299
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1300
|
+
backend: options.backend,
|
|
1301
|
+
extractor: "intraday_bar"
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
async bdtick(ticker, options = {}) {
|
|
1305
|
+
return await this.request({
|
|
1306
|
+
service: "//blp/refdata",
|
|
1307
|
+
operation: "IntradayTickRequest",
|
|
1308
|
+
security: ticker,
|
|
1309
|
+
eventTypes: options.eventTypes ?? ["TRADE"],
|
|
1310
|
+
startDatetime: formatDateTime(options.start),
|
|
1311
|
+
endDatetime: formatDateTime(options.end),
|
|
1312
|
+
requestTz: options.requestTz,
|
|
1313
|
+
outputTz: options.outputTz,
|
|
1314
|
+
kwargs: buildBdtickKwargs(options),
|
|
1315
|
+
backend: options.backend,
|
|
1316
|
+
extractor: "intraday_tick"
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
async bql(query, options = {}) {
|
|
1320
|
+
return await this.request({
|
|
1321
|
+
service: "//blp/bqlsvc",
|
|
1322
|
+
operation: "sendQuery",
|
|
1323
|
+
elements: [{ key: "expression", value: toRequestString(query) }],
|
|
1324
|
+
backend: options.backend,
|
|
1325
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1326
|
+
format: options.format,
|
|
1327
|
+
extractor: "bql"
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
async beqs(screen, options = {}) {
|
|
1331
|
+
const elements = [
|
|
1332
|
+
{ key: "screenName", value: toRequestString(screen) },
|
|
1333
|
+
{ key: "screenType", value: toRequestString(options.screenType ?? "PRIVATE") },
|
|
1334
|
+
{ key: "Group", value: toRequestString(options.group ?? "General") }
|
|
1335
|
+
];
|
|
1336
|
+
if (options.asof !== void 0) {
|
|
1337
|
+
const asofFormatted = formatDate(options.asof);
|
|
1338
|
+
if (asofFormatted !== void 0) {
|
|
1339
|
+
elements.push({ key: "asOfDate", value: asofFormatted });
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
const overrides = { ...options.overrides ?? {} };
|
|
1343
|
+
return await this.request({
|
|
1344
|
+
service: "//blp/refdata",
|
|
1345
|
+
operation: "BeqsRequest",
|
|
1346
|
+
elements,
|
|
1347
|
+
backend: options.backend,
|
|
1348
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1349
|
+
overrides: mapObjectToPairs(overrides),
|
|
1350
|
+
format: options.format,
|
|
1351
|
+
extractor: "generic"
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
async bsrch(searchSpec, options = {}) {
|
|
1355
|
+
const elements = {
|
|
1356
|
+
Domain: toRequestString(searchSpec),
|
|
1357
|
+
...options.overrides ?? {},
|
|
1358
|
+
...options.kwargs ?? {}
|
|
1359
|
+
};
|
|
1360
|
+
return await this.request({
|
|
1361
|
+
service: "//blp/exrsvc",
|
|
1362
|
+
operation: "ExcelGetGridRequest",
|
|
1363
|
+
backend: options.backend,
|
|
1364
|
+
elements: mapObjectToPairs(elements),
|
|
1365
|
+
format: options.format,
|
|
1366
|
+
extractor: "bsrch"
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
async bta(ticker, study, options = {}) {
|
|
1370
|
+
return await this.request({
|
|
1371
|
+
service: "//blp/tasvc",
|
|
1372
|
+
operation: "studyRequest",
|
|
1373
|
+
elements: buildTaRequest(ticker, study, options),
|
|
1374
|
+
backend: options.backend,
|
|
1375
|
+
format: options.format,
|
|
1376
|
+
extractor: "generic"
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
async bflds(options = {}) {
|
|
1380
|
+
if (options.searchSpec !== void 0) {
|
|
1381
|
+
return await this.request({
|
|
1382
|
+
service: "//blp/apiflds",
|
|
1383
|
+
operation: "FieldSearchRequest",
|
|
1384
|
+
searchSpec: toRequestString(options.searchSpec),
|
|
1385
|
+
backend: options.backend,
|
|
1386
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1387
|
+
format: options.format
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
const fields = Array.isArray(options.fields) ? options.fields : typeof options.fields === "string" ? [options.fields] : [];
|
|
1391
|
+
return await this.request({
|
|
1392
|
+
service: "//blp/apiflds",
|
|
1393
|
+
operation: "FieldInfoRequest",
|
|
1394
|
+
fieldIds: fields,
|
|
1395
|
+
backend: options.backend,
|
|
1396
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1397
|
+
format: options.format
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
async blkp(query, options = {}) {
|
|
1401
|
+
return await this.request({
|
|
1402
|
+
service: "//blp/instruments",
|
|
1403
|
+
operation: "instrumentListRequest",
|
|
1404
|
+
elements: [{ key: "query", value: toRequestString(query) }],
|
|
1405
|
+
backend: options.backend,
|
|
1406
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1407
|
+
format: options.format
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
async bport(portfolio, fields, options = {}) {
|
|
1411
|
+
return await this.request({
|
|
1412
|
+
service: "//blp/refdata",
|
|
1413
|
+
operation: "PortfolioDataRequest",
|
|
1414
|
+
security: toRequestString(portfolio),
|
|
1415
|
+
fields: Array.isArray(fields) ? fields : [toRequestString(fields)],
|
|
1416
|
+
backend: options.backend,
|
|
1417
|
+
overrides: mapObjectToPairs(options.overrides),
|
|
1418
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1419
|
+
format: options.format
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
async bcurves(ticker, options = {}) {
|
|
1423
|
+
return await this.request({
|
|
1424
|
+
service: "//blp/instruments",
|
|
1425
|
+
operation: "curveListRequest",
|
|
1426
|
+
elements: [{ key: "query", value: toRequestString(ticker) }],
|
|
1427
|
+
backend: options.backend,
|
|
1428
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1429
|
+
format: options.format
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
async bgovts(ticker, options = {}) {
|
|
1433
|
+
return await this.request({
|
|
1434
|
+
service: "//blp/instruments",
|
|
1435
|
+
operation: "govtListRequest",
|
|
1436
|
+
elements: [{ key: "query", value: toRequestString(ticker) }],
|
|
1437
|
+
backend: options.backend,
|
|
1438
|
+
kwargs: mapObjectToPairs(options.kwargs),
|
|
1439
|
+
format: options.format
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
async resolveFieldTypes(fields, overrides, defaultType = "string") {
|
|
1443
|
+
const items = await this._inner.resolveFieldTypes(
|
|
1444
|
+
fields,
|
|
1445
|
+
mapObjectToPairs(overrides),
|
|
1446
|
+
defaultType
|
|
1447
|
+
);
|
|
1448
|
+
return Object.fromEntries(items.map((item) => [item.key, item.value]));
|
|
1449
|
+
}
|
|
1450
|
+
getFieldInfo(field) {
|
|
1451
|
+
return this._inner.getFieldInfo(field);
|
|
1452
|
+
}
|
|
1453
|
+
clearFieldCache() {
|
|
1454
|
+
this._inner.clearFieldCache();
|
|
1455
|
+
}
|
|
1456
|
+
saveFieldCache() {
|
|
1457
|
+
this._inner.saveFieldCache();
|
|
1458
|
+
}
|
|
1459
|
+
async validateFields(fields) {
|
|
1460
|
+
return await this._inner.validateFields(fields);
|
|
1461
|
+
}
|
|
1462
|
+
isFieldValidationEnabled() {
|
|
1463
|
+
return this._inner.isFieldValidationEnabled();
|
|
1464
|
+
}
|
|
1465
|
+
async getSchema(service) {
|
|
1466
|
+
const json = await this._inner.getSchema(service);
|
|
1467
|
+
return JSON.parse(json);
|
|
1468
|
+
}
|
|
1469
|
+
async getOperation(service, operation) {
|
|
1470
|
+
const json = await this._inner.getOperation(service, operation);
|
|
1471
|
+
return JSON.parse(json);
|
|
1472
|
+
}
|
|
1473
|
+
async listOperations(service) {
|
|
1474
|
+
return await this._inner.listOperations(service);
|
|
1475
|
+
}
|
|
1476
|
+
getCachedSchema(service) {
|
|
1477
|
+
const json = this._inner.getCachedSchema(service);
|
|
1478
|
+
return json === null ? null : JSON.parse(json);
|
|
1479
|
+
}
|
|
1480
|
+
invalidateSchema(service) {
|
|
1481
|
+
this._inner.invalidateSchema(service);
|
|
1482
|
+
}
|
|
1483
|
+
clearSchemaCache() {
|
|
1484
|
+
this._inner.clearSchemaCache();
|
|
1485
|
+
}
|
|
1486
|
+
listCachedSchemas() {
|
|
1487
|
+
return this._inner.listCachedSchemas();
|
|
1488
|
+
}
|
|
1489
|
+
async getEnumValues(service, operation, element) {
|
|
1490
|
+
return await this._inner.getEnumValues(service, operation, element);
|
|
1491
|
+
}
|
|
1492
|
+
async listValidElements(service, operation) {
|
|
1493
|
+
return await this._inner.listValidElements(service, operation);
|
|
1494
|
+
}
|
|
1495
|
+
async subscribe(tickers, fields, options = {}) {
|
|
1496
|
+
try {
|
|
1497
|
+
const useOptions = options.options !== void 0 || options.flushThreshold !== void 0 || options.overflowPolicy !== void 0 || options.streamCapacity !== void 0;
|
|
1498
|
+
const stream = useOptions ? await this._inner.subscribeWithOptions(
|
|
1499
|
+
"//blp/mktdata",
|
|
1500
|
+
tickers,
|
|
1501
|
+
fields,
|
|
1502
|
+
options.options,
|
|
1503
|
+
options.flushThreshold,
|
|
1504
|
+
options.overflowPolicy,
|
|
1505
|
+
options.streamCapacity,
|
|
1506
|
+
options.allFields
|
|
1507
|
+
) : await this._inner.subscribe(tickers, fields, options.allFields);
|
|
1508
|
+
return new Subscription(stream);
|
|
1509
|
+
} catch (err) {
|
|
1510
|
+
throw wrapError(err);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
async subscribeWithOptions(service, tickers, fields, options, flushThreshold, overflowPolicy, streamCapacity, allFields) {
|
|
1514
|
+
try {
|
|
1515
|
+
const stream = await this._inner.subscribeWithOptions(
|
|
1516
|
+
service,
|
|
1517
|
+
tickers,
|
|
1518
|
+
fields,
|
|
1519
|
+
options,
|
|
1520
|
+
flushThreshold,
|
|
1521
|
+
overflowPolicy,
|
|
1522
|
+
streamCapacity,
|
|
1523
|
+
allFields
|
|
1524
|
+
);
|
|
1525
|
+
return new Subscription(stream);
|
|
1526
|
+
} catch (err) {
|
|
1527
|
+
throw wrapError(err);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
signalShutdown() {
|
|
1531
|
+
this._inner.signalShutdown();
|
|
1532
|
+
}
|
|
1533
|
+
isAvailable() {
|
|
1534
|
+
return this._inner.isAvailable();
|
|
1535
|
+
}
|
|
1536
|
+
async stream(tickers, fields, options = {}) {
|
|
1537
|
+
return await this.subscribeWithOptions(
|
|
1538
|
+
"//blp/mktdata",
|
|
1539
|
+
tickers,
|
|
1540
|
+
fields,
|
|
1541
|
+
options.options,
|
|
1542
|
+
options.flushThreshold,
|
|
1543
|
+
options.overflowPolicy,
|
|
1544
|
+
options.streamCapacity,
|
|
1545
|
+
options.allFields
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
async vwap(tickers, fields, options = {}) {
|
|
1549
|
+
return await this.subscribeWithOptions(
|
|
1550
|
+
"//blp/mktvwap",
|
|
1551
|
+
tickers,
|
|
1552
|
+
fields,
|
|
1553
|
+
options.options,
|
|
1554
|
+
options.flushThreshold,
|
|
1555
|
+
options.overflowPolicy,
|
|
1556
|
+
options.streamCapacity,
|
|
1557
|
+
options.allFields
|
|
1558
|
+
);
|
|
1559
|
+
}
|
|
1560
|
+
async mktbar(ticker, options = {}) {
|
|
1561
|
+
return await this.subscribeWithOptions(
|
|
1562
|
+
"//blp/mktbar",
|
|
1563
|
+
[ticker],
|
|
1564
|
+
options.fields ?? [],
|
|
1565
|
+
options.options,
|
|
1566
|
+
options.flushThreshold,
|
|
1567
|
+
options.overflowPolicy,
|
|
1568
|
+
options.streamCapacity,
|
|
1569
|
+
options.allFields
|
|
1570
|
+
);
|
|
1571
|
+
}
|
|
1572
|
+
async depth(ticker, options = {}) {
|
|
1573
|
+
return await this.subscribeWithOptions(
|
|
1574
|
+
"//blp/mktdepthdata",
|
|
1575
|
+
[ticker],
|
|
1576
|
+
options.fields ?? [],
|
|
1577
|
+
options.options,
|
|
1578
|
+
options.flushThreshold,
|
|
1579
|
+
options.overflowPolicy,
|
|
1580
|
+
options.streamCapacity,
|
|
1581
|
+
options.allFields
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
async chains(ticker, options = {}) {
|
|
1585
|
+
return await this.subscribeWithOptions(
|
|
1586
|
+
"//blp/mktlist",
|
|
1587
|
+
[ticker],
|
|
1588
|
+
options.fields ?? [],
|
|
1589
|
+
options.options,
|
|
1590
|
+
options.flushThreshold,
|
|
1591
|
+
options.overflowPolicy,
|
|
1592
|
+
options.streamCapacity,
|
|
1593
|
+
options.allFields
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
async bops(service) {
|
|
1597
|
+
return await this._inner.listOperations(service);
|
|
1598
|
+
}
|
|
1599
|
+
async bschema(service, operation) {
|
|
1600
|
+
if (operation !== void 0) {
|
|
1601
|
+
const json2 = await this._inner.getOperation(service, operation);
|
|
1602
|
+
return JSON.parse(json2);
|
|
1603
|
+
}
|
|
1604
|
+
const json = await this._inner.getSchema(service);
|
|
1605
|
+
return JSON.parse(json);
|
|
1606
|
+
}
|
|
1607
|
+
async fieldInfo(fields, options = {}) {
|
|
1608
|
+
return await this.bflds({
|
|
1609
|
+
fields: Array.isArray(fields) ? fields : [toRequestString(fields)],
|
|
1610
|
+
...options
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
async fieldSearch(searchSpec, options = {}) {
|
|
1614
|
+
return await this.bflds({ searchSpec: toRequestString(searchSpec), ...options });
|
|
1615
|
+
}
|
|
1616
|
+
// ── Recipes ─────────────────────────────────────────────────────────
|
|
1617
|
+
async bqr(ticker, options = {}) {
|
|
1618
|
+
const backend = normalizeBackend(options.backend);
|
|
1619
|
+
try {
|
|
1620
|
+
const buffer = await this._inner.recipeBqr(
|
|
1621
|
+
toRequestString(ticker),
|
|
1622
|
+
formatDateTime(options.startDatetime),
|
|
1623
|
+
formatDateTime(options.endDatetime),
|
|
1624
|
+
options.eventTypes ?? null,
|
|
1625
|
+
options.includeBrokerCodes !== false
|
|
1626
|
+
);
|
|
1627
|
+
return ipcToBackend(buffer, backend);
|
|
1628
|
+
} catch (err) {
|
|
1629
|
+
throw wrapError(err);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
async yas(tickers, fields, options = {}) {
|
|
1633
|
+
const backend = normalizeBackend(options.backend);
|
|
1634
|
+
try {
|
|
1635
|
+
const buffer = await this._inner.recipeYas(
|
|
1636
|
+
toStringArray(tickers),
|
|
1637
|
+
toStringArray(fields),
|
|
1638
|
+
formatDate(options.settleDt),
|
|
1639
|
+
options.yieldType ?? void 0,
|
|
1640
|
+
options.spread ?? void 0,
|
|
1641
|
+
options.yieldVal ?? void 0,
|
|
1642
|
+
options.price ?? void 0,
|
|
1643
|
+
options.benchmark ?? void 0
|
|
1644
|
+
);
|
|
1645
|
+
return ipcToBackend(buffer, backend);
|
|
1646
|
+
} catch (err) {
|
|
1647
|
+
throw wrapError(err);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
async preferreds(equityTicker, options = {}) {
|
|
1651
|
+
const backend = normalizeBackend(options.backend);
|
|
1652
|
+
try {
|
|
1653
|
+
const buffer = await this._inner.recipePreferreds(
|
|
1654
|
+
toRequestString(equityTicker),
|
|
1655
|
+
options.fields !== void 0 ? toStringArray(options.fields) : null
|
|
1656
|
+
);
|
|
1657
|
+
return ipcToBackend(buffer, backend);
|
|
1658
|
+
} catch (err) {
|
|
1659
|
+
throw wrapError(err);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
async corporateBonds(ticker, options = {}) {
|
|
1663
|
+
const backend = normalizeBackend(options.backend);
|
|
1664
|
+
try {
|
|
1665
|
+
const buffer = await this._inner.recipeCorporateBonds(
|
|
1666
|
+
toRequestString(ticker),
|
|
1667
|
+
options.ccy ?? void 0,
|
|
1668
|
+
options.fields !== void 0 ? toStringArray(options.fields) : null,
|
|
1669
|
+
options.activeOnly !== false
|
|
1670
|
+
);
|
|
1671
|
+
return ipcToBackend(buffer, backend);
|
|
1672
|
+
} catch (err) {
|
|
1673
|
+
throw wrapError(err);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
async futTicker(genTicker, dt, options = {}) {
|
|
1677
|
+
const backend = normalizeBackend(options.backend);
|
|
1678
|
+
try {
|
|
1679
|
+
const buffer = await this._inner.recipeFutTicker(
|
|
1680
|
+
toRequestString(genTicker),
|
|
1681
|
+
formatDate(dt) ?? "",
|
|
1682
|
+
options.freq ?? void 0
|
|
1683
|
+
);
|
|
1684
|
+
return ipcToBackend(buffer, backend);
|
|
1685
|
+
} catch (err) {
|
|
1686
|
+
throw wrapError(err);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
async activeFutures(genTicker, dt, options = {}) {
|
|
1690
|
+
const backend = normalizeBackend(options.backend);
|
|
1691
|
+
try {
|
|
1692
|
+
const buffer = await this._inner.recipeActiveFutures(
|
|
1693
|
+
toRequestString(genTicker),
|
|
1694
|
+
formatDate(dt) ?? "",
|
|
1695
|
+
options.freq ?? void 0
|
|
1696
|
+
);
|
|
1697
|
+
return ipcToBackend(buffer, backend);
|
|
1698
|
+
} catch (err) {
|
|
1699
|
+
throw wrapError(err);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
async cdxTicker(genTicker, dt, options = {}) {
|
|
1703
|
+
const backend = normalizeBackend(options.backend);
|
|
1704
|
+
try {
|
|
1705
|
+
const buffer = await this._inner.recipeCdxTicker(
|
|
1706
|
+
toRequestString(genTicker),
|
|
1707
|
+
formatDate(dt) ?? ""
|
|
1708
|
+
);
|
|
1709
|
+
return ipcToBackend(buffer, backend);
|
|
1710
|
+
} catch (err) {
|
|
1711
|
+
throw wrapError(err);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
async activeCdx(genTicker, dt, options = {}) {
|
|
1715
|
+
const backend = normalizeBackend(options.backend);
|
|
1716
|
+
try {
|
|
1717
|
+
const buffer = await this._inner.recipeActiveCdx(
|
|
1718
|
+
toRequestString(genTicker),
|
|
1719
|
+
formatDate(dt) ?? "",
|
|
1720
|
+
options.lookbackDays ?? void 0
|
|
1721
|
+
);
|
|
1722
|
+
return ipcToBackend(buffer, backend);
|
|
1723
|
+
} catch (err) {
|
|
1724
|
+
throw wrapError(err);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
async dividend(tickers, startDate, endDate, options = {}) {
|
|
1728
|
+
const backend = normalizeBackend(options.backend);
|
|
1729
|
+
try {
|
|
1730
|
+
const buffer = await this._inner.recipeDividend(
|
|
1731
|
+
toStringArray(tickers),
|
|
1732
|
+
formatDate(startDate) ?? "",
|
|
1733
|
+
formatDate(endDate) ?? "",
|
|
1734
|
+
options.dvdType ?? void 0
|
|
1735
|
+
);
|
|
1736
|
+
return ipcToBackend(buffer, backend);
|
|
1737
|
+
} catch (err) {
|
|
1738
|
+
throw wrapError(err);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
async turnover(tickers, startDate, endDate, options = {}) {
|
|
1742
|
+
const backend = normalizeBackend(options.backend);
|
|
1743
|
+
try {
|
|
1744
|
+
const buffer = await this._inner.recipeTurnover(
|
|
1745
|
+
toStringArray(tickers),
|
|
1746
|
+
formatDate(startDate) ?? "",
|
|
1747
|
+
formatDate(endDate) ?? "",
|
|
1748
|
+
options.ccy ?? void 0,
|
|
1749
|
+
options.factor ?? void 0
|
|
1750
|
+
);
|
|
1751
|
+
return ipcToBackend(buffer, backend);
|
|
1752
|
+
} catch (err) {
|
|
1753
|
+
throw wrapError(err);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
async etfHoldings(etfTicker, options = {}) {
|
|
1757
|
+
const backend = normalizeBackend(options.backend);
|
|
1758
|
+
try {
|
|
1759
|
+
const buffer = await this._inner.recipeEtfHoldings(
|
|
1760
|
+
toRequestString(etfTicker),
|
|
1761
|
+
options.fields !== void 0 ? toStringArray(options.fields) : null
|
|
1762
|
+
);
|
|
1763
|
+
return ipcToBackend(buffer, backend);
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
throw wrapError(err);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
async currencyConversion(ticker, targetCcy, startDate, endDate, options = {}) {
|
|
1769
|
+
const backend = normalizeBackend(options.backend);
|
|
1770
|
+
try {
|
|
1771
|
+
const buffer = await this._inner.recipeCurrencyConversion(
|
|
1772
|
+
toRequestString(ticker),
|
|
1773
|
+
toRequestString(targetCcy),
|
|
1774
|
+
formatDate(startDate) ?? "",
|
|
1775
|
+
formatDate(endDate) ?? ""
|
|
1776
|
+
);
|
|
1777
|
+
return ipcToBackend(buffer, backend);
|
|
1778
|
+
} catch (err) {
|
|
1779
|
+
throw wrapError(err);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
async function connect(config) {
|
|
1784
|
+
return await Promise.resolve(
|
|
1785
|
+
config === void 0 ? new Engine() : Engine.withConfig(config)
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1788
|
+
function configure(configOrHost, port) {
|
|
1789
|
+
configuredEngineConfig = normalizeConfigureArgs(configOrHost, port);
|
|
1790
|
+
clearConfiguredEngine();
|
|
1791
|
+
return configuredEngineConfig;
|
|
1792
|
+
}
|
|
1793
|
+
async function abdp(tickers, fields, options = {}) {
|
|
1794
|
+
const engine = await getConfiguredEngine();
|
|
1795
|
+
return await engine.bdp(toStringArray(tickers), toStringArray(fields), options);
|
|
1796
|
+
}
|
|
1797
|
+
async function bdp(tickers, fields, options = {}) {
|
|
1798
|
+
return await abdp(tickers, fields, options);
|
|
1799
|
+
}
|
|
1800
|
+
async function abdh(tickers, fields, start, end, options = {}) {
|
|
1801
|
+
const engine = await getConfiguredEngine();
|
|
1802
|
+
if (isPlainObject(start) && !(start instanceof Date) && !hasToJSDate(start) && end === void 0) {
|
|
1803
|
+
return await engine.bdh(
|
|
1804
|
+
toStringArray(tickers),
|
|
1805
|
+
toStringArray(fields),
|
|
1806
|
+
start
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
return await engine.bdh(toStringArray(tickers), toStringArray(fields), {
|
|
1810
|
+
...options,
|
|
1811
|
+
start,
|
|
1812
|
+
end
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
async function bdh(tickers, fields, options = {}) {
|
|
1816
|
+
return await abdh(tickers, fields, options);
|
|
1817
|
+
}
|
|
1818
|
+
async function abds(tickers, fields, overrides, options = {}) {
|
|
1819
|
+
const engine = await getConfiguredEngine();
|
|
1820
|
+
const normalizedOptions = isPlainObject(overrides) ? { ...options, overrides: { ...options.overrides ?? {}, ...overrides } } : options;
|
|
1821
|
+
return await engine.bds(
|
|
1822
|
+
toStringArray(tickers),
|
|
1823
|
+
toStringArray(fields),
|
|
1824
|
+
normalizedOptions
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
async function bds(tickers, fields, options = {}) {
|
|
1828
|
+
return await abds(tickers, fields, void 0, options);
|
|
1829
|
+
}
|
|
1830
|
+
async function abdib(ticker, dt, interval = 1, options = {}) {
|
|
1831
|
+
const engine = await getConfiguredEngine();
|
|
1832
|
+
const dtIsOptions = isPlainObject(dt) && !(dt instanceof Date) && !hasToJSDate(dt);
|
|
1833
|
+
if (dtIsOptions && interval === 1 && Object.keys(options).length === 0) {
|
|
1834
|
+
return await engine.bdib(toRequestString(ticker), dt);
|
|
1835
|
+
}
|
|
1836
|
+
const normalizedOptions = isPlainObject(interval) ? { ...interval } : { ...options, interval: typeof interval === "number" ? interval : 1 };
|
|
1837
|
+
if (normalizedOptions.start === void 0 && normalizedOptions.end === void 0) {
|
|
1838
|
+
if (dt === void 0) {
|
|
1839
|
+
throw new TypeError("abdib requires dt or explicit start/end options");
|
|
1840
|
+
}
|
|
1841
|
+
const range = fullDayRange(dt);
|
|
1842
|
+
normalizedOptions.start = range.start;
|
|
1843
|
+
normalizedOptions.end = range.end;
|
|
1844
|
+
}
|
|
1845
|
+
return await engine.bdib(toRequestString(ticker), normalizedOptions);
|
|
1846
|
+
}
|
|
1847
|
+
async function bdib(ticker, options = {}) {
|
|
1848
|
+
return await abdib(ticker, options);
|
|
1849
|
+
}
|
|
1850
|
+
async function abdtick(ticker, start, end, options = {}) {
|
|
1851
|
+
if (start === void 0 || start === null || end === void 0 || end === null) {
|
|
1852
|
+
throw new TypeError("abdtick requires both start and end datetimes");
|
|
1853
|
+
}
|
|
1854
|
+
const engine = await getConfiguredEngine();
|
|
1855
|
+
return await engine.bdtick(toRequestString(ticker), { ...options, start, end });
|
|
1856
|
+
}
|
|
1857
|
+
async function bdtick(ticker, options = {}) {
|
|
1858
|
+
const engine = await getConfiguredEngine();
|
|
1859
|
+
return await engine.bdtick(toRequestString(ticker), options);
|
|
1860
|
+
}
|
|
1861
|
+
async function asubscribe(tickers, fields, options = {}) {
|
|
1862
|
+
const engine = await getConfiguredEngine();
|
|
1863
|
+
return await engine.subscribe(toStringArray(tickers), toStringArray(fields), options);
|
|
1864
|
+
}
|
|
1865
|
+
async function subscribe(tickers, fields, options = {}) {
|
|
1866
|
+
return await asubscribe(tickers, fields, options);
|
|
1867
|
+
}
|
|
1868
|
+
async function acdxInfo(ticker, options = {}) {
|
|
1869
|
+
const engine = await getConfiguredEngine();
|
|
1870
|
+
return await engine.bdp([toRequestString(ticker)], [...CDX_INFO_FIELDS], options);
|
|
1871
|
+
}
|
|
1872
|
+
async function acdxPricing(ticker, options = {}) {
|
|
1873
|
+
const engine = await getConfiguredEngine();
|
|
1874
|
+
return await engine.bdp(
|
|
1875
|
+
[toRequestString(ticker)],
|
|
1876
|
+
[...CDX_PRICING_FIELDS],
|
|
1877
|
+
normalizeRecoveryOptions(options)
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
async function acdxRisk(ticker, options = {}) {
|
|
1881
|
+
const engine = await getConfiguredEngine();
|
|
1882
|
+
return await engine.bdp(
|
|
1883
|
+
[toRequestString(ticker)],
|
|
1884
|
+
[...CDX_RISK_FIELDS],
|
|
1885
|
+
normalizeRecoveryOptions(options)
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
var blp = Object.freeze({
|
|
1889
|
+
bdp,
|
|
1890
|
+
bdh,
|
|
1891
|
+
bds,
|
|
1892
|
+
bdib,
|
|
1893
|
+
bdtick,
|
|
1894
|
+
subscribe,
|
|
1895
|
+
abdp,
|
|
1896
|
+
abdh,
|
|
1897
|
+
abds,
|
|
1898
|
+
abdib,
|
|
1899
|
+
abdtick,
|
|
1900
|
+
asubscribe
|
|
1901
|
+
});
|
|
1902
|
+
var ext = Object.freeze({
|
|
1903
|
+
cdx: Object.freeze({
|
|
1904
|
+
acdx_info: acdxInfo,
|
|
1905
|
+
acdx_pricing: acdxPricing,
|
|
1906
|
+
acdx_risk: acdxRisk
|
|
1907
|
+
}),
|
|
1908
|
+
parseDate: native.extParseDate,
|
|
1909
|
+
fmtDate: native.extFmtDate,
|
|
1910
|
+
pivotToWide: native.extPivotToWide,
|
|
1911
|
+
isLongFormat: native.extIsLongFormat,
|
|
1912
|
+
parseTicker: native.extParseTicker,
|
|
1913
|
+
isSpecificContract: native.extIsSpecificContract,
|
|
1914
|
+
buildFuturesTicker: native.extBuildFuturesTicker,
|
|
1915
|
+
normalizeTickers: native.extNormalizeTickers,
|
|
1916
|
+
filterEquityTickers: native.extFilterEquityTickers,
|
|
1917
|
+
generateFuturesCandidates: native.extGenerateFuturesCandidates,
|
|
1918
|
+
validateGenericTicker: native.extValidateGenericTicker,
|
|
1919
|
+
contractIndex: native.extContractIndex,
|
|
1920
|
+
filterCandidatesByCycle: native.extFilterCandidatesByCycle,
|
|
1921
|
+
filterValidContracts: native.extFilterValidContracts,
|
|
1922
|
+
parseCdxTicker: native.extParseCdxTicker,
|
|
1923
|
+
previousCdxSeries: native.extPreviousCdxSeries,
|
|
1924
|
+
cdxGenToSpecific: native.extCdxGenToSpecific,
|
|
1925
|
+
buildFxPair: native.extBuildFxPair,
|
|
1926
|
+
sameCurrency: native.extSameCurrency,
|
|
1927
|
+
currenciesNeedingConversion: native.extCurrenciesNeedingConversion,
|
|
1928
|
+
renameDividendColumns: native.extRenameDividendColumns,
|
|
1929
|
+
renameEtfColumns: native.extRenameEtfColumns,
|
|
1930
|
+
getMonthCode: native.extGetMonthCode,
|
|
1931
|
+
getMonthName: native.extGetMonthName,
|
|
1932
|
+
getFuturesMonths: native.extGetFuturesMonths,
|
|
1933
|
+
getDvdType: native.extGetDvdType,
|
|
1934
|
+
getDvdTypes: native.extGetDvdTypes,
|
|
1935
|
+
getDvdCols: native.extGetDvdCols,
|
|
1936
|
+
getEtfCols: native.extGetEtfCols,
|
|
1937
|
+
buildYasOverrides: native.extBuildYasOverrides,
|
|
1938
|
+
buildEarningHeaderRename: native.extBuildEarningHeaderRename,
|
|
1939
|
+
calculateLevelPercentages: native.extCalculateLevelPercentages,
|
|
1940
|
+
buildPreferredsQuery: native.extBuildPreferredsQuery,
|
|
1941
|
+
buildCorporateBondsQuery: native.extBuildCorporateBondsQuery,
|
|
1942
|
+
buildEtfHoldingsQuery: native.extBuildEtfHoldingsQuery,
|
|
1943
|
+
defaultTurnoverDates: native.extDefaultTurnoverDates,
|
|
1944
|
+
defaultBqrDatetimes: native.extDefaultBqrDatetimes,
|
|
1945
|
+
deriveSessions: native.extDeriveSessions,
|
|
1946
|
+
getMarketRule: native.extGetMarketRule,
|
|
1947
|
+
inferTimezone: native.extInferTimezone,
|
|
1948
|
+
setExchangeOverride: native.extSetExchangeOverride,
|
|
1949
|
+
getExchangeOverride: native.extGetExchangeOverride,
|
|
1950
|
+
clearExchangeOverride: native.extClearExchangeOverride,
|
|
1951
|
+
listExchangeOverrides: native.extListExchangeOverrides,
|
|
1952
|
+
sessionTimesToUtc: native.extSessionTimesToUtc
|
|
1953
|
+
});
|
|
1954
|
+
function version() {
|
|
1955
|
+
return packageJson.version;
|
|
1956
|
+
}
|
|
1957
|
+
var setLogLevel = native.setLogLevel;
|
|
1958
|
+
var getLogLevel = native.getLogLevel;
|
|
1959
|
+
|
|
1960
|
+
exports.ArrowSubscription = ArrowSubscription;
|
|
1961
|
+
exports.Backend = Backend;
|
|
1962
|
+
exports.BlpError = BlpError;
|
|
1963
|
+
exports.BlpInternalError = BlpInternalError;
|
|
1964
|
+
exports.BlpRequestError = BlpRequestError;
|
|
1965
|
+
exports.BlpSessionError = BlpSessionError;
|
|
1966
|
+
exports.BlpTimeoutError = BlpTimeoutError;
|
|
1967
|
+
exports.BlpValidationError = BlpValidationError;
|
|
1968
|
+
exports.Engine = Engine;
|
|
1969
|
+
exports.FieldHandle = FieldHandle;
|
|
1970
|
+
exports.Format = Format;
|
|
1971
|
+
exports.Subscription = Subscription;
|
|
1972
|
+
exports.Tick = Tick;
|
|
1973
|
+
exports.abdh = abdh;
|
|
1974
|
+
exports.abdib = abdib;
|
|
1975
|
+
exports.abdp = abdp;
|
|
1976
|
+
exports.abds = abds;
|
|
1977
|
+
exports.abdtick = abdtick;
|
|
1978
|
+
exports.asubscribe = asubscribe;
|
|
1979
|
+
exports.bdh = bdh;
|
|
1980
|
+
exports.bdib = bdib;
|
|
1981
|
+
exports.bdp = bdp;
|
|
1982
|
+
exports.bds = bds;
|
|
1983
|
+
exports.bdtick = bdtick;
|
|
1984
|
+
exports.blp = blp;
|
|
1985
|
+
exports.configure = configure;
|
|
1986
|
+
exports.connect = connect;
|
|
1987
|
+
exports.ext = ext;
|
|
1988
|
+
exports.formatDate = formatDate;
|
|
1989
|
+
exports.formatDateTime = formatDateTime;
|
|
1990
|
+
exports.getLogLevel = getLogLevel;
|
|
1991
|
+
exports.setLogLevel = setLogLevel;
|
|
1992
|
+
exports.subscribe = subscribe;
|
|
1993
|
+
exports.version = version;
|
|
1994
|
+
exports.wrapError = wrapError;
|
|
1995
|
+
//# sourceMappingURL=index.js.map
|
|
1996
|
+
//# sourceMappingURL=index.js.map
|