@steerprotocol/app-loader 0.0.5 → 0.0.7
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 +14 -0
- package/lib/index.js +77 -2
- package/package.json +6 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export declare class Candle {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
high: number;
|
|
4
|
+
low: number;
|
|
5
|
+
open: number;
|
|
6
|
+
close: number;
|
|
7
|
+
volume: number;
|
|
8
|
+
constructor(timestamp: number, high: number, low: number, open: number, close: number, volume: number);
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* assembly/index/initialize
|
|
3
13
|
* @param config `~lib/string/String`
|
|
@@ -28,5 +38,9 @@ export type WasmModule = {
|
|
|
28
38
|
transform: typeof transform;
|
|
29
39
|
memory: WebAssembly.Memory;
|
|
30
40
|
};
|
|
41
|
+
export type TickData = {
|
|
42
|
+
index: number;
|
|
43
|
+
value: string;
|
|
44
|
+
};
|
|
31
45
|
export declare const loadWasm: (input: string | ArrayBuffer, imports?: {}) => Promise<WasmModule>;
|
|
32
46
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.loadWasm = void 0;
|
|
35
|
+
exports.loadWasm = exports.Candle = void 0;
|
|
36
|
+
const pondjs_1 = require("pondjs");
|
|
37
|
+
const types_1 = require("pondjs/lib/types");
|
|
38
|
+
class Candle {
|
|
39
|
+
constructor(timestamp, high, low, open, close, volume) {
|
|
40
|
+
this.timestamp = timestamp;
|
|
41
|
+
this.high = high;
|
|
42
|
+
this.low = low;
|
|
43
|
+
this.open = open;
|
|
44
|
+
this.close = close;
|
|
45
|
+
this.volume = volume;
|
|
46
|
+
}
|
|
47
|
+
toString() {
|
|
48
|
+
return JSON.stringify(this);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Candle = Candle;
|
|
36
52
|
function instantiate(module, imports = {}) {
|
|
37
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
54
|
const adaptedImports = {
|
|
@@ -50,10 +66,17 @@ function instantiate(module, imports = {}) {
|
|
|
50
66
|
throw new Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
|
|
51
67
|
})();
|
|
52
68
|
},
|
|
69
|
+
generateCandles(data, candleSize) {
|
|
70
|
+
const _data = __liftString(data >>> 0) || '[]';
|
|
71
|
+
console.log("🧙♂️ 🔎 -> ~ file: index.ts:72 ~ generateCandles ~ _data", _data);
|
|
72
|
+
const _candleSize = __liftString(candleSize >>> 0) || '69m';
|
|
73
|
+
console.log("🧙♂️ 🔎 -> ~ file: index.ts:74 ~ generateCandles ~ _candleSize", _candleSize);
|
|
74
|
+
return __lowerString(JSON.stringify(generateCandles(JSON.parse(_data), _candleSize)));
|
|
75
|
+
}
|
|
53
76
|
}),
|
|
54
77
|
console: {
|
|
55
78
|
log: (msg) => {
|
|
56
|
-
console.log(msg);
|
|
79
|
+
console.log(__liftString(msg >>> 0));
|
|
57
80
|
},
|
|
58
81
|
}
|
|
59
82
|
};
|
|
@@ -184,6 +207,58 @@ function instantiate(module, imports = {}) {
|
|
|
184
207
|
return __dataview.getFloat64(pointer, true);
|
|
185
208
|
}
|
|
186
209
|
}
|
|
210
|
+
function generateCandles(data, candleSize) {
|
|
211
|
+
if (data[0] === undefined || Object.keys(data[0]).length === 0) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
const series = (0, pondjs_1.timeSeries)({
|
|
215
|
+
name: 'swaps',
|
|
216
|
+
columns: [...Object.keys(data[0])],
|
|
217
|
+
points: data.map((point) => {
|
|
218
|
+
return [...Object.values(point)].map(value => Number(value));
|
|
219
|
+
}),
|
|
220
|
+
});
|
|
221
|
+
const windowRollup = series
|
|
222
|
+
.fixedWindowRollup({
|
|
223
|
+
window: (0, pondjs_1.window)((0, pondjs_1.duration)(candleSize)),
|
|
224
|
+
aggregation: {
|
|
225
|
+
high: ['value', (0, pondjs_1.max)()],
|
|
226
|
+
low: ['value', (0, pondjs_1.min)()],
|
|
227
|
+
close: ['value', (0, pondjs_1.last)()],
|
|
228
|
+
open: ['value', (0, pondjs_1.first)()],
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
.fill({
|
|
232
|
+
fieldSpec: 'value',
|
|
233
|
+
method: 2,
|
|
234
|
+
});
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
return windowRollup
|
|
238
|
+
.toJSON()
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
240
|
+
// @ts-ignore
|
|
241
|
+
.points.map((p) => {
|
|
242
|
+
// Convert time range to timestamp of beginning of range
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
p[0] = new pondjs_1.Index(p[0])
|
|
246
|
+
.toTimeRange()
|
|
247
|
+
.toTime(types_1.TimeAlignment.Begin)
|
|
248
|
+
.toDate()
|
|
249
|
+
.getTime();
|
|
250
|
+
return p;
|
|
251
|
+
})
|
|
252
|
+
.map((p) => {
|
|
253
|
+
return {
|
|
254
|
+
timestamp: p[0],
|
|
255
|
+
high: p[1],
|
|
256
|
+
low: p[2],
|
|
257
|
+
close: p[3],
|
|
258
|
+
open: p[4],
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
187
262
|
return adaptedExports;
|
|
188
263
|
});
|
|
189
264
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
8
|
+
"build": "tsc --build tsconfig.json",
|
|
9
9
|
"format": "prettier --write \"src/**/*.(js|ts)\"",
|
|
10
10
|
"lint": "eslint src --ext .js,.ts",
|
|
11
11
|
"lint:fix": "eslint src --fix --ext .js,.ts",
|
|
@@ -43,5 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"lib/**/*"
|
|
46
|
-
]
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"pondjs": "1.0.0-alpha.10"
|
|
49
|
+
}
|
|
47
50
|
}
|