@steerprotocol/app-loader 0.1.6 → 0.2.2
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/Candle.d.ts +12 -0
- package/lib/Candle.js +32 -0
- package/lib/RawTradeData.d.ts +6 -0
- package/lib/RawTradeData.js +11 -0
- package/lib/index.d.ts +8 -151
- package/lib/index.js +291 -273
- package/package.json +4 -2
package/lib/Candle.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
11
|
+
export declare function encodeCandle(candle: Candle): Uint32Array;
|
|
12
|
+
export declare function decodeCandle(buffer: Uint32Array): Candle;
|
package/lib/Candle.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeCandle = exports.encodeCandle = exports.Candle = void 0;
|
|
4
|
+
class Candle {
|
|
5
|
+
constructor(timestamp, high, low, open, close, volume) {
|
|
6
|
+
this.timestamp = timestamp;
|
|
7
|
+
this.high = high;
|
|
8
|
+
this.low = low;
|
|
9
|
+
this.open = open;
|
|
10
|
+
this.close = close;
|
|
11
|
+
this.volume = volume;
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return JSON.stringify(this);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Candle = Candle;
|
|
18
|
+
function encodeCandle(candle) {
|
|
19
|
+
return new Uint32Array([
|
|
20
|
+
candle.timestamp,
|
|
21
|
+
candle.high,
|
|
22
|
+
candle.low,
|
|
23
|
+
candle.open,
|
|
24
|
+
candle.close,
|
|
25
|
+
candle.volume
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
exports.encodeCandle = encodeCandle;
|
|
29
|
+
function decodeCandle(buffer) {
|
|
30
|
+
return new Candle(buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
|
|
31
|
+
}
|
|
32
|
+
exports.decodeCandle = decodeCandle;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RawTradeData = void 0;
|
|
4
|
+
class RawTradeData {
|
|
5
|
+
constructor(timestamp, price, volume) {
|
|
6
|
+
this.timestamp = timestamp;
|
|
7
|
+
this.price = price;
|
|
8
|
+
this.volume = volume;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.RawTradeData = RawTradeData;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,162 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* assembly/index/initialize
|
|
19
|
-
* @param config `~lib/string/String`
|
|
20
|
-
*/
|
|
1
|
+
import { Candle } from './Candle';
|
|
2
|
+
import { RawTradeData } from './RawTradeData';
|
|
3
|
+
export { Candle, RawTradeData };
|
|
4
|
+
declare function responseHandler(body: ArrayBuffer, statusCode: number, redirected: number, callbackID: number): void;
|
|
21
5
|
declare function initialize(config: string): void;
|
|
22
|
-
/**
|
|
23
|
-
* assembly/index/execute
|
|
24
|
-
* @returns `~lib/string/String`
|
|
25
|
-
*/
|
|
26
|
-
declare function execute(): string;
|
|
27
|
-
/**
|
|
28
|
-
* assembly/index/execute
|
|
29
|
-
* @param param_1 `~lib/string/String`
|
|
30
|
-
* @returns `~lib/string/String`
|
|
31
|
-
*/
|
|
32
|
-
declare function execute(param_1: string): string;
|
|
33
|
-
/**
|
|
34
|
-
* assembly/index/execute
|
|
35
|
-
* @param param_1 `~lib/string/String`
|
|
36
|
-
* @param param_2 `~lib/string/String`
|
|
37
|
-
* @returns `~lib/string/String`
|
|
38
|
-
*/
|
|
39
|
-
declare function execute(param_1: string, param_2: string): string;
|
|
40
|
-
/**
|
|
41
|
-
* assembly/index/execute
|
|
42
|
-
* @param param_1 `~lib/string/String`
|
|
43
|
-
* @param param_2 `~lib/string/String`
|
|
44
|
-
* @param param_3 `~lib/string/String`
|
|
45
|
-
* @returns `~lib/string/String`
|
|
46
|
-
*/
|
|
47
|
-
declare function execute(param_1: string, param_2: string, param_3: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* assembly/index/execute
|
|
50
|
-
* @param param_1 `~lib/string/String`
|
|
51
|
-
* @param param_2 `~lib/string/String`
|
|
52
|
-
* @param param_3 `~lib/string/String`
|
|
53
|
-
* @param param_4 `~lib/string/String`
|
|
54
|
-
* @returns `~lib/string/String`
|
|
55
|
-
*/
|
|
56
|
-
declare function execute(param_1: string, param_2: string, param_3: string, param_4: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* assembly/index/execute
|
|
59
|
-
* @param param_1 `~lib/string/String`
|
|
60
|
-
* @param param_2 `~lib/string/String`
|
|
61
|
-
* @param param_3 `~lib/string/String`
|
|
62
|
-
* @param param_4 `~lib/string/String`
|
|
63
|
-
* @param param_5 `~lib/string/String`
|
|
64
|
-
* @returns `~lib/string/String`
|
|
65
|
-
*/
|
|
66
|
-
declare function execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string): string;
|
|
67
|
-
/**
|
|
68
|
-
* assembly/index/execute
|
|
69
|
-
* @param param_1 `~lib/string/String`
|
|
70
|
-
* @param param_2 `~lib/string/String`
|
|
71
|
-
* @param param_3 `~lib/string/String`
|
|
72
|
-
* @param param_4 `~lib/string/String`
|
|
73
|
-
* @param param_5 `~lib/string/String`
|
|
74
|
-
* @param param_6 `~lib/string/String`
|
|
75
|
-
* @returns `~lib/string/String`
|
|
76
|
-
*/
|
|
77
|
-
declare function execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string): string;
|
|
78
|
-
/**
|
|
79
|
-
* assembly/index/execute
|
|
80
|
-
* @param param_1 `~lib/string/String`
|
|
81
|
-
* @param param_2 `~lib/string/String`
|
|
82
|
-
* @param param_3 `~lib/string/String`
|
|
83
|
-
* @param param_4 `~lib/string/String`
|
|
84
|
-
* @param param_5 `~lib/string/String`
|
|
85
|
-
* @param param_6 `~lib/string/String`
|
|
86
|
-
* @param param_7 `~lib/string/String`
|
|
87
|
-
* @returns `~lib/string/String`
|
|
88
|
-
*/
|
|
89
|
-
declare function execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string): string;
|
|
90
|
-
/**
|
|
91
|
-
* assembly/index/execute
|
|
92
|
-
* @param param_1 `~lib/string/String`
|
|
93
|
-
* @param param_2 `~lib/string/String`
|
|
94
|
-
* @param param_3 `~lib/string/String`
|
|
95
|
-
* @param param_4 `~lib/string/String`
|
|
96
|
-
* @param param_5 `~lib/string/String`
|
|
97
|
-
* @param param_6 `~lib/string/String`
|
|
98
|
-
* @param param_7 `~lib/string/String`
|
|
99
|
-
* @param param_8 `~lib/string/String`
|
|
100
|
-
* @returns `~lib/string/String`
|
|
101
|
-
*/
|
|
102
|
-
declare function 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): string;
|
|
103
|
-
/**
|
|
104
|
-
* assembly/index/execute
|
|
105
|
-
* @param param_1 `~lib/string/String`
|
|
106
|
-
* @param param_2 `~lib/string/String`
|
|
107
|
-
* @param param_3 `~lib/string/String`
|
|
108
|
-
* @param param_4 `~lib/string/String`
|
|
109
|
-
* @param param_5 `~lib/string/String`
|
|
110
|
-
* @param param_6 `~lib/string/String`
|
|
111
|
-
* @param param_7 `~lib/string/String`
|
|
112
|
-
* @param param_8 `~lib/string/String`
|
|
113
|
-
* @param param_9 `~lib/string/String`
|
|
114
|
-
* @returns `~lib/string/String`
|
|
115
|
-
*/
|
|
116
|
-
declare function 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): string;
|
|
117
|
-
/**
|
|
118
|
-
* assembly/index/execute
|
|
119
|
-
* @param param_1 `~lib/string/String`
|
|
120
|
-
* @param param_2 `~lib/string/String`
|
|
121
|
-
* @param param_3 `~lib/string/String`
|
|
122
|
-
* @param param_4 `~lib/string/String`
|
|
123
|
-
* @param param_5 `~lib/string/String`
|
|
124
|
-
* @param param_6 `~lib/string/String`
|
|
125
|
-
* @param param_7 `~lib/string/String`
|
|
126
|
-
* @param param_8 `~lib/string/String`
|
|
127
|
-
* @param param_9 `~lib/string/String`
|
|
128
|
-
* @param param_10 `~lib/string/String`
|
|
129
|
-
* @returns `~lib/string/String`
|
|
130
|
-
*/
|
|
131
|
-
declare function 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): string;
|
|
132
|
-
/**
|
|
133
|
-
* assembly/index/config
|
|
134
|
-
* @returns `~lib/string/String`
|
|
135
|
-
*/
|
|
136
6
|
declare function config(): string;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*/
|
|
141
|
-
declare function version(): number;
|
|
142
|
-
export declare function transform(): string;
|
|
7
|
+
declare function version(): string;
|
|
8
|
+
declare function transform(): string;
|
|
9
|
+
declare function execute(...params: string[]): string;
|
|
143
10
|
export type WasmModule = {
|
|
11
|
+
responseHandler: typeof responseHandler;
|
|
144
12
|
initialize: typeof initialize;
|
|
145
13
|
execute: typeof execute;
|
|
146
|
-
"execute(param_1: string)": typeof execute;
|
|
147
|
-
"execute(param_1: string, param_2: string)": typeof execute;
|
|
148
|
-
"execute(param_1: string, param_2: string, param_3: string)": typeof execute;
|
|
149
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string)": typeof execute;
|
|
150
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string)": typeof execute;
|
|
151
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string)": typeof execute;
|
|
152
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string)": typeof execute;
|
|
153
|
-
"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;
|
|
154
|
-
"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;
|
|
155
|
-
"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;
|
|
156
14
|
config: typeof config;
|
|
157
15
|
version: typeof version;
|
|
158
16
|
transform: typeof transform;
|
|
159
17
|
memory: WebAssembly.Memory;
|
|
160
18
|
};
|
|
161
19
|
export declare const loadWasm: (input: string | ArrayBuffer, imports?: {}) => Promise<WasmModule>;
|
|
162
|
-
export {};
|
package/lib/index.js
CHANGED
|
@@ -31,181 +31,248 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.loadWasm = exports.
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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;
|
|
38
|
+
exports.loadWasm = exports.RawTradeData = exports.Candle = void 0;
|
|
39
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
40
|
+
const ccxt_1 = __importDefault(require("ccxt"));
|
|
41
|
+
const timestring_1 = __importDefault(require("timestring"));
|
|
42
|
+
const Candle_1 = require("./Candle");
|
|
43
|
+
Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
|
|
44
|
+
const RawTradeData_1 = require("./RawTradeData");
|
|
45
|
+
Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
|
|
46
|
+
let _fetchGETSyncPtr = 0;
|
|
47
|
+
let _fetchPOSTSyncPtr = 0;
|
|
48
|
+
let _ohlcvPtr = 0;
|
|
49
|
+
let ASYNCIFY_PTR = 0;
|
|
50
|
+
let ASYNCIFY_MEM;
|
|
51
|
+
let _exports;
|
|
60
52
|
function instantiate(module, imports = {}) {
|
|
61
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
54
|
const adaptedImports = {
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
64
55
|
// @ts-ignore
|
|
65
56
|
env: Object.assign(Object.create(globalThis), imports.env || {}, {
|
|
57
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
58
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
59
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
60
|
+
// I don't know if I need to reserve all this memory...
|
|
61
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
62
|
+
},
|
|
66
63
|
abort(message, fileName, lineNumber, columnNumber) {
|
|
67
|
-
// ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
|
|
68
|
-
message = __liftString(message >>> 0);
|
|
69
|
-
fileName = __liftString(fileName >>> 0);
|
|
70
|
-
lineNumber >>>= 0;
|
|
71
|
-
columnNumber >>>= 0;
|
|
72
64
|
(() => {
|
|
73
|
-
|
|
74
|
-
throw new Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
|
|
65
|
+
throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);
|
|
75
66
|
})();
|
|
76
67
|
},
|
|
77
68
|
generateCandles(data, candleSize) {
|
|
78
|
-
const _data = __liftString(data
|
|
79
|
-
const _candleSize = __liftString(candleSize
|
|
80
|
-
|
|
69
|
+
const _data = __liftString(data) || '[]';
|
|
70
|
+
const _candleSize = __liftString(candleSize) || '69m';
|
|
71
|
+
const candles = generateCandles(JSON.parse(_data), _candleSize);
|
|
72
|
+
// We could pack this data into binary before sending...
|
|
73
|
+
// Much faster
|
|
74
|
+
// Which are 32 bit and which are 64?
|
|
75
|
+
// I'll assume 32 bits for now though I believe timestamp should be 64
|
|
76
|
+
/*
|
|
77
|
+
const decodedCandles: Candle[] = [];
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < __liftBuffer(data).byteLength >> 2; i++) {
|
|
80
|
+
decodedCandles.push(decodeCandle(new Uint32Array(data, i * 6, 6)));
|
|
81
|
+
}
|
|
82
|
+
const candles =
|
|
83
|
+
|
|
84
|
+
let buffer = new Uint32Array(candles.length * 6);
|
|
85
|
+
for (let i = 0; i < candles.length; i++) {
|
|
86
|
+
const candle = candles[i];
|
|
87
|
+
// Pack it into
|
|
88
|
+
|
|
89
|
+
// Structure: [timestamp, high, low, open, close, volume]
|
|
90
|
+
// Stride: 24 bytes
|
|
91
|
+
// This is essentially what FASS does
|
|
92
|
+
|
|
93
|
+
buffer.set(
|
|
94
|
+
encodeCandle(candle),
|
|
95
|
+
i
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return __lowerBuffer(buffer);*/
|
|
99
|
+
return __lowerString(JSON.stringify(candles));
|
|
100
|
+
},
|
|
101
|
+
'console.log': (text) => {
|
|
102
|
+
console.log(__liftString(text));
|
|
103
|
+
},
|
|
104
|
+
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
const currentState = _exports.asyncify_get_state();
|
|
107
|
+
if (currentState === 2) {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
_exports.asyncify_stop_rewind();
|
|
110
|
+
return _ohlcvPtr;
|
|
111
|
+
}
|
|
112
|
+
else if (currentState === 0) {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
_exports.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
115
|
+
const _exchangeId = __liftString(exchangeId);
|
|
116
|
+
const _symbol = __liftString(symbol);
|
|
117
|
+
const _timeframe = __liftString(timeframe);
|
|
118
|
+
const _since = since;
|
|
119
|
+
const _limit = limit;
|
|
120
|
+
if (_exchangeId &&
|
|
121
|
+
_symbol &&
|
|
122
|
+
_timeframe &&
|
|
123
|
+
_since &&
|
|
124
|
+
_limit) {
|
|
125
|
+
try {
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
_exports.asyncify_stop_unwind();
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
new ccxt_1.default[exchangeId]({
|
|
130
|
+
apiKey: "",
|
|
131
|
+
secret: ""
|
|
132
|
+
}).fetchOHLCV(_symbol, _timeframe, _limit, _since).then((data) => {
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
_exports.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
135
|
+
_ohlcvPtr = __lowerString(JSON.stringify(data));
|
|
136
|
+
_exports.execute();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
_exports.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
142
|
+
process.env.DEBUG && console.error(e);
|
|
143
|
+
_exports.execute();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
81
147
|
}
|
|
82
148
|
}),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
149
|
+
'as-fetch': {
|
|
150
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
151
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
152
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
153
|
+
// I don't know if I need to reserve all this memory...
|
|
154
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
86
155
|
},
|
|
87
|
-
|
|
156
|
+
_fetchPOSTSync(url, mode, headers, body) {
|
|
157
|
+
var _a;
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
const currentState = _exports.asyncify_get_state();
|
|
160
|
+
if (currentState === 2) {
|
|
161
|
+
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
162
|
+
// @ts-ignore
|
|
163
|
+
_exports.asyncify_stop_rewind();
|
|
164
|
+
return _fetchPOSTSyncPtr;
|
|
165
|
+
}
|
|
166
|
+
else if (currentState === 0) {
|
|
167
|
+
//console.log("asyncify_start_unwind() [pause wasm]");
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
_exports.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
170
|
+
fetch((_a = __liftString(url)) !== null && _a !== void 0 ? _a : '', {
|
|
171
|
+
method: "POST",
|
|
172
|
+
mode: modeToString(mode) || "cors",
|
|
173
|
+
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
174
|
+
body: __liftBuffer(body)
|
|
175
|
+
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
//console.log("asyncify_stop_unwind() [unpause wasm]");
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
_exports.asyncify_stop_unwind();
|
|
179
|
+
const value = yield res.arrayBuffer();
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
_fetchPOSTSyncPtr = _exports.__new(value.byteLength, 1);
|
|
182
|
+
new Uint8Array(_exports.memory.buffer).set(new Uint8Array(value), _fetchPOSTSyncPtr);
|
|
183
|
+
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
_exports.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
// Set to your execute function that your fetch calls are in. I would go and create a _start func
|
|
188
|
+
_exports.execute();
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
_fetchGETSync(url, mode, headers) {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
const currentState = _exports.asyncify_get_state();
|
|
195
|
+
if (currentState === 2) {
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
//console.log("asyncify_stop_rewind() [resume wasm]");
|
|
198
|
+
_exports.asyncify_stop_rewind();
|
|
199
|
+
return _fetchGETSyncPtr;
|
|
200
|
+
}
|
|
201
|
+
else if (currentState === 0) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
//console.log("asyncify_start_unwind() [pause wasm]");
|
|
204
|
+
_exports.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
205
|
+
fetch(__liftString(url) || "", {
|
|
206
|
+
method: "GET",
|
|
207
|
+
mode: modeToString(mode) || "cors",
|
|
208
|
+
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || []
|
|
209
|
+
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
//console.log("asyncify_stop_unwind() [unpause wasm]");
|
|
212
|
+
_exports.asyncify_stop_unwind();
|
|
213
|
+
const value = yield res.arrayBuffer();
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
_fetchGETSyncPtr = _exports.__new(value.byteLength, 1);
|
|
216
|
+
new Uint8Array(_exports.memory.buffer).set(new Uint8Array(value), _fetchGETSyncPtr);
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
//console.log("asyncify_start_rewind() [resuming wasm]");
|
|
219
|
+
_exports.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
_exports.execute();
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
_fetchGET(url, mode, headers, callbackID) {
|
|
226
|
+
fetch(__liftString(url) || "", {
|
|
227
|
+
method: "GET",
|
|
228
|
+
mode: modeToString(mode) || "cors",
|
|
229
|
+
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || []
|
|
230
|
+
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const body = yield res.arrayBuffer();
|
|
232
|
+
_exports.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
|
|
233
|
+
}));
|
|
234
|
+
},
|
|
235
|
+
_fetchPOST(url, mode, headers, body, callbackID) {
|
|
236
|
+
fetch(__liftString(url) || "", {
|
|
237
|
+
method: "POST",
|
|
238
|
+
mode: modeToString(mode) || "cors",
|
|
239
|
+
body: body,
|
|
240
|
+
headers: __liftArray((pointer) => __liftArray((pointer) => __liftString(__getU32(pointer)), 2, __getU32(pointer)), 2, headers) || [],
|
|
241
|
+
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
const body = yield res.arrayBuffer();
|
|
243
|
+
_exports.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
88
247
|
};
|
|
89
|
-
|
|
90
|
-
// @ts-ignore
|
|
248
|
+
//@ts-ignore
|
|
91
249
|
const { exports } = yield WebAssembly.instantiate(module, adaptedImports);
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
93
250
|
// @ts-ignore
|
|
94
251
|
const memory = exports.memory || imports.env.memory;
|
|
252
|
+
_exports = exports;
|
|
253
|
+
ASYNCIFY_MEM = new Uint32Array(memory.buffer);
|
|
95
254
|
const adaptedExports = Object.setPrototypeOf({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
"execute()": () => {
|
|
102
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
103
|
-
// const _pricesPointer = __lowerString(_prices) || __notnull()
|
|
104
|
-
return __liftString(exports.execute() >>> 0);
|
|
105
|
-
},
|
|
106
|
-
"execute(param_1: string)": (param_1) => {
|
|
107
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
108
|
-
const _paramPointer = __lowerString(param_1) || __notnull();
|
|
109
|
-
return __liftString(exports.execute(_paramPointer) >>> 0);
|
|
110
|
-
},
|
|
111
|
-
"execute(param_1: string, param_2: string)": (param_1, param_2) => {
|
|
112
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
113
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
114
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
115
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2) >>> 0);
|
|
116
|
-
},
|
|
117
|
-
"execute(param_1: string, param_2: string, param_3: string)": (param_1, param_2, param_3) => {
|
|
118
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
119
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
120
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
121
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
122
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3) >>> 0);
|
|
123
|
-
},
|
|
124
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string)": (param_1, param_2, param_3, param_4) => {
|
|
125
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
126
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
127
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
128
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
129
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
130
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4) >>> 0);
|
|
131
|
-
},
|
|
132
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string)": (param_1, param_2, param_3, param_4, param_5) => {
|
|
133
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
134
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
135
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
136
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
137
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
138
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
139
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5) >>> 0);
|
|
140
|
-
},
|
|
141
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string)": (param_1, param_2, param_3, param_4, param_5, param_6) => {
|
|
142
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
143
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
144
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
145
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
146
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
147
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
148
|
-
const _paramPointer6 = __lowerString(param_6) || __notnull();
|
|
149
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5, _paramPointer6) >>> 0);
|
|
150
|
-
},
|
|
151
|
-
"execute(param_1: string, param_2: string, param_3: string, param_4: string, param_5: string, param_6: string, param_7: string)": (param_1, param_2, param_3, param_4, param_5, param_6, param_7) => {
|
|
152
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
153
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
154
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
155
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
156
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
157
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
158
|
-
const _paramPointer6 = __lowerString(param_6) || __notnull();
|
|
159
|
-
const _paramPointer7 = __lowerString(param_7) || __notnull();
|
|
160
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5, _paramPointer6, _paramPointer7) >>> 0);
|
|
161
|
-
},
|
|
162
|
-
"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_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8) => {
|
|
163
|
-
// assembly/index/execute(~lib/string/String) => ~lib/string/String
|
|
164
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
165
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
166
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
167
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
168
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
169
|
-
const _paramPointer6 = __lowerString(param_6) || __notnull();
|
|
170
|
-
const _paramPointer7 = __lowerString(param_7) || __notnull();
|
|
171
|
-
const _paramPointer8 = __lowerString(param_8) || __notnull();
|
|
172
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5, _paramPointer6, _paramPointer7, _paramPointer8) >>> 0);
|
|
255
|
+
responseHandler(body, statusCode, redirected, callbackID) {
|
|
256
|
+
if (exports['responseHandler']) {
|
|
257
|
+
exports.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
258
|
+
}
|
|
173
259
|
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const _paramPointer1 = __lowerString(param_1) || __notnull();
|
|
177
|
-
const _paramPointer2 = __lowerString(param_2) || __notnull();
|
|
178
|
-
const _paramPointer3 = __lowerString(param_3) || __notnull();
|
|
179
|
-
const _paramPointer4 = __lowerString(param_4) || __notnull();
|
|
180
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
181
|
-
const _paramPointer6 = __lowerString(param_6) || __notnull();
|
|
182
|
-
const _paramPointer7 = __lowerString(param_7) || __notnull();
|
|
183
|
-
const _paramPointer8 = __lowerString(param_8) || __notnull();
|
|
184
|
-
const _paramPointer9 = __lowerString(param_9) || __notnull();
|
|
185
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5, _paramPointer6, _paramPointer7, _paramPointer8, _paramPointer9) >>> 0);
|
|
260
|
+
initialize(config) {
|
|
261
|
+
exports.initialize(__lowerString(config));
|
|
186
262
|
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const _paramPointer5 = __lowerString(param_5) || __notnull();
|
|
194
|
-
const _paramPointer6 = __lowerString(param_6) || __notnull();
|
|
195
|
-
const _paramPointer7 = __lowerString(param_7) || __notnull();
|
|
196
|
-
const _paramPointer8 = __lowerString(param_8) || __notnull();
|
|
197
|
-
const _paramPointer9 = __lowerString(param_9) || __notnull();
|
|
198
|
-
const _paramPointer10 = __lowerString(param_10) || __notnull();
|
|
199
|
-
return __liftString(exports.execute(_paramPointer1, _paramPointer2, _paramPointer3, _paramPointer4, _paramPointer5, _paramPointer6, _paramPointer7, _paramPointer8, _paramPointer9, _paramPointer10) >>> 0);
|
|
263
|
+
execute(...params) {
|
|
264
|
+
const loweredArgs = new Array(params.length);
|
|
265
|
+
for (let i = 0; i < params.length; i++) {
|
|
266
|
+
loweredArgs[i] = __lowerString(params[i]);
|
|
267
|
+
}
|
|
268
|
+
return __liftString(exports.execute(...loweredArgs));
|
|
200
269
|
},
|
|
201
270
|
config() {
|
|
202
|
-
|
|
203
|
-
return __liftString(exports.config() >>> 0);
|
|
271
|
+
return __liftString(exports.config());
|
|
204
272
|
},
|
|
205
273
|
transform() {
|
|
206
274
|
try {
|
|
207
|
-
|
|
208
|
-
return __liftString(exports.transform() >>> 0);
|
|
275
|
+
return __liftString(exports.transform());
|
|
209
276
|
}
|
|
210
277
|
catch (e) {
|
|
211
278
|
console.error(e);
|
|
@@ -213,22 +280,34 @@ function instantiate(module, imports = {}) {
|
|
|
213
280
|
}
|
|
214
281
|
},
|
|
215
282
|
}, exports);
|
|
283
|
+
function __liftBuffer(pointer) {
|
|
284
|
+
if (!pointer)
|
|
285
|
+
return null;
|
|
286
|
+
return memory.buffer.slice(pointer, pointer + new Uint32Array(memory.buffer)[(pointer - 4) >>> 2]);
|
|
287
|
+
}
|
|
288
|
+
function __lowerBuffer(value) {
|
|
289
|
+
if (value == null)
|
|
290
|
+
return 0;
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
const pointer = exports.__new(value.byteLength, 1);
|
|
293
|
+
new Uint8Array(memory.buffer).set(new Uint8Array(value), pointer);
|
|
294
|
+
return pointer;
|
|
295
|
+
}
|
|
216
296
|
function __liftString(pointer) {
|
|
217
297
|
if (!pointer)
|
|
218
298
|
return null;
|
|
219
|
-
const end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1;
|
|
220
|
-
|
|
221
|
-
let start = pointer >>> 1;
|
|
222
|
-
let string = '';
|
|
299
|
+
const end = (pointer + new Uint32Array(memory.buffer)[(pointer - 4) >>> 2]) >>> 1, memoryU16 = new Uint16Array(memory.buffer);
|
|
300
|
+
let start = pointer >>> 1, string = '';
|
|
223
301
|
while (end - start > 1024)
|
|
224
|
-
string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
|
|
302
|
+
string += String.fromCharCode(...memoryU16.subarray(start, (start += 1024)));
|
|
225
303
|
return string + String.fromCharCode(...memoryU16.subarray(start, end));
|
|
226
304
|
}
|
|
227
305
|
function __lowerString(value) {
|
|
228
306
|
if (value === null)
|
|
229
307
|
return 0;
|
|
230
308
|
const length = value.length;
|
|
231
|
-
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
const pointer = exports.__new(length << 1, 2);
|
|
232
311
|
const memoryU16 = new Uint16Array(memory.buffer);
|
|
233
312
|
for (let i = 0; i < length; ++i)
|
|
234
313
|
memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
|
|
@@ -237,51 +316,12 @@ function instantiate(module, imports = {}) {
|
|
|
237
316
|
function __liftArray(liftElement, align, pointer) {
|
|
238
317
|
if (!pointer)
|
|
239
318
|
return null;
|
|
240
|
-
const dataStart = __getU32(pointer + 4);
|
|
241
|
-
const length = __dataview.getUint32(pointer + 12, true);
|
|
242
|
-
const values = new Array(length);
|
|
319
|
+
const dataStart = __getU32(pointer + 4), length = __dataview.getUint32(pointer + 12, true), values = new Array(length);
|
|
243
320
|
for (let i = 0; i < length; ++i)
|
|
244
|
-
values[i] = liftElement(dataStart + (i << align
|
|
321
|
+
values[i] = liftElement(dataStart + (i << align));
|
|
245
322
|
return values;
|
|
246
323
|
}
|
|
247
|
-
function __lowerArray(lowerElement, id, align, values) {
|
|
248
|
-
if (values === null)
|
|
249
|
-
return 0;
|
|
250
|
-
const length = values.length;
|
|
251
|
-
const buffer = exports.__pin(exports.__new(length << align, 1)) >>> 0;
|
|
252
|
-
const header = exports.__pin(exports.__new(16, id)) >>> 0;
|
|
253
|
-
__setU32(header + 0, buffer);
|
|
254
|
-
__dataview.setUint32(header + 4, buffer, true);
|
|
255
|
-
__dataview.setUint32(header + 8, length << align, true);
|
|
256
|
-
__dataview.setUint32(header + 12, length, true);
|
|
257
|
-
for (let i = 0; i < length; ++i)
|
|
258
|
-
lowerElement(buffer + (i << align >>> 0), values[i]);
|
|
259
|
-
exports.__unpin(buffer);
|
|
260
|
-
exports.__unpin(header);
|
|
261
|
-
return header;
|
|
262
|
-
}
|
|
263
|
-
class Internref extends Number {
|
|
264
|
-
}
|
|
265
|
-
function __lowerInternref(value) {
|
|
266
|
-
if (value === null)
|
|
267
|
-
return 0;
|
|
268
|
-
if (value instanceof Internref)
|
|
269
|
-
return value.valueOf();
|
|
270
|
-
throw new TypeError('internref expected');
|
|
271
|
-
}
|
|
272
|
-
function __notnull() {
|
|
273
|
-
throw new TypeError('value must not be null');
|
|
274
|
-
}
|
|
275
324
|
let __dataview = new DataView(memory.buffer);
|
|
276
|
-
function __setU32(pointer, value) {
|
|
277
|
-
try {
|
|
278
|
-
__dataview.setUint32(pointer, value, true);
|
|
279
|
-
}
|
|
280
|
-
catch (_a) {
|
|
281
|
-
__dataview = new DataView(memory.buffer);
|
|
282
|
-
__dataview.setUint32(pointer, value, true);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
325
|
function __getU32(pointer) {
|
|
286
326
|
try {
|
|
287
327
|
return __dataview.getUint32(pointer, true);
|
|
@@ -291,94 +331,60 @@ function instantiate(module, imports = {}) {
|
|
|
291
331
|
return __dataview.getUint32(pointer, true);
|
|
292
332
|
}
|
|
293
333
|
}
|
|
294
|
-
function __getF32(pointer) {
|
|
295
|
-
try {
|
|
296
|
-
return __dataview.getFloat32(pointer, true);
|
|
297
|
-
}
|
|
298
|
-
catch (_a) {
|
|
299
|
-
__dataview = new DataView(memory.buffer);
|
|
300
|
-
return __dataview.getFloat32(pointer, true);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function __getF64(pointer) {
|
|
304
|
-
try {
|
|
305
|
-
return __dataview.getFloat64(pointer, true);
|
|
306
|
-
}
|
|
307
|
-
catch (_a) {
|
|
308
|
-
__dataview = new DataView(memory.buffer);
|
|
309
|
-
return __dataview.getFloat64(pointer, true);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
334
|
function generateCandles(data, candleSize) {
|
|
335
|
+
const candleWidth = (0, timestring_1.default)(candleSize, 'ms', {});
|
|
336
|
+
if (data.length === 0) {
|
|
337
|
+
throw new Error('Input data is empty');
|
|
338
|
+
}
|
|
313
339
|
const _data = data.map((point) => {
|
|
314
|
-
return Object.assign(Object.assign({}, point), {
|
|
340
|
+
return Object.assign(Object.assign({}, point), {
|
|
315
341
|
// This will convert the timestamp to milliseconds if it's in seconds
|
|
316
|
-
timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1000 : point.timestamp
|
|
342
|
+
timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1000 : point.timestamp,
|
|
343
|
+
});
|
|
317
344
|
});
|
|
318
345
|
if (_data[0] === undefined || Object.keys(_data[0]).length === 0) {
|
|
319
346
|
return [];
|
|
320
347
|
}
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
.points.map((p) => {
|
|
356
|
-
// Convert time range to timestamp of beginning of range
|
|
357
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
358
|
-
// @ts-ignore
|
|
359
|
-
p[0] = new pondjs_1.Index(p[0])
|
|
360
|
-
.toTimeRange()
|
|
361
|
-
.toTime(types_1.TimeAlignment.Begin)
|
|
362
|
-
.toDate()
|
|
363
|
-
.getTime();
|
|
364
|
-
return p;
|
|
365
|
-
})
|
|
366
|
-
.map((p) => {
|
|
367
|
-
return {
|
|
368
|
-
timestamp: p[0],
|
|
369
|
-
high: p[1],
|
|
370
|
-
low: p[2],
|
|
371
|
-
close: p[3],
|
|
372
|
-
open: p[4],
|
|
373
|
-
volume: p[5],
|
|
374
|
-
};
|
|
375
|
-
});
|
|
348
|
+
const ohlcvData = [];
|
|
349
|
+
let i = 0;
|
|
350
|
+
let currentTimestamp = Math.floor(_data[0].timestamp / candleWidth) * candleWidth;
|
|
351
|
+
let open = _data[0].price;
|
|
352
|
+
let high = _data[0].price;
|
|
353
|
+
let low = _data[0].price;
|
|
354
|
+
let close = _data[0].price;
|
|
355
|
+
let volume = 0.0;
|
|
356
|
+
while (i < _data.length) {
|
|
357
|
+
open = close;
|
|
358
|
+
high = close;
|
|
359
|
+
low = close;
|
|
360
|
+
volume = 0.0;
|
|
361
|
+
let innerI = i;
|
|
362
|
+
while (innerI < _data.length && _data[innerI].timestamp < currentTimestamp + candleWidth) {
|
|
363
|
+
open = innerI === 0 ? _data[innerI].price : open;
|
|
364
|
+
high = Math.max(high, _data[innerI].price);
|
|
365
|
+
low = Math.min(low, _data[innerI].price);
|
|
366
|
+
close = _data[innerI].price;
|
|
367
|
+
volume += _data[innerI].volume;
|
|
368
|
+
innerI++;
|
|
369
|
+
}
|
|
370
|
+
ohlcvData.push({
|
|
371
|
+
timestamp: currentTimestamp,
|
|
372
|
+
high,
|
|
373
|
+
low,
|
|
374
|
+
open,
|
|
375
|
+
close,
|
|
376
|
+
volume,
|
|
377
|
+
});
|
|
378
|
+
currentTimestamp += candleWidth;
|
|
379
|
+
i = innerI;
|
|
380
|
+
}
|
|
381
|
+
return ohlcvData;
|
|
376
382
|
}
|
|
377
383
|
return adaptedExports;
|
|
378
384
|
});
|
|
379
385
|
}
|
|
380
386
|
const loadWasm = (input, imports = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
381
|
-
|
|
387
|
+
const mod = (yield instantiate(yield (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
382
388
|
if (typeof input === 'string') {
|
|
383
389
|
try {
|
|
384
390
|
return yield globalThis.WebAssembly.compileStreaming(globalThis.fetch(input));
|
|
@@ -390,6 +396,18 @@ const loadWasm = (input, imports = {}) => __awaiter(void 0, void 0, void 0, func
|
|
|
390
396
|
else {
|
|
391
397
|
return globalThis.WebAssembly.compile(input);
|
|
392
398
|
}
|
|
393
|
-
}))(), imports);
|
|
399
|
+
}))(), imports));
|
|
400
|
+
return mod;
|
|
394
401
|
});
|
|
395
402
|
exports.loadWasm = loadWasm;
|
|
403
|
+
function modeToString(mode) {
|
|
404
|
+
if (mode == 1)
|
|
405
|
+
return 'cors';
|
|
406
|
+
if (mode == 2)
|
|
407
|
+
return 'no-cors';
|
|
408
|
+
if (mode == 3)
|
|
409
|
+
return 'same-origin';
|
|
410
|
+
if (mode == 4)
|
|
411
|
+
return 'navigate';
|
|
412
|
+
return null;
|
|
413
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"homepage": "https://github.com/hebertcisco/ts-npm-package-boilerplate#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "29.2.4",
|
|
35
|
+
"@types/timestring": "^6.0.2",
|
|
35
36
|
"@typescript-eslint/eslint-plugin": "5.46.0",
|
|
36
37
|
"@typescript-eslint/parser": "5.47.1",
|
|
37
38
|
"eslint": "8.30.0",
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"lib/**/*"
|
|
46
47
|
],
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"
|
|
49
|
+
"ccxt": "^3.0.30",
|
|
50
|
+
"timestring": "^7.0.0"
|
|
49
51
|
}
|
|
50
52
|
}
|