@steerprotocol/app-loader 0.0.5 → 0.0.8
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 +16 -0
- package/lib/index.js +87 -2
- package/package.json +5 -2
- package/lib/helpers/uuid.d.ts +0 -7
- package/lib/helpers/uuid.js +0 -14
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export declare class RawTradeData {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
price: number;
|
|
4
|
+
volume: number;
|
|
5
|
+
constructor(timestamp: number, price: number, volume: number);
|
|
6
|
+
}
|
|
7
|
+
export declare class Candle {
|
|
8
|
+
timestamp: number;
|
|
9
|
+
high: number;
|
|
10
|
+
low: number;
|
|
11
|
+
open: number;
|
|
12
|
+
close: number;
|
|
13
|
+
volume: number;
|
|
14
|
+
constructor(timestamp: number, high: number, low: number, open: number, close: number, volume: number);
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
1
17
|
/**
|
|
2
18
|
* assembly/index/initialize
|
|
3
19
|
* @param config `~lib/string/String`
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,31 @@ 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 = exports.RawTradeData = void 0;
|
|
36
|
+
const pondjs_1 = require("pondjs");
|
|
37
|
+
const types_1 = require("pondjs/lib/types");
|
|
38
|
+
class RawTradeData {
|
|
39
|
+
constructor(timestamp, price, volume) {
|
|
40
|
+
this.timestamp = timestamp;
|
|
41
|
+
this.price = price;
|
|
42
|
+
this.volume = volume;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.RawTradeData = RawTradeData;
|
|
46
|
+
class Candle {
|
|
47
|
+
constructor(timestamp, high, low, open, close, volume) {
|
|
48
|
+
this.timestamp = timestamp;
|
|
49
|
+
this.high = high;
|
|
50
|
+
this.low = low;
|
|
51
|
+
this.open = open;
|
|
52
|
+
this.close = close;
|
|
53
|
+
this.volume = volume;
|
|
54
|
+
}
|
|
55
|
+
toString() {
|
|
56
|
+
return JSON.stringify(this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Candle = Candle;
|
|
36
60
|
function instantiate(module, imports = {}) {
|
|
37
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
62
|
const adaptedImports = {
|
|
@@ -50,10 +74,17 @@ function instantiate(module, imports = {}) {
|
|
|
50
74
|
throw new Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
|
|
51
75
|
})();
|
|
52
76
|
},
|
|
77
|
+
generateCandles(data, candleSize) {
|
|
78
|
+
const _data = __liftString(data >>> 0) || '[]';
|
|
79
|
+
console.log("🧙♂️ 🔎 -> ~ file: index.ts:72 ~ generateCandles ~ _data", _data);
|
|
80
|
+
const _candleSize = __liftString(candleSize >>> 0) || '69m';
|
|
81
|
+
console.log("🧙♂️ 🔎 -> ~ file: index.ts:74 ~ generateCandles ~ _candleSize", _candleSize);
|
|
82
|
+
return __lowerString(JSON.stringify(generateCandles(JSON.parse(_data), _candleSize)));
|
|
83
|
+
}
|
|
53
84
|
}),
|
|
54
85
|
console: {
|
|
55
86
|
log: (msg) => {
|
|
56
|
-
console.log(msg);
|
|
87
|
+
console.log(__liftString(msg >>> 0));
|
|
57
88
|
},
|
|
58
89
|
}
|
|
59
90
|
};
|
|
@@ -184,6 +215,60 @@ function instantiate(module, imports = {}) {
|
|
|
184
215
|
return __dataview.getFloat64(pointer, true);
|
|
185
216
|
}
|
|
186
217
|
}
|
|
218
|
+
function generateCandles(data, candleSize) {
|
|
219
|
+
if (data[0] === undefined || Object.keys(data[0]).length === 0) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const series = (0, pondjs_1.timeSeries)({
|
|
223
|
+
name: 'candles',
|
|
224
|
+
columns: [...Object.keys(data[0])],
|
|
225
|
+
points: data.map((point) => {
|
|
226
|
+
return [...Object.values(point)].map(value => Number(value));
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
const windowRollup = series
|
|
230
|
+
.fixedWindowRollup({
|
|
231
|
+
window: (0, pondjs_1.window)((0, pondjs_1.duration)(candleSize)),
|
|
232
|
+
aggregation: {
|
|
233
|
+
high: ['price', (0, pondjs_1.max)()],
|
|
234
|
+
low: ['price', (0, pondjs_1.min)()],
|
|
235
|
+
close: ['price', (0, pondjs_1.last)()],
|
|
236
|
+
open: ['price', (0, pondjs_1.first)()],
|
|
237
|
+
volume: ['volume', (0, pondjs_1.sum)()],
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
.fill({
|
|
241
|
+
fieldSpec: 'value',
|
|
242
|
+
method: 2,
|
|
243
|
+
});
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
245
|
+
// @ts-ignore
|
|
246
|
+
return windowRollup
|
|
247
|
+
.toJSON()
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
.points.map((p) => {
|
|
251
|
+
// Convert time range to timestamp of beginning of range
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
p[0] = new pondjs_1.Index(p[0])
|
|
255
|
+
.toTimeRange()
|
|
256
|
+
.toTime(types_1.TimeAlignment.Begin)
|
|
257
|
+
.toDate()
|
|
258
|
+
.getTime();
|
|
259
|
+
return p;
|
|
260
|
+
})
|
|
261
|
+
.map((p) => {
|
|
262
|
+
return {
|
|
263
|
+
timestamp: p[0],
|
|
264
|
+
high: p[1],
|
|
265
|
+
low: p[2],
|
|
266
|
+
close: p[3],
|
|
267
|
+
open: p[4],
|
|
268
|
+
volume: p[5],
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
}
|
|
187
272
|
return adaptedExports;
|
|
188
273
|
});
|
|
189
274
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.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
|
}
|
package/lib/helpers/uuid.d.ts
DELETED
package/lib/helpers/uuid.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Uuid = void 0;
|
|
7
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
-
class Uuid {
|
|
9
|
-
v4(options) {
|
|
10
|
-
return node_crypto_1.default.randomUUID(options);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.Uuid = Uuid;
|
|
14
|
-
exports.default = new Uuid();
|