@steerprotocol/data-connector-loader 0.0.16 → 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.
- package/lib/dataConnector.js +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -2
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +28 -0
- package/package.json +3 -3
package/lib/dataConnector.js
CHANGED
|
@@ -56,7 +56,7 @@ class DataConnector {
|
|
|
56
56
|
if (!this.module)
|
|
57
57
|
throw new Error('Module not initialized');
|
|
58
58
|
// Call the main function with the response
|
|
59
|
-
return this.module
|
|
59
|
+
return this.module.execute(response);
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
// This function returns a provider based on the chainId of the request
|
|
@@ -109,7 +109,7 @@ class DataConnector {
|
|
|
109
109
|
version() {
|
|
110
110
|
if (!this.module)
|
|
111
111
|
throw new Error('Module not initialized');
|
|
112
|
-
return this.module.version();
|
|
112
|
+
return Number(this.module.version());
|
|
113
113
|
}
|
|
114
114
|
subtractDate(timestamp, epochLength) {
|
|
115
115
|
const date = new Date(timestamp);
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -12,9 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DataConnectorExecution = void 0;
|
|
15
|
+
exports.DataConnectorExecution = exports.DataConnector = void 0;
|
|
16
|
+
const dataConnector_1 = require("./dataConnector");
|
|
17
|
+
Object.defineProperty(exports, "DataConnector", { enumerable: true, get: function () { return dataConnector_1.DataConnector; } });
|
|
16
18
|
const axios_1 = __importDefault(require("axios"));
|
|
17
19
|
const pluginManager_1 = require("./pluginManager");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
18
21
|
class DataConnectorExecution {
|
|
19
22
|
constructor(dataConnectors) {
|
|
20
23
|
this.dataConnectors = dataConnectors;
|
|
@@ -63,6 +66,7 @@ class DataConnectorExecution {
|
|
|
63
66
|
return delay;
|
|
64
67
|
}
|
|
65
68
|
execute(_vaultConfig) {
|
|
69
|
+
var _a, _b, _c;
|
|
66
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
71
|
const executionTimestamp = new Date().getTime();
|
|
68
72
|
const vaultConfig = JSON.parse(_vaultConfig);
|
|
@@ -89,6 +93,7 @@ class DataConnectorExecution {
|
|
|
89
93
|
blockTime,
|
|
90
94
|
blockNumber,
|
|
91
95
|
});
|
|
96
|
+
const version = yield dataConnector.version();
|
|
92
97
|
let request = yield dataConnector.execute('');
|
|
93
98
|
let response;
|
|
94
99
|
try {
|
|
@@ -113,7 +118,21 @@ class DataConnectorExecution {
|
|
|
113
118
|
throw e;
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
|
-
|
|
121
|
+
let transformedData = JSON.parse(dataConnector.getResults());
|
|
122
|
+
if (version == 1 && transformedData.length > 0) {
|
|
123
|
+
const keys = Object.keys(transformedData[0]);
|
|
124
|
+
const requiredKeys = ['open', 'high', 'low', 'close', 'volume'];
|
|
125
|
+
const hasAllKeys = requiredKeys.every((key) => keys.includes(key));
|
|
126
|
+
// has the 'lookback' key
|
|
127
|
+
const lookback = (_a = dataConnector === null || dataConnector === void 0 ? void 0 : dataConnector.configObj) === null || _a === void 0 ? void 0 : _a.lookback;
|
|
128
|
+
if (hasAllKeys && !!lookback) {
|
|
129
|
+
// Now that we have identified a v1 data connector, we need to transform the data so that the data is up to the current execution epoch timestamp
|
|
130
|
+
if ((_b = dataConnector === null || dataConnector === void 0 ? void 0 : dataConnector.executionContext) === null || _b === void 0 ? void 0 : _b.epochTimestamp) {
|
|
131
|
+
const extended = (0, utils_1.extendOHLCV)(transformedData, lookback, ((_c = dataConnector === null || dataConnector === void 0 ? void 0 : dataConnector.executionContext) === null || _c === void 0 ? void 0 : _c.epochTimestamp) * 1000);
|
|
132
|
+
transformedData = extended;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
117
136
|
transformationData.push(transformedData);
|
|
118
137
|
}
|
|
119
138
|
return transformationData;
|
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendOHLCV = void 0;
|
|
4
|
+
// The purpose of this function is to look at the end timestamp and extend the current candle array so that it backfills any missing candles up to the end timestamp
|
|
5
|
+
const extendOHLCV = (rawData, period, endTimestamp) => {
|
|
6
|
+
// Sort rawData by timestamp
|
|
7
|
+
const sortedData = rawData.sort((a, b) => a.timestamp - b.timestamp);
|
|
8
|
+
const lastCandle = sortedData[sortedData.length - 1];
|
|
9
|
+
const startTimestamp = lastCandle ? lastCandle.timestamp : endTimestamp;
|
|
10
|
+
// Calculate the number of periods to backfill
|
|
11
|
+
const periodsToBackfill = Math.floor(((endTimestamp - startTimestamp)) / 1000 / period);
|
|
12
|
+
// Backfill the candles
|
|
13
|
+
for (let i = 0; i < periodsToBackfill; i++) {
|
|
14
|
+
const candleWidth = (period * (i + 1));
|
|
15
|
+
const newCandle = {
|
|
16
|
+
timestamp: startTimestamp + candleWidth,
|
|
17
|
+
open: lastCandle.open,
|
|
18
|
+
high: lastCandle.open,
|
|
19
|
+
low: lastCandle.open,
|
|
20
|
+
close: lastCandle.open,
|
|
21
|
+
volume: 0, // You may need to replace these with appropriate logic
|
|
22
|
+
};
|
|
23
|
+
sortedData.push(newCandle);
|
|
24
|
+
}
|
|
25
|
+
// Return the converted data
|
|
26
|
+
return sortedData;
|
|
27
|
+
};
|
|
28
|
+
exports.extendOHLCV = extendOHLCV;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/data-connector-loader",
|
|
3
|
-
"version": "0.0
|
|
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",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"lib/**/*"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@steerprotocol/app-loader": "0.
|
|
49
|
+
"@steerprotocol/app-loader": "0.2.0",
|
|
50
50
|
"@steerprotocol/strategy-utils": "^2.1.0",
|
|
51
51
|
"axios": "^1.3.4",
|
|
52
52
|
"ethers": "^5.1.0",
|
|
53
|
-
"
|
|
53
|
+
"timestring": "^7.0.0"
|
|
54
54
|
}
|
|
55
55
|
}
|