wenay-common 1.0.77 → 1.0.79

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.
@@ -71,6 +71,9 @@ export type typeNoVoid2<T> = {
71
71
  [P in keyof T]: T[P] extends (any: any) => any ? ReturnType<T[P]> extends void ? never : P : never;
72
72
  }[keyof T]>]: T[P];
73
73
  };
74
+ export type UnAwaited<T extends Promise<any>> = T extends Promise<infer R> ? R : never;
75
+ export type UnAwaitedArr<T extends Promise<any>[]> = T extends Promise<infer R>[] ? R[] : never;
76
+ export type tElArr<T extends any[]> = T extends (infer R)[] ? R : never;
74
77
  export declare function CreatAPIFacadeClient<T extends object>({ socketKey, socket }: {
75
78
  socket: any;
76
79
  socketKey: string;
@@ -40,7 +40,11 @@ export type tLoadFist<IntervalNameT extends (number | string)> = {
40
40
  export type tSetHistoryData = CBar & {
41
41
  tf?: TF;
42
42
  };
43
- type tBinanceLoadBase<Bar, maxLoadBarType extends (number | Date), IntervalNameT extends (number | string)> = {
43
+ type tBinanceLoadBase<Bar extends {
44
+ time?: number;
45
+ } | {
46
+ time?: Date;
47
+ } | object, maxLoadBarType extends (number | Date), IntervalNameT extends (number | string)> = {
44
48
  base: string;
45
49
  maxLoadBars: maxLoadBarType;
46
50
  maxLoadBars2?: maxLoadBarType;
@@ -54,10 +58,15 @@ type tBinanceLoadBase<Bar, maxLoadBarType extends (number | Date), IntervalNameT
54
58
  }[];
55
59
  nameKey?: string;
56
60
  };
57
- export declare function LoadQuoteBase<Bar, T extends (number | Date), T2 extends (number | string)>(setting: tBinanceLoadBase<Bar, T, T2> & {
61
+ export declare function LoadQuoteBase<Bar extends {
62
+ time?: number;
63
+ } | {
64
+ time?: Date;
65
+ } | object, T extends (number | Date), T2 extends (number | string)>(setting: tBinanceLoadBase<Bar, T, T2> & {
58
66
  maxLoadBars: T;
59
67
  }, data?: {
60
68
  fetch?: tFetch3;
61
69
  error?: boolean;
70
+ reverseControl?: boolean;
62
71
  }): (info: tInfoForLoadHistory) => Promise<Bar[]>;
63
72
  export {};
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoadQuoteBase = void 0;
4
4
  const Common_1 = require("../Common/Common");
5
+ const Time_1 = require("../Common/Time");
5
6
  const funcTimeWait_1 = require("../Common/funcTimeWait");
6
7
  function LoadQuoteBase(setting, data) {
7
8
  const { base, maxLoadBars, countConnect, intervalToName } = setting;
@@ -9,6 +10,7 @@ function LoadQuoteBase(setting, data) {
9
10
  const startMap = new Map();
10
11
  const keyName = setting.nameKey ?? "loadKey";
11
12
  const time = setting.time ?? 60000;
13
+ const other = data;
12
14
  async function waitLimit(weight = 1) {
13
15
  const t1 = funcTimeWait_1.FuncTimeWait.byWeight(keyName, setting.countConnect) - (Date.now() - time) + 1;
14
16
  if (t1 > 0) {
@@ -20,7 +22,7 @@ function LoadQuoteBase(setting, data) {
20
22
  }
21
23
  }
22
24
  const mapTimeToName = new Map(intervalToName.map((e) => [e.time.sec, e]));
23
- const _fetch = data?.fetch ?? fetch;
25
+ const _fetch = other?.fetch ?? fetch;
24
26
  return async (info) => {
25
27
  const infoTF = mapTimeToName.get(info.tf.sec);
26
28
  if (!_fetch)
@@ -39,6 +41,7 @@ function LoadQuoteBase(setting, data) {
39
41
  if (time2 <= time1) {
40
42
  return [];
41
43
  }
44
+ const [t1, t2] = info.right ? [time1, time2] : [time2, time1];
42
45
  const arr = [];
43
46
  const interval = infoTF.time.valueOf();
44
47
  const map = [];
@@ -46,7 +49,6 @@ function LoadQuoteBase(setting, data) {
46
49
  const [step1] = [
47
50
  maxLoadBars.valueOf()
48
51
  ];
49
- const [t1, t2] = info.right ? [time1, time2] : [time2, time1];
50
52
  arr.push(lastTime = t1);
51
53
  let barsTime = (t1 - t2);
52
54
  if (barsTime <= maxLoadBars.valueOf())
@@ -60,11 +62,10 @@ function LoadQuoteBase(setting, data) {
60
62
  arr.push(t2);
61
63
  }
62
64
  }
63
- else if (maxLoadBars instanceof Number) {
65
+ else if (typeof maxLoadBars == "number") {
64
66
  const [step1] = [
65
67
  maxLoadBars * interval,
66
68
  ];
67
- const [t1, t2] = info.right ? [time1, time2] : [time2, time1];
68
69
  arr.push(lastTime = t1);
69
70
  let bars = (t1 - t2) / interval;
70
71
  if (bars <= maxLoadBars)
@@ -95,15 +96,26 @@ function LoadQuoteBase(setting, data) {
95
96
  waitLimit
96
97
  };
97
98
  await waitLimit();
98
- return setting.funcLoad(data);
99
+ const res = await setting.funcLoad(data);
100
+ if (res.length && res[0].time && (other?.reverseControl !== false)) {
101
+ let t1, t2;
102
+ if (typeof res[0].time == "object")
103
+ [t1, t2] = [res[0].time.valueOf(), res.at(-1).time?.valueOf()];
104
+ else
105
+ [t1, t2] = [res[0].time, res.at(-1).time];
106
+ if (t1 > t2)
107
+ res.reverse();
108
+ }
109
+ return res;
99
110
  })());
100
111
  }
101
112
  const resulI = await Promise.allSettled(map);
102
113
  const result = [];
103
114
  for (let i = resulI.length - 1; i >= 0; i--) {
104
115
  const el = resulI[i];
105
- if (el.status == "fulfilled")
116
+ if (el.status == "fulfilled") {
106
117
  result.push(...el.value);
118
+ }
107
119
  if (el.status == "rejected") {
108
120
  console.error(el.reason);
109
121
  if (data?.error === true)
@@ -114,3 +126,32 @@ function LoadQuoteBase(setting, data) {
114
126
  };
115
127
  }
116
128
  exports.LoadQuoteBase = LoadQuoteBase;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wenay-common",
3
- "version": "1.0.77",
3
+ "version": "1.0.79",
4
4
  "description": "math math math",
5
5
  "strict": true,
6
6
  "main": "lib/index.js",