wenay-common2 1.0.39 → 1.0.41
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.
|
@@ -14,11 +14,6 @@ function createClient(socket, key, opts) {
|
|
|
14
14
|
let strictData = {};
|
|
15
15
|
let strictWaiters = [];
|
|
16
16
|
let debug = false;
|
|
17
|
-
const unpackResult = (v) => {
|
|
18
|
-
if (!v)
|
|
19
|
-
return v;
|
|
20
|
-
return v;
|
|
21
|
-
};
|
|
22
17
|
socket.on(key, (msg) => {
|
|
23
18
|
if (!Array.isArray(msg))
|
|
24
19
|
return;
|
|
@@ -33,11 +28,11 @@ function createClient(socket, key, opts) {
|
|
|
33
28
|
callbacks.delete(cbId);
|
|
34
29
|
pool.release(cbId);
|
|
35
30
|
}
|
|
36
|
-
msg[3] ? req.fail(msg[3]) : req.ok(unpackResult(msg[2]));
|
|
31
|
+
msg[3] ? req.fail(msg[3]) : req.ok((0, rpc_walk_1.unpackResult)(msg[2]));
|
|
37
32
|
break;
|
|
38
33
|
}
|
|
39
34
|
case rpc_protocol_1.Pkt.CB: {
|
|
40
|
-
callbacks.get(msg[1])?.(...(msg[2] || []));
|
|
35
|
+
callbacks.get(msg[1])?.(...(msg[2] || []).map(rpc_walk_1.unpackResult));
|
|
41
36
|
break;
|
|
42
37
|
}
|
|
43
38
|
case rpc_protocol_1.Pkt.CB_END: {
|
|
@@ -189,7 +189,7 @@ function createServer(socket, key, target, hooks, limits) {
|
|
|
189
189
|
send([rpc_protocol_1.Pkt.RESP, reqId, (0, rpc_walk_1.packResult)(current)]);
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
const args = (0, rpc_walk_1.unpack)(rawArgsOrSteps, (cbId, cbArgs) => send([rpc_protocol_1.Pkt.CB, cbId, cbArgs]), (cbId) => send([rpc_protocol_1.Pkt.CB_END, cbId]), lim);
|
|
192
|
+
const args = (0, rpc_walk_1.unpack)(rawArgsOrSteps, (cbId, cbArgs) => send([rpc_protocol_1.Pkt.CB, cbId, cbArgs.map(rpc_walk_1.packResult)]), (cbId) => send([rpc_protocol_1.Pkt.CB_END, cbId]), lim);
|
|
193
193
|
const res = await fn.apply(ctx, args);
|
|
194
194
|
if (wait)
|
|
195
195
|
send([rpc_protocol_1.Pkt.RESP, reqId, (0, rpc_walk_1.packResult)(res)]);
|
|
@@ -38,6 +38,8 @@ function walk(val, onLeaf, lim, depth = 0) {
|
|
|
38
38
|
}
|
|
39
39
|
if (val == null || typeof val !== "object")
|
|
40
40
|
return onLeaf(val);
|
|
41
|
+
if (val instanceof Date || val instanceof Map || val instanceof Set || val instanceof RegExp)
|
|
42
|
+
return onLeaf(val);
|
|
41
43
|
if (ALL_MARKERS.has(Object.keys(val)[0]))
|
|
42
44
|
return onLeaf(val);
|
|
43
45
|
if (Array.isArray(val)) {
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/Exchange/LoadBase.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoadQuoteBase = LoadQuoteBase;
|
|
4
|
-
const Time_1 = require("../Common/Time");
|
|
5
4
|
const funcTimeWait_1 = require("../Common/funcTimeWait");
|
|
6
5
|
const common_1 = require("../Common/core/common");
|
|
7
6
|
function LoadQuoteBase(setting, data) {
|
|
8
|
-
const { base, maxLoadBars,
|
|
9
|
-
const maxLoadBars2 = setting.maxLoadBars2 ?? maxLoadBars;
|
|
7
|
+
const { base, maxLoadBars, intervalToName } = setting;
|
|
10
8
|
const startMap = new Map();
|
|
11
9
|
const keyName = setting.nameKey ?? "loadKey";
|
|
12
10
|
const time = setting.time ?? 60000;
|
|
13
11
|
const other = data;
|
|
14
12
|
const getDataEl = (a) => setting.controlTimeToNumber?.(a);
|
|
15
13
|
async function waitLimit(weight = 1) {
|
|
16
|
-
const
|
|
14
|
+
const oldestTs = funcTimeWait_1.FuncTimeWait.byWeight(keyName, setting.countConnect);
|
|
15
|
+
const t1 = oldestTs > 0 ? oldestTs - Date.now() + time + 1 : 0;
|
|
17
16
|
if (t1 > 0) {
|
|
18
|
-
funcTimeWait_1.FuncTimeWait.add({ type: keyName, weight: weight, timeStamp: Date.now() + t1 });
|
|
19
17
|
await (0, common_1.sleepAsync)(t1);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
funcTimeWait_1.FuncTimeWait.add({ type: keyName, weight: weight, timeStamp: Date.now() });
|
|
23
|
-
}
|
|
19
|
+
funcTimeWait_1.FuncTimeWait.add({ type: keyName, weight: weight, timeStamp: Date.now() });
|
|
24
20
|
}
|
|
25
21
|
const mapTimeToName = new Map(intervalToName.map((e) => [e.time.sec, e]));
|
|
26
22
|
const _fetch = other?.fetch ?? fetch;
|
|
@@ -30,128 +26,82 @@ function LoadQuoteBase(setting, data) {
|
|
|
30
26
|
throw "_fetch - не определен";
|
|
31
27
|
if (!infoTF)
|
|
32
28
|
throw "нет такого таймфрейма";
|
|
33
|
-
let lastTime;
|
|
34
29
|
const nameForMap = info.exchangeName + info.symbol + infoTF.name;
|
|
35
30
|
let leftTime = startMap.get(nameForMap);
|
|
36
31
|
if (!leftTime) {
|
|
37
32
|
await waitLimit();
|
|
38
|
-
leftTime = await setting.funcFistTime({
|
|
33
|
+
leftTime = await setting.funcFistTime({
|
|
34
|
+
symbol: info.symbol, baseURL: base, interval: infoTF.name,
|
|
35
|
+
fetch: _fetch, intervalTF: info.tf, waitLimit
|
|
36
|
+
});
|
|
39
37
|
startMap.set(nameForMap, leftTime);
|
|
40
38
|
}
|
|
41
|
-
const
|
|
39
|
+
const time1 = Math.max(info.time1.valueOf(), leftTime.valueOf());
|
|
40
|
+
const time2 = info.time2.valueOf();
|
|
42
41
|
if (time2 <= time1) {
|
|
43
42
|
return [];
|
|
44
43
|
}
|
|
45
|
-
const [
|
|
44
|
+
const [tNewer, tOlder] = info.right ? [time2, time1] : [time2, time1];
|
|
46
45
|
const arr = [];
|
|
47
46
|
const interval = infoTF.time.valueOf();
|
|
48
|
-
const map = [];
|
|
49
47
|
if (maxLoadBars instanceof Date) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
arr.push(t2);
|
|
57
|
-
else {
|
|
58
|
-
barsTime -= maxLoadBars.valueOf();
|
|
59
|
-
arr.push(lastTime = lastTime - step1);
|
|
60
|
-
for (; barsTime > 0; barsTime -= maxLoadBars.valueOf())
|
|
61
|
-
arr.push(lastTime = lastTime - step1);
|
|
62
|
-
if (barsTime < 0)
|
|
63
|
-
arr.push(t2);
|
|
48
|
+
const step = maxLoadBars.valueOf();
|
|
49
|
+
arr.push(tNewer);
|
|
50
|
+
let span = tNewer - tOlder;
|
|
51
|
+
while (span > step) {
|
|
52
|
+
arr.push(arr[arr.length - 1] - step);
|
|
53
|
+
span -= step;
|
|
64
54
|
}
|
|
55
|
+
if (arr[arr.length - 1] > tOlder)
|
|
56
|
+
arr.push(tOlder);
|
|
65
57
|
}
|
|
66
|
-
else if (typeof maxLoadBars
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (bars <= maxLoadBars)
|
|
73
|
-
arr.push(t2);
|
|
74
|
-
else {
|
|
58
|
+
else if (typeof maxLoadBars === "number") {
|
|
59
|
+
const step = maxLoadBars * interval;
|
|
60
|
+
arr.push(tNewer);
|
|
61
|
+
let bars = (tNewer - tOlder) / interval;
|
|
62
|
+
while (bars > maxLoadBars) {
|
|
63
|
+
arr.push(arr[arr.length - 1] - step);
|
|
75
64
|
bars -= maxLoadBars;
|
|
76
|
-
arr.push(lastTime = lastTime - step1);
|
|
77
|
-
for (; bars > 0; bars -= maxLoadBars)
|
|
78
|
-
arr.push(lastTime = lastTime - step1);
|
|
79
|
-
if (bars < 0)
|
|
80
|
-
arr.push(t2);
|
|
81
65
|
}
|
|
66
|
+
if (arr[arr.length - 1] > tOlder)
|
|
67
|
+
arr.push(tOlder);
|
|
82
68
|
}
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
const result = [];
|
|
70
|
+
for (let i = 0; i < arr.length - 1; i++) {
|
|
71
|
+
const endTime = arr[i];
|
|
72
|
+
const startTime = arr[i + 1];
|
|
73
|
+
if (startTime >= endTime)
|
|
85
74
|
continue;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
let res = await setting.funcLoad(
|
|
101
|
-
if (setting.controlTimeToNumber && res.length) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
];
|
|
106
|
-
if (t1 && t2 && t1 > t2) {
|
|
75
|
+
await waitLimit();
|
|
76
|
+
const reqData = {
|
|
77
|
+
maxLoadBars,
|
|
78
|
+
fetch: _fetch,
|
|
79
|
+
baseURL: base,
|
|
80
|
+
symbol: info.symbol,
|
|
81
|
+
interval: infoTF.name,
|
|
82
|
+
startTime: new Date(startTime),
|
|
83
|
+
endTime: new Date(endTime),
|
|
84
|
+
limit: maxLoadBars,
|
|
85
|
+
intervalTF: info.tf,
|
|
86
|
+
waitLimit
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
let res = await setting.funcLoad(reqData);
|
|
90
|
+
if (setting.controlTimeToNumber && res.length > 0) {
|
|
91
|
+
const t1 = getDataEl(res[0]);
|
|
92
|
+
const t2 = getDataEl(res.at(-1));
|
|
93
|
+
if (t1 != null && t2 != null && t1 > t2) {
|
|
107
94
|
res = res.reverse();
|
|
108
95
|
}
|
|
109
96
|
}
|
|
110
|
-
|
|
111
|
-
})());
|
|
112
|
-
}
|
|
113
|
-
const resulI = await Promise.allSettled(map);
|
|
114
|
-
const result = [];
|
|
115
|
-
for (let i = resulI.length - 1; i >= 0; i--) {
|
|
116
|
-
const el = resulI[i];
|
|
117
|
-
if (el.status == "fulfilled") {
|
|
118
|
-
result.push(...el.value);
|
|
97
|
+
result.unshift(...res);
|
|
119
98
|
}
|
|
120
|
-
|
|
121
|
-
console.error(
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.error(e);
|
|
122
101
|
if (data?.error === true)
|
|
123
|
-
throw
|
|
102
|
+
throw e;
|
|
124
103
|
}
|
|
125
104
|
}
|
|
126
105
|
return result;
|
|
127
106
|
};
|
|
128
107
|
}
|
|
129
|
-
async function test() {
|
|
130
|
-
const arr = [];
|
|
131
|
-
for (let i = 0; i < 10000; i++) {
|
|
132
|
-
arr[i] = { time: Date.now() - i * Time_1.TF.H1.msec, price: i };
|
|
133
|
-
}
|
|
134
|
-
let ress = [];
|
|
135
|
-
const tt = LoadQuoteBase({
|
|
136
|
-
base: "",
|
|
137
|
-
countConnect: 2,
|
|
138
|
-
funcFistTime: async ({}) => {
|
|
139
|
-
const time = new Date(arr.at(-1).time);
|
|
140
|
-
console.log("funcFistTime: ", time);
|
|
141
|
-
return time;
|
|
142
|
-
},
|
|
143
|
-
nameKey: "cd",
|
|
144
|
-
maxLoadBars: 100,
|
|
145
|
-
time: 50,
|
|
146
|
-
intervalToName: [{ name: "1", time: Time_1.TF.H1 }],
|
|
147
|
-
funcLoad: (data) => {
|
|
148
|
-
ress.push(data.startTime);
|
|
149
|
-
ress.push(data.endTime);
|
|
150
|
-
return (async () => [{ time: 5 }])();
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
const res = await tt({ symbol: "s", time2: new Date(), tf: Time_1.TF.H1, time1: new Date(2015) });
|
|
154
|
-
ress.sort((a, b) => a.valueOf() - b.valueOf());
|
|
155
|
-
console.log(ress);
|
|
156
|
-
console.log(res);
|
|
157
|
-
}
|