@yuants/vendor-huobi 0.11.34 → 0.11.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-huobi",
3
- "version": "0.11.34",
3
+ "version": "0.11.36",
4
4
  "bin": "lib/cli.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -9,18 +9,17 @@
9
9
  "temp"
10
10
  ],
11
11
  "dependencies": {
12
- "@yuants/protocol": "0.49.0",
13
- "@yuants/data-account": "0.6.8",
14
- "@yuants/data-order": "0.3.6",
15
- "@yuants/transfer": "0.2.27",
16
- "@yuants/utils": "0.9.0",
17
- "@yuants/cache": "0.2.0",
18
- "@yuants/sql": "0.9.18",
19
- "@yuants/data-product": "0.4.8",
20
- "@yuants/data-series": "0.3.39",
21
- "@yuants/data-interest-rate": "0.1.36",
22
- "@yuants/data-quote": "0.2.31",
23
- "@yuants/secret": "0.2.22",
12
+ "@yuants/protocol": "0.49.1",
13
+ "@yuants/data-account": "0.6.9",
14
+ "@yuants/data-order": "0.3.7",
15
+ "@yuants/transfer": "0.2.28",
16
+ "@yuants/utils": "0.10.0",
17
+ "@yuants/cache": "0.2.1",
18
+ "@yuants/sql": "0.9.19",
19
+ "@yuants/data-product": "0.4.10",
20
+ "@yuants/data-series": "0.3.40",
21
+ "@yuants/data-interest-rate": "0.1.37",
22
+ "@yuants/data-quote": "0.2.32",
24
23
  "rxjs": "~7.5.6",
25
24
  "crypto-js": "^4.2.0"
26
25
  },
@@ -31,7 +30,7 @@
31
30
  "@rushstack/heft-node-rig": "~1.10.7",
32
31
  "@types/heft-jest": "1.0.3",
33
32
  "@types/node": "22",
34
- "@yuants/extension": "0.2.25",
33
+ "@yuants/extension": "0.2.26",
35
34
  "@yuants/tool-kit": "0.2.0",
36
35
  "typescript": "~4.7.4"
37
36
  },
@@ -1,35 +1,33 @@
1
1
  {
2
- "apps/vendor-huobi/CHANGELOG.json": "6362911551d4075c8f362223f5e08f28373d2ea6",
3
- "apps/vendor-huobi/CHANGELOG.md": "dbdd0b02029cf3f9acadba6adc34c3aced8295a1",
2
+ "apps/vendor-huobi/CHANGELOG.json": "7c6e1649709d6d0d6f5618285924962338d7fa6c",
3
+ "apps/vendor-huobi/CHANGELOG.md": "f27b1e0bf92cb6248be1d19d1b3eda744a48080b",
4
4
  "apps/vendor-huobi/README.md": "d7bf0149513114eab5500a6b5c9e7cba10565572",
5
5
  "apps/vendor-huobi/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
6
6
  "apps/vendor-huobi/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
7
7
  "apps/vendor-huobi/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
8
8
  "apps/vendor-huobi/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
9
9
  "apps/vendor-huobi/etc/vendor-huobi.api.md": "dc8cbf2a044a227b30a4ee9701b0c97328244724",
10
- "apps/vendor-huobi/package.json": "6815bca462ed82ed841726f77c859bdb78bf2f0b",
10
+ "apps/vendor-huobi/package.json": "22c7e348cf2a3616fc378bf1a2e9c811670d030f",
11
11
  "apps/vendor-huobi/src/api.ts": "7f13d45da5c3600276cdf4e734e086358d96b348",
12
12
  "apps/vendor-huobi/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
13
- "apps/vendor-huobi/src/cluster.ts": "f58a96d9c89e29e4fcf7cedd8ea9cb1dc920540b",
14
13
  "apps/vendor-huobi/src/index.ts": "a0695d883a439740b990c883b002f27f237ee5a5",
15
14
  "apps/vendor-huobi/src/interest_rate.ts": "1ada272b47f382533368928758b35176442d957f",
16
15
  "apps/vendor-huobi/src/logger.ts": "d25d427e74f46819a601e0cb17d5358b22c8db7b",
17
16
  "apps/vendor-huobi/src/product.ts": "2e15fedf89c1dc5ab2fc9c557ee94c3fbb0bd57d",
18
17
  "apps/vendor-huobi/src/quote.ts": "d772d64897c765a8157dac1a9abc0f3f488eaa1d",
19
18
  "apps/vendor-huobi/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
20
- "apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "d9fc97de6643d551cb315ce28c6deca42698705c",
21
- "libraries/protocol/temp/package-deps.json": "11b1ec6e83d466da55c316e4e2ab53cc48c3bc64",
22
- "libraries/data-account/temp/package-deps.json": "89f0acde8bee43a9c2125559935730dadbf64ce9",
23
- "libraries/data-order/temp/package-deps.json": "9f7b7bb91ce6b9d2bd039912dd1cece19a72c68a",
24
- "libraries/transfer/temp/package-deps.json": "b5d75d2dca39bc64460a1376fe39addd236d7385",
25
- "libraries/utils/temp/package-deps.json": "43e2f82267afa2b74314163b5c31d42ac615785b",
26
- "libraries/cache/temp/package-deps.json": "50519511068988ff0a7c64f03d862908566bdd30",
27
- "libraries/sql/temp/package-deps.json": "5e3867c0ea14708b0cddcba1d02628882f39b533",
28
- "libraries/data-product/temp/package-deps.json": "4a91ef28bc65b1dce56d36f3c93d5affa2cea31d",
29
- "libraries/data-series/temp/package-deps.json": "31a1137caa1541f8f3b2486cc2f071d7cc8d2c7e",
30
- "libraries/data-interest-rate/temp/package-deps.json": "e1affc2c24b409a5f6de81b4c515a21facfea59b",
31
- "libraries/data-quote/temp/package-deps.json": "c5e47fcf2e8f98773e4df19a07eab210b627c498",
32
- "libraries/secret/temp/package-deps.json": "44f23aaaa96260dcdb77343f792e2b945231356e",
33
- "libraries/extension/temp/package-deps.json": "89316671ad698642d396774cf743dbe240cdbddc",
19
+ "apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "9cfeff02d2b4838478ed6afd825f89806d4c2b57",
20
+ "libraries/protocol/temp/package-deps.json": "0a3f80906e99efffe686a474d0f15c9410ee8874",
21
+ "libraries/data-account/temp/package-deps.json": "bfa01200dc996e34f59d2768caf5077467df5573",
22
+ "libraries/data-order/temp/package-deps.json": "3a98bb6bed777858bc9b6a6ab4067fd86cddd6cf",
23
+ "libraries/transfer/temp/package-deps.json": "d73a9ba8f08848ccf0aa1ae8f1debc0d6862325b",
24
+ "libraries/utils/temp/package-deps.json": "00132af02f003a95edfc2b9e1e9ec298a59fb89c",
25
+ "libraries/cache/temp/package-deps.json": "799f9edbfbe2ac79db21a0f933c78373356203dc",
26
+ "libraries/sql/temp/package-deps.json": "1d1d91dcd9a6cc28f3309fe7fd45de952aacb4fb",
27
+ "libraries/data-product/temp/package-deps.json": "722dbd45b5a7433c9fa26e450c39a2b5f9d7045f",
28
+ "libraries/data-series/temp/package-deps.json": "678eae040552d81b455284857d187123decd832d",
29
+ "libraries/data-interest-rate/temp/package-deps.json": "2ecad524c89f84f7b8528305ac396080d2ab1b07",
30
+ "libraries/data-quote/temp/package-deps.json": "54b24d1649fab8db58f9b19c1b43a7c63c62533c",
31
+ "libraries/extension/temp/package-deps.json": "baf08ab93278543b640b68f31261ffd3705bd9e7",
34
32
  "tools/toolkit/temp/package-deps.json": "3bef053db16659f0cdaceea64c8a8580c0131633"
35
33
  }
package/dist/cluster.js DELETED
@@ -1,72 +0,0 @@
1
- import { Terminal } from '@yuants/protocol';
2
- import { loadSecrets } from '@yuants/secret';
3
- import { listWatch } from '@yuants/utils';
4
- import cluster from 'cluster';
5
- import { bufferTime, defer, filter, map, Observable, repeat, retry, Subject } from 'rxjs';
6
- import { overrideConsole } from './logger';
7
- overrideConsole();
8
- if (cluster.isPrimary) {
9
- console.info('This is the primary process');
10
- const logBuffer = new Subject();
11
- logBuffer
12
- .pipe(
13
- //
14
- bufferTime(100), map((v) => v.join('\n')), filter((v) => v.trim() !== ''))
15
- .subscribe((message) => {
16
- console.info(message);
17
- });
18
- defer(() => loadSecrets({
19
- terminal: Terminal.fromNodeEnv(),
20
- encryption_key_base58: process.env.ENCRYPTION_KEY_BASE58,
21
- }))
22
- .pipe(
23
- //
24
- retry({ delay: 5000 }), repeat({ delay: 5000 }))
25
- .pipe(listWatch((x) => x.secret.id, (account) => defer(() => new Observable((subscriber) => {
26
- if (account.secret.public_data.type !== 'api_key_htx')
27
- return;
28
- if (!account.secret.public_data.name)
29
- return;
30
- if (!account.decrypted_data)
31
- return;
32
- if (!account.decrypted_data.access_key)
33
- return;
34
- if (!account.decrypted_data.secret_key)
35
- return;
36
- const worker = cluster.fork({
37
- ENCRYPTION_KEY_BASE58: '',
38
- ACCESS_KEY: account.decrypted_data.access_key,
39
- SECRET_KEY: account.decrypted_data.secret_key,
40
- WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',
41
- TERMINAL_ID: `@yuants/vendor-huobi/worker/${account.secret.public_data.name}`,
42
- WORKER_LABEL: account.secret.public_data.name,
43
- });
44
- worker.on('message', (message) => {
45
- if (message.type === 'log') {
46
- logBuffer.next(`[Worker ${worker.process.pid} ${message.label}] ${message.level}: ${message.message}`);
47
- }
48
- });
49
- worker.on('exit', (code, signal) => {
50
- if (code === 0) {
51
- console.log(`Worker ${worker.process.pid} exited gracefully`);
52
- subscriber.complete();
53
- }
54
- else {
55
- console.error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`);
56
- subscriber.error(new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`));
57
- }
58
- });
59
- return () => {
60
- worker.kill();
61
- console.log(`Worker ${worker.process.pid} killed`);
62
- };
63
- })).pipe(
64
- //
65
- retry({ delay: 1000 }), repeat({ delay: 1000 })), (a, b) => a.secret.updated_at === b.secret.updated_at))
66
- .subscribe();
67
- }
68
- else {
69
- console.info('This is the worker process', process.pid, process.env);
70
- import('./index');
71
- }
72
- //# sourceMappingURL=cluster.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../src/cluster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,E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AAC,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,CAAC;gBAC9D,UAAU,CAAC,QAAQ,EAAE,CAAC;aACvB;iBAAM;gBACL,OAAO,CAAC,KAAK,CACX,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,qBAAqB,IAAI,eAAe,MAAM,EAAE,CAC7E,CAAC;gBACF,UAAU,CAAC,KAAK,CACd,IAAI,KAAK,CAAC,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,qBAAqB,IAAI,eAAe,MAAM,EAAE,CAAC,CACxF,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;QACrD,CAAC,CAAC;IACJ,CAAC,CAAC,CACL,CAAC,IAAI;IACJ,EAAE;IACF,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CACxB,EACH,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CACtD,CACF;SACA,SAAS,EAAE,CAAC;CAChB;KAAM;IACL,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACrE,MAAM,CAAC,SAAS,CAAC,CAAC;CACnB","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { loadSecrets } from '@yuants/secret';\nimport { listWatch } from '@yuants/utils';\nimport cluster from 'cluster';\nimport { bufferTime, defer, filter, map, Observable, repeat, retry, Subject } from 'rxjs';\nimport { overrideConsole } from './logger';\n\noverrideConsole();\n\nif (cluster.isPrimary) {\n console.info('This is the primary process');\n\n const logBuffer = new Subject<string>();\n\n logBuffer\n .pipe(\n //\n bufferTime(100),\n map((v) => v.join('\\n')),\n filter((v) => v.trim() !== ''),\n )\n .subscribe((message) => {\n console.info(message);\n });\n\n defer(() =>\n loadSecrets<{ access_key: string; secret_key: string }>({\n terminal: Terminal.fromNodeEnv(),\n encryption_key_base58: process.env.ENCRYPTION_KEY_BASE58!,\n }),\n )\n .pipe(\n //\n retry({ delay: 5000 }),\n repeat({ delay: 5000 }),\n )\n .pipe(\n listWatch(\n (x) => x.secret.id,\n (account) =>\n defer(\n () =>\n new Observable((subscriber) => {\n if (account.secret.public_data.type !== 'api_key_htx') return;\n if (!account.secret.public_data.name) return;\n if (!account.decrypted_data) return;\n if (!account.decrypted_data.access_key) return;\n if (!account.decrypted_data.secret_key) return;\n\n const worker = cluster.fork({\n ENCRYPTION_KEY_BASE58: '',\n ACCESS_KEY: account.decrypted_data.access_key,\n SECRET_KEY: account.decrypted_data.secret_key,\n WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',\n TERMINAL_ID: `@yuants/vendor-huobi/worker/${account.secret.public_data.name}`,\n WORKER_LABEL: account.secret.public_data.name,\n });\n\n worker.on('message', (message: any) => {\n if (message.type === 'log') {\n logBuffer.next(\n `[Worker ${worker.process.pid} ${message.label}] ${message.level}: ${message.message}`,\n );\n }\n });\n\n worker.on('exit', (code, signal) => {\n if (code === 0) {\n console.log(`Worker ${worker.process.pid} exited gracefully`);\n subscriber.complete();\n } else {\n console.error(\n `Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`,\n );\n subscriber.error(\n new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`),\n );\n }\n });\n return () => {\n worker.kill();\n console.log(`Worker ${worker.process.pid} killed`);\n };\n }),\n ).pipe(\n //\n retry({ delay: 1000 }),\n repeat({ delay: 1000 }), // 重试间隔为 1 秒\n ),\n (a, b) => a.secret.updated_at === b.secret.updated_at,\n ),\n )\n .subscribe();\n} else {\n console.info('This is the worker process', process.pid, process.env);\n import('./index');\n}\n"]}
package/lib/cluster.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=cluster.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../src/cluster.ts"],"names":[],"mappings":""}
package/lib/cluster.js DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const protocol_1 = require("@yuants/protocol");
30
- const secret_1 = require("@yuants/secret");
31
- const utils_1 = require("@yuants/utils");
32
- const cluster_1 = __importDefault(require("cluster"));
33
- const rxjs_1 = require("rxjs");
34
- const logger_1 = require("./logger");
35
- (0, logger_1.overrideConsole)();
36
- if (cluster_1.default.isPrimary) {
37
- console.info('This is the primary process');
38
- const logBuffer = new rxjs_1.Subject();
39
- logBuffer
40
- .pipe(
41
- //
42
- (0, rxjs_1.bufferTime)(100), (0, rxjs_1.map)((v) => v.join('\n')), (0, rxjs_1.filter)((v) => v.trim() !== ''))
43
- .subscribe((message) => {
44
- console.info(message);
45
- });
46
- (0, rxjs_1.defer)(() => (0, secret_1.loadSecrets)({
47
- terminal: protocol_1.Terminal.fromNodeEnv(),
48
- encryption_key_base58: process.env.ENCRYPTION_KEY_BASE58,
49
- }))
50
- .pipe(
51
- //
52
- (0, rxjs_1.retry)({ delay: 5000 }), (0, rxjs_1.repeat)({ delay: 5000 }))
53
- .pipe((0, utils_1.listWatch)((x) => x.secret.id, (account) => (0, rxjs_1.defer)(() => new rxjs_1.Observable((subscriber) => {
54
- if (account.secret.public_data.type !== 'api_key_htx')
55
- return;
56
- if (!account.secret.public_data.name)
57
- return;
58
- if (!account.decrypted_data)
59
- return;
60
- if (!account.decrypted_data.access_key)
61
- return;
62
- if (!account.decrypted_data.secret_key)
63
- return;
64
- const worker = cluster_1.default.fork({
65
- ENCRYPTION_KEY_BASE58: '',
66
- ACCESS_KEY: account.decrypted_data.access_key,
67
- SECRET_KEY: account.decrypted_data.secret_key,
68
- WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',
69
- TERMINAL_ID: `@yuants/vendor-huobi/worker/${account.secret.public_data.name}`,
70
- WORKER_LABEL: account.secret.public_data.name,
71
- });
72
- worker.on('message', (message) => {
73
- if (message.type === 'log') {
74
- logBuffer.next(`[Worker ${worker.process.pid} ${message.label}] ${message.level}: ${message.message}`);
75
- }
76
- });
77
- worker.on('exit', (code, signal) => {
78
- if (code === 0) {
79
- console.log(`Worker ${worker.process.pid} exited gracefully`);
80
- subscriber.complete();
81
- }
82
- else {
83
- console.error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`);
84
- subscriber.error(new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`));
85
- }
86
- });
87
- return () => {
88
- worker.kill();
89
- console.log(`Worker ${worker.process.pid} killed`);
90
- };
91
- })).pipe(
92
- //
93
- (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.repeat)({ delay: 1000 })), (a, b) => a.secret.updated_at === b.secret.updated_at))
94
- .subscribe();
95
- }
96
- else {
97
- console.info('This is the worker process', process.pid, process.env);
98
- Promise.resolve().then(() => __importStar(require('./index')));
99
- }
100
- //# sourceMappingURL=cluster.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../src/cluster.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,2CAA6C;AAC7C,yCAA0C;AAC1C,sDAA8B;AAC9B,+BAA0F;AAC1F,qCAA2C;AAE3C,IAAA,wBAAe,GAAE,CAAC;AAElB,IAAI,iBAAO,CAAC,SAAS,EAAE;IACrB,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAE5C,MAAM,SAAS,GAAG,IAAI,cAAO,EAAU,CAAC;IAExC,SAAS;SACN,IAAI;IACH,EAAE;IACF,IAAA,iBAAU,EAAC,GAAG,CAAC,EACf,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EACxB,IAAA,aAAM,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAC/B;SACA,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;QACrB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEL,IAAA,YAAK,EAAC,GAAG,EAAE,CACT,IAAA,oBAAW,EAA6C;QACtD,QAAQ,EAAE,mBAAQ,CAAC,WAAW,EAAE;QAChC,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAsB;KAC1D,CAAC,CACH;SACE,IAAI;IACH,EAAE;IACF,IAAA,YAAK,EAAC,EAAE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AC,GAAG,CAAC,CAAC;IACrE,kDAAO,SAAS,IAAE;CACnB","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { loadSecrets } from '@yuants/secret';\nimport { listWatch } from '@yuants/utils';\nimport cluster from 'cluster';\nimport { bufferTime, defer, filter, map, Observable, repeat, retry, Subject } from 'rxjs';\nimport { overrideConsole } from './logger';\n\noverrideConsole();\n\nif (cluster.isPrimary) {\n console.info('This is the primary process');\n\n const logBuffer = new Subject<string>();\n\n logBuffer\n .pipe(\n //\n bufferTime(100),\n map((v) => v.join('\\n')),\n filter((v) => v.trim() !== ''),\n )\n .subscribe((message) => {\n console.info(message);\n });\n\n defer(() =>\n loadSecrets<{ access_key: string; secret_key: string }>({\n terminal: Terminal.fromNodeEnv(),\n encryption_key_base58: process.env.ENCRYPTION_KEY_BASE58!,\n }),\n )\n .pipe(\n //\n retry({ delay: 5000 }),\n repeat({ delay: 5000 }),\n )\n .pipe(\n listWatch(\n (x) => x.secret.id,\n (account) =>\n defer(\n () =>\n new Observable((subscriber) => {\n if (account.secret.public_data.type !== 'api_key_htx') return;\n if (!account.secret.public_data.name) return;\n if (!account.decrypted_data) return;\n if (!account.decrypted_data.access_key) return;\n if (!account.decrypted_data.secret_key) return;\n\n const worker = cluster.fork({\n ENCRYPTION_KEY_BASE58: '',\n ACCESS_KEY: account.decrypted_data.access_key,\n SECRET_KEY: account.decrypted_data.secret_key,\n WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',\n TERMINAL_ID: `@yuants/vendor-huobi/worker/${account.secret.public_data.name}`,\n WORKER_LABEL: account.secret.public_data.name,\n });\n\n worker.on('message', (message: any) => {\n if (message.type === 'log') {\n logBuffer.next(\n `[Worker ${worker.process.pid} ${message.label}] ${message.level}: ${message.message}`,\n );\n }\n });\n\n worker.on('exit', (code, signal) => {\n if (code === 0) {\n console.log(`Worker ${worker.process.pid} exited gracefully`);\n subscriber.complete();\n } else {\n console.error(\n `Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`,\n );\n subscriber.error(\n new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`),\n );\n }\n });\n return () => {\n worker.kill();\n console.log(`Worker ${worker.process.pid} killed`);\n };\n }),\n ).pipe(\n //\n retry({ delay: 1000 }),\n repeat({ delay: 1000 }), // 重试间隔为 1 秒\n ),\n (a, b) => a.secret.updated_at === b.secret.updated_at,\n ),\n )\n .subscribe();\n} else {\n console.info('This is the worker process', process.pid, process.env);\n import('./index');\n}\n"]}