@steerprotocol/app-loader 0.0.7 → 0.0.9

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 CHANGED
@@ -1,3 +1,9 @@
1
+ export declare class RawTradeData {
2
+ timestamp: number;
3
+ price: number;
4
+ volume: number;
5
+ constructor(timestamp: number, price: number, volume: number);
6
+ }
1
7
  export declare class Candle {
2
8
  timestamp: number;
3
9
  high: number;
@@ -38,9 +44,5 @@ export type WasmModule = {
38
44
  transform: typeof transform;
39
45
  memory: WebAssembly.Memory;
40
46
  };
41
- export type TickData = {
42
- index: number;
43
- value: string;
44
- };
45
47
  export declare const loadWasm: (input: string | ArrayBuffer, imports?: {}) => Promise<WasmModule>;
46
48
  export {};
package/lib/index.js CHANGED
@@ -32,9 +32,17 @@ 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 = exports.Candle = void 0;
35
+ exports.loadWasm = exports.Candle = exports.RawTradeData = void 0;
36
36
  const pondjs_1 = require("pondjs");
37
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;
38
46
  class Candle {
39
47
  constructor(timestamp, high, low, open, close, volume) {
40
48
  this.timestamp = timestamp;
@@ -208,13 +216,18 @@ function instantiate(module, imports = {}) {
208
216
  }
209
217
  }
210
218
  function generateCandles(data, candleSize) {
211
- if (data[0] === undefined || Object.keys(data[0]).length === 0) {
219
+ const _data = data.map((point) => {
220
+ return Object.assign(Object.assign({}, point), {
221
+ // This will convert the timestamp to milliseconds if it's in seconds
222
+ timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1000 : point.timestamp });
223
+ });
224
+ if (_data[0] === undefined || Object.keys(_data[0]).length === 0) {
212
225
  return [];
213
226
  }
214
227
  const series = (0, pondjs_1.timeSeries)({
215
- name: 'swaps',
216
- columns: [...Object.keys(data[0])],
217
- points: data.map((point) => {
228
+ name: 'candles',
229
+ columns: [...Object.keys(_data[0])],
230
+ points: _data.map((point) => {
218
231
  return [...Object.values(point)].map(value => Number(value));
219
232
  }),
220
233
  });
@@ -222,15 +235,22 @@ function instantiate(module, imports = {}) {
222
235
  .fixedWindowRollup({
223
236
  window: (0, pondjs_1.window)((0, pondjs_1.duration)(candleSize)),
224
237
  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)()],
238
+ high: ['price', (0, pondjs_1.max)()],
239
+ low: ['price', (0, pondjs_1.min)()],
240
+ close: ['price', (0, pondjs_1.last)()],
241
+ open: ['price', (0, pondjs_1.first)()],
242
+ volume: ['volume', (values) => {
243
+ const cleanValues = pondjs_1.filter.ignoreMissing(values);
244
+ if (!cleanValues) {
245
+ return 0;
246
+ }
247
+ return cleanValues.reduce((a, b) => Math.abs(a) + Math.abs(b), 0);
248
+ }],
229
249
  },
230
250
  })
231
251
  .fill({
232
- fieldSpec: 'value',
233
- method: 2,
252
+ fieldSpec: 'price',
253
+ method: types_1.FillMethod.Pad,
234
254
  });
235
255
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
236
256
  // @ts-ignore
@@ -256,6 +276,7 @@ function instantiate(module, imports = {}) {
256
276
  low: p[2],
257
277
  close: p[3],
258
278
  open: p[4],
279
+ volume: p[5],
259
280
  };
260
281
  });
261
282
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@steerprotocol/app-loader",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
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 --build tsconfig.json",
8
+ "build": "tsc",
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",
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- import crypto from 'node:crypto';
3
- export declare class Uuid {
4
- v4(options?: crypto.RandomUUIDOptions | undefined): string;
5
- }
6
- declare const _default: Uuid;
7
- export default _default;
@@ -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();