@steerprotocol/app-loader 0.2.0 → 0.2.3
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/lib/index.d.ts +0 -10
- package/lib/index.js +143 -59
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -11,16 +11,6 @@ export type WasmModule = {
|
|
|
11
11
|
responseHandler: typeof responseHandler;
|
|
12
12
|
initialize: typeof initialize;
|
|
13
13
|
execute: typeof execute;
|
|
14
|
-
"execute(param_1: string)": typeof execute;
|
|
15
|
-
"execute(param_1: string, param_2: string)": typeof execute;
|
|
16
|
-
"execute(param_1: string, param_2: string, param_3: string)": typeof execute;
|
|
17
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string)": typeof execute;
|
|
18
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string)": typeof execute;
|
|
19
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string)": typeof execute;
|
|
20
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string)": typeof execute;
|
|
21
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string, param_8: string)": typeof execute;
|
|
22
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string, param_8: string, param_9: string)": typeof execute;
|
|
23
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string, param_8: string, param_9: string, param_10: string)": typeof execute;
|
|
24
14
|
config: typeof config;
|
|
25
15
|
version: typeof version;
|
|
26
16
|
transform: typeof transform;
|
package/lib/index.js
CHANGED
|
@@ -45,14 +45,25 @@ const RawTradeData_1 = require("./RawTradeData");
|
|
|
45
45
|
Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
|
|
46
46
|
let _fetchGETSyncPtr = 0;
|
|
47
47
|
let _fetchPOSTSyncPtr = 0;
|
|
48
|
+
let _ohlcvPtr = 0;
|
|
48
49
|
let ASYNCIFY_PTR = 0;
|
|
49
50
|
let ASYNCIFY_MEM;
|
|
51
|
+
let ASYNCIFY_INITIALIZED = false;
|
|
50
52
|
let _exports;
|
|
51
53
|
function instantiate(module, imports = {}) {
|
|
52
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
55
|
const adaptedImports = {
|
|
54
56
|
// @ts-ignore
|
|
55
57
|
env: Object.assign(Object.create(globalThis), imports.env || {}, {
|
|
58
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
59
|
+
if (ASYNCIFY_INITIALIZED)
|
|
60
|
+
return;
|
|
61
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
62
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
63
|
+
// I don't know if I need to reserve all this memory...
|
|
64
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
65
|
+
ASYNCIFY_INITIALIZED = true;
|
|
66
|
+
},
|
|
56
67
|
abort(message, fileName, lineNumber, columnNumber) {
|
|
57
68
|
(() => {
|
|
58
69
|
throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);
|
|
@@ -62,70 +73,64 @@ function instantiate(module, imports = {}) {
|
|
|
62
73
|
const _data = __liftString(data) || '[]';
|
|
63
74
|
const _candleSize = __liftString(candleSize) || '69m';
|
|
64
75
|
const candles = generateCandles(JSON.parse(_data), _candleSize);
|
|
65
|
-
// We could pack this data into binary before sending...
|
|
66
|
-
// Much faster
|
|
67
|
-
// Which are 32 bit and which are 64?
|
|
68
|
-
// I'll assume 32 bits for now though I believe timestamp should be 64
|
|
69
|
-
/*
|
|
70
|
-
const decodedCandles: Candle[] = [];
|
|
71
|
-
|
|
72
|
-
for (let i = 0; i < __liftBuffer(data).byteLength >> 2; i++) {
|
|
73
|
-
decodedCandles.push(decodeCandle(new Uint32Array(data, i * 6, 6)));
|
|
74
|
-
}
|
|
75
|
-
const candles =
|
|
76
|
-
|
|
77
|
-
let buffer = new Uint32Array(candles.length * 6);
|
|
78
|
-
for (let i = 0; i < candles.length; i++) {
|
|
79
|
-
const candle = candles[i];
|
|
80
|
-
// Pack it into
|
|
81
|
-
|
|
82
|
-
// Structure: [timestamp, high, low, open, close, volume]
|
|
83
|
-
// Stride: 24 bytes
|
|
84
|
-
// This is essentially what FASS does
|
|
85
|
-
|
|
86
|
-
buffer.set(
|
|
87
|
-
encodeCandle(candle),
|
|
88
|
-
i
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
return __lowerBuffer(buffer);*/
|
|
92
76
|
return __lowerString(JSON.stringify(candles));
|
|
93
77
|
},
|
|
94
78
|
'console.log': (text) => {
|
|
95
79
|
console.log(__liftString(text));
|
|
96
80
|
},
|
|
97
|
-
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) =>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
|
|
82
|
+
// Since may need to be passed as 64-bit?
|
|
83
|
+
// Timestamps are large
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
const currentState = _exports.asyncify_get_state();
|
|
86
|
+
if (currentState === 2) {
|
|
87
|
+
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
_exports.asyncify_stop_rewind();
|
|
90
|
+
return _ohlcvPtr;
|
|
91
|
+
}
|
|
92
|
+
else if (currentState === 0) {
|
|
93
|
+
//console.log("asyncify_start_unwind() [pause wasm]");
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
_exports.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
96
|
+
// How about we pass an Enum back and forth?
|
|
97
|
+
const _exchange = __liftString(exchangeId);
|
|
98
|
+
const _symbol = __liftString(symbol);
|
|
99
|
+
const _timeframe = __liftString(timeframe);
|
|
100
|
+
if (!_exchange || !_symbol || !_timeframe)
|
|
101
|
+
throw new Error("Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.");
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
new ccxt_1.default[_exchange]({
|
|
104
|
+
apiKey: "",
|
|
105
|
+
secret: ""
|
|
106
|
+
}).fetchOHLCV(_symbol, _timeframe, since, limit).then((data) => {
|
|
107
|
+
//console.log("asyncify_stop_unwind() [unpause wasm]");
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
_exports.asyncify_stop_unwind();
|
|
110
|
+
// @ts-ignore: __new is defined
|
|
111
|
+
_ohlcvPtr = __lowerStaticArray((pointer, value) => { __setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array)); }, 8, 2, data);
|
|
112
|
+
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
111
113
|
// @ts-ignore
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
process.env.DEBUG && console.error(e);
|
|
118
|
-
}
|
|
114
|
+
_exports.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
115
|
+
_exports.execute();
|
|
116
|
+
});
|
|
119
117
|
}
|
|
120
|
-
|
|
121
|
-
})
|
|
118
|
+
}
|
|
122
119
|
}),
|
|
120
|
+
console: {
|
|
121
|
+
log: (msg) => {
|
|
122
|
+
console.log(__liftString(msg >>> 0));
|
|
123
|
+
}
|
|
124
|
+
},
|
|
123
125
|
'as-fetch': {
|
|
124
126
|
_initAsyncify(frame_ptr, stack_ptr) {
|
|
127
|
+
if (ASYNCIFY_INITIALIZED)
|
|
128
|
+
return;
|
|
125
129
|
ASYNCIFY_PTR = frame_ptr;
|
|
126
130
|
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
127
131
|
// I don't know if I need to reserve all this memory...
|
|
128
132
|
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
133
|
+
ASYNCIFY_INITIALIZED = true;
|
|
129
134
|
},
|
|
130
135
|
_fetchPOSTSync(url, mode, headers, body) {
|
|
131
136
|
var _a;
|
|
@@ -254,6 +259,61 @@ function instantiate(module, imports = {}) {
|
|
|
254
259
|
}
|
|
255
260
|
},
|
|
256
261
|
}, exports);
|
|
262
|
+
let __dataview = new DataView(memory.buffer);
|
|
263
|
+
function __liftArray(liftElement, align, pointer) {
|
|
264
|
+
if (!pointer)
|
|
265
|
+
return null;
|
|
266
|
+
const dataStart = __getU32(pointer + 4), length = __dataview.getUint32(pointer + 12, true), values = new Array(length);
|
|
267
|
+
for (let i = 0; i < length; ++i)
|
|
268
|
+
values[i] = liftElement(dataStart + (i << align));
|
|
269
|
+
return values;
|
|
270
|
+
}
|
|
271
|
+
function __lowerArray(lowerElement, id, align, values) {
|
|
272
|
+
if (values == null)
|
|
273
|
+
return 0;
|
|
274
|
+
const length = values.length,
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
buffer = __retain(exports.__new(length << align, 1)),
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
header = __retain(exports.__new(16, id));
|
|
279
|
+
__setU32(header + 0, buffer);
|
|
280
|
+
__dataview.setUint32(header + 4, buffer, true);
|
|
281
|
+
__dataview.setUint32(header + 8, length << align, true);
|
|
282
|
+
__dataview.setUint32(header + 12, length, true);
|
|
283
|
+
for (let i = 0; i < length; ++i)
|
|
284
|
+
lowerElement(buffer + (i << align), values[i]);
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
//exports.__unpin(buffer);
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
//exports.__unpin(header);
|
|
289
|
+
return header;
|
|
290
|
+
}
|
|
291
|
+
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor) {
|
|
292
|
+
if (values == null)
|
|
293
|
+
return 0;
|
|
294
|
+
const length = values.length,
|
|
295
|
+
// @ts-ignore: __pin and __new are defined
|
|
296
|
+
buffer = _exports.__pin(_exports.__new(length << align, id)) >>> 0;
|
|
297
|
+
if (typedConstructor) {
|
|
298
|
+
new typedConstructor(_exports.memory.buffer, buffer, length).set(values);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
for (let i = 0; i < length; i++)
|
|
302
|
+
lowerElement(buffer + (i << align >>> 0), values[i]);
|
|
303
|
+
}
|
|
304
|
+
// @ts-ignore: __unpin is defined
|
|
305
|
+
_exports.__unpin(buffer);
|
|
306
|
+
return buffer;
|
|
307
|
+
}
|
|
308
|
+
function __setF64(pointer, value) {
|
|
309
|
+
try {
|
|
310
|
+
__dataview.setFloat64(pointer, value, true);
|
|
311
|
+
}
|
|
312
|
+
catch (_a) {
|
|
313
|
+
__dataview = new DataView(memory.buffer);
|
|
314
|
+
__dataview.setFloat64(pointer, value, true);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
257
317
|
function __liftBuffer(pointer) {
|
|
258
318
|
if (!pointer)
|
|
259
319
|
return null;
|
|
@@ -287,15 +347,6 @@ function instantiate(module, imports = {}) {
|
|
|
287
347
|
memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
|
|
288
348
|
return pointer;
|
|
289
349
|
}
|
|
290
|
-
function __liftArray(liftElement, align, pointer) {
|
|
291
|
-
if (!pointer)
|
|
292
|
-
return null;
|
|
293
|
-
const dataStart = __getU32(pointer + 4), length = __dataview.getUint32(pointer + 12, true), values = new Array(length);
|
|
294
|
-
for (let i = 0; i < length; ++i)
|
|
295
|
-
values[i] = liftElement(dataStart + (i << align));
|
|
296
|
-
return values;
|
|
297
|
-
}
|
|
298
|
-
let __dataview = new DataView(memory.buffer);
|
|
299
350
|
function __getU32(pointer) {
|
|
300
351
|
try {
|
|
301
352
|
return __dataview.getUint32(pointer, true);
|
|
@@ -305,6 +356,39 @@ function instantiate(module, imports = {}) {
|
|
|
305
356
|
return __dataview.getUint32(pointer, true);
|
|
306
357
|
}
|
|
307
358
|
}
|
|
359
|
+
function __setU32(pointer, value) {
|
|
360
|
+
try {
|
|
361
|
+
__dataview.setUint32(pointer, value, true);
|
|
362
|
+
}
|
|
363
|
+
catch (_a) {
|
|
364
|
+
__dataview = new DataView(memory.buffer);
|
|
365
|
+
__dataview.setUint32(pointer, value, true);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const refcounts = new Map();
|
|
369
|
+
function __retain(pointer) {
|
|
370
|
+
if (pointer) {
|
|
371
|
+
const refcount = refcounts.get(pointer);
|
|
372
|
+
if (refcount)
|
|
373
|
+
refcounts.set(pointer, refcount + 1);
|
|
374
|
+
// @ts-ignore: __pin is defined
|
|
375
|
+
else
|
|
376
|
+
refcounts.set(exports.__pin(pointer), 1);
|
|
377
|
+
}
|
|
378
|
+
return pointer;
|
|
379
|
+
}
|
|
380
|
+
function __release(pointer) {
|
|
381
|
+
if (pointer) {
|
|
382
|
+
const refcount = refcounts.get(pointer);
|
|
383
|
+
// @ts-ignore: __unpin is defined
|
|
384
|
+
if (refcount === 1)
|
|
385
|
+
exports.__unpin(pointer), refcounts.delete(pointer);
|
|
386
|
+
else if (refcount)
|
|
387
|
+
refcounts.set(pointer, refcount - 1);
|
|
388
|
+
else
|
|
389
|
+
throw Error(`invalid refcount '${refcount}' for reference '${pointer}'`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
308
392
|
function generateCandles(data, candleSize) {
|
|
309
393
|
const candleWidth = (0, timestring_1.default)(candleSize, 'ms', {});
|
|
310
394
|
if (data.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lib/**/*"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"ccxt": "^
|
|
49
|
+
"ccxt": "^4.0.52",
|
|
50
50
|
"timestring": "^7.0.0"
|
|
51
51
|
}
|
|
52
52
|
}
|