@steerprotocol/app-loader 0.0.8 → 0.1.0

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.
Files changed (2) hide show
  1. package/lib/index.js +18 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -76,9 +76,7 @@ function instantiate(module, imports = {}) {
76
76
  },
77
77
  generateCandles(data, candleSize) {
78
78
  const _data = __liftString(data >>> 0) || '[]';
79
- console.log("🧙‍♂️ 🔎 -> ~ file: index.ts:72 ~ generateCandles ~ _data", _data);
80
79
  const _candleSize = __liftString(candleSize >>> 0) || '69m';
81
- console.log("🧙‍♂️ 🔎 -> ~ file: index.ts:74 ~ generateCandles ~ _candleSize", _candleSize);
82
80
  return __lowerString(JSON.stringify(generateCandles(JSON.parse(_data), _candleSize)));
83
81
  }
84
82
  }),
@@ -115,6 +113,7 @@ function instantiate(module, imports = {}) {
115
113
  return __liftString(exports.transform() >>> 0);
116
114
  }
117
115
  catch (e) {
116
+ console.error(e);
118
117
  throw new Error('Unable to call .transform on wasm module. Are you sure this is a data connector?');
119
118
  }
120
119
  },
@@ -216,13 +215,18 @@ function instantiate(module, imports = {}) {
216
215
  }
217
216
  }
218
217
  function generateCandles(data, candleSize) {
219
- if (data[0] === undefined || Object.keys(data[0]).length === 0) {
218
+ const _data = data.map((point) => {
219
+ return Object.assign(Object.assign({}, point), {
220
+ // This will convert the timestamp to milliseconds if it's in seconds
221
+ timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1000 : point.timestamp });
222
+ });
223
+ if (_data[0] === undefined || Object.keys(_data[0]).length === 0) {
220
224
  return [];
221
225
  }
222
226
  const series = (0, pondjs_1.timeSeries)({
223
227
  name: 'candles',
224
- columns: [...Object.keys(data[0])],
225
- points: data.map((point) => {
228
+ columns: [...Object.keys(_data[0])],
229
+ points: _data.map((point) => {
226
230
  return [...Object.values(point)].map(value => Number(value));
227
231
  }),
228
232
  });
@@ -234,12 +238,18 @@ function instantiate(module, imports = {}) {
234
238
  low: ['price', (0, pondjs_1.min)()],
235
239
  close: ['price', (0, pondjs_1.last)()],
236
240
  open: ['price', (0, pondjs_1.first)()],
237
- volume: ['volume', (0, pondjs_1.sum)()],
241
+ volume: ['volume', (values) => {
242
+ const cleanValues = pondjs_1.filter.ignoreMissing(values);
243
+ if (!cleanValues) {
244
+ return 0;
245
+ }
246
+ return cleanValues.reduce((a, b) => Math.abs(a) + Math.abs(b), 0);
247
+ }],
238
248
  },
239
249
  })
240
250
  .fill({
241
- fieldSpec: 'value',
242
- method: 2,
251
+ fieldSpec: 'price',
252
+ method: types_1.FillMethod.Pad,
243
253
  });
244
254
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
245
255
  // @ts-ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerprotocol/app-loader",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",