@steerprotocol/strategy-utils 0.0.1 → 0.0.5
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.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { JSON } from "assemblyscript-json";
|
|
2
|
+
|
|
3
|
+
export class Price {
|
|
4
|
+
constructor(
|
|
5
|
+
public high: f32,
|
|
6
|
+
public low: f32,
|
|
7
|
+
public open: f32,
|
|
8
|
+
public close: f32
|
|
9
|
+
) {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function parsePrices(_prices: String): Array<Price> {
|
|
13
|
+
const prices = _prices;
|
|
14
|
+
// Parse an object using the JSON object
|
|
15
|
+
let jsonObj: JSON.Obj = <JSON.Obj>JSON.parse(prices);
|
|
16
|
+
const result: Array<Price> = [];
|
|
17
|
+
|
|
18
|
+
const val = jsonObj.getValue("data");
|
|
19
|
+
if (val != null) {
|
|
20
|
+
if (val.isArr) {
|
|
21
|
+
const pricesArray = (<JSON.Arr>val).valueOf();
|
|
22
|
+
|
|
23
|
+
for (let priceIndex = 0; priceIndex < prices.length; priceIndex++) {
|
|
24
|
+
const price = pricesArray[priceIndex];
|
|
25
|
+
|
|
26
|
+
const candle = <JSON.Obj>JSON.parse(price.toString());
|
|
27
|
+
|
|
28
|
+
if (candle) {
|
|
29
|
+
const cl = candle.getValue("close");
|
|
30
|
+
const hi = candle.getValue("high");
|
|
31
|
+
const lo = candle.getValue("low");
|
|
32
|
+
const op = candle.getValue("open");
|
|
33
|
+
|
|
34
|
+
if (cl && hi && lo && op) {
|
|
35
|
+
//@ts-ignore
|
|
36
|
+
const close = f32(Number.parseFloat(cl.toString()));
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
const high = f32(Number.parseFloat(hi.toString()));
|
|
39
|
+
//@ts-ignore
|
|
40
|
+
const low = f32(Number.parseFloat(lo.toString()));
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
const open = f32(Number.parseFloat(op.toString()));
|
|
43
|
+
|
|
44
|
+
const obj: Price = new Price(high, low, open, close);
|
|
45
|
+
|
|
46
|
+
result.push(obj);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
} else {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
package/assembly/utils/Ranges.ts
CHANGED
package/assembly/utils/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Price';
|