@yuants/vendor-okx 0.16.9 → 0.17.1

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.
Files changed (90) hide show
  1. package/dist/account.js +198 -0
  2. package/dist/account.js.map +1 -0
  3. package/dist/api.js +463 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/cli.js +3 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cluster.js +80 -0
  8. package/dist/cluster.js.map +1 -0
  9. package/dist/extension.js +89 -0
  10. package/dist/extension.js.map +1 -0
  11. package/dist/index.js +7 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/interest_rate.js +133 -0
  14. package/dist/interest_rate.js.map +1 -0
  15. package/dist/legacy_index.js +554 -0
  16. package/dist/legacy_index.js.map +1 -0
  17. package/dist/logger.js +91 -0
  18. package/dist/logger.js.map +1 -0
  19. package/dist/ohlc.js +171 -0
  20. package/dist/ohlc.js.map +1 -0
  21. package/dist/order.js +96 -0
  22. package/dist/order.js.map +1 -0
  23. package/dist/product.js +85 -0
  24. package/dist/product.js.map +1 -0
  25. package/dist/quote.js +58 -0
  26. package/dist/quote.js.map +1 -0
  27. package/dist/vendor-okx.d.ts +1 -0
  28. package/dist/websocket.js +80 -0
  29. package/dist/websocket.js.map +1 -0
  30. package/lib/account.d.ts +102 -0
  31. package/lib/account.d.ts.map +1 -0
  32. package/lib/account.js +201 -0
  33. package/lib/account.js.map +1 -0
  34. package/lib/api.d.ts +1401 -0
  35. package/lib/api.d.ts.map +1 -0
  36. package/lib/api.js +470 -0
  37. package/lib/api.js.map +1 -0
  38. package/lib/cli.d.ts +3 -0
  39. package/lib/cli.d.ts.map +1 -0
  40. package/lib/cli.js +5 -0
  41. package/lib/cli.js.map +1 -0
  42. package/lib/cluster.d.ts +2 -0
  43. package/lib/cluster.d.ts.map +1 -0
  44. package/lib/cluster.js +108 -0
  45. package/lib/cluster.js.map +1 -0
  46. package/lib/extension.d.ts +4 -0
  47. package/lib/extension.d.ts.map +1 -0
  48. package/lib/extension.js +91 -0
  49. package/lib/extension.js.map +1 -0
  50. package/lib/index.d.ts +7 -0
  51. package/lib/index.d.ts.map +1 -0
  52. package/lib/index.js +9 -0
  53. package/lib/index.js.map +1 -0
  54. package/lib/interest_rate.d.ts +2 -0
  55. package/lib/interest_rate.d.ts.map +1 -0
  56. package/lib/interest_rate.js +135 -0
  57. package/lib/interest_rate.js.map +1 -0
  58. package/lib/legacy_index.d.ts +2 -0
  59. package/lib/legacy_index.d.ts.map +1 -0
  60. package/lib/legacy_index.js +556 -0
  61. package/lib/legacy_index.js.map +1 -0
  62. package/lib/logger.d.ts +21 -0
  63. package/lib/logger.d.ts.map +1 -0
  64. package/lib/logger.js +98 -0
  65. package/lib/logger.js.map +1 -0
  66. package/lib/ohlc.d.ts +2 -0
  67. package/lib/ohlc.d.ts.map +1 -0
  68. package/lib/ohlc.js +173 -0
  69. package/lib/ohlc.js.map +1 -0
  70. package/lib/order.d.ts +4 -0
  71. package/lib/order.d.ts.map +1 -0
  72. package/lib/order.js +99 -0
  73. package/lib/order.js.map +1 -0
  74. package/lib/product.d.ts +6 -0
  75. package/lib/product.d.ts.map +1 -0
  76. package/lib/product.js +88 -0
  77. package/lib/product.js.map +1 -0
  78. package/lib/quote.d.ts +42 -0
  79. package/lib/quote.d.ts.map +1 -0
  80. package/lib/quote.js +61 -0
  81. package/lib/quote.js.map +1 -0
  82. package/lib/websocket.d.ts +14 -0
  83. package/lib/websocket.d.ts.map +1 -0
  84. package/lib/websocket.js +83 -0
  85. package/lib/websocket.js.map +1 -0
  86. package/package.json +9 -4
  87. package/temp/image-tag +1 -0
  88. package/temp/package-deps.json +42 -0
  89. package/temp/vendor-okx.api.json +177 -0
  90. package/temp/vendor-okx.api.md +9 -0
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AACA,mBAAiB","sourcesContent":["#!/usr/bin/env node\nimport './index';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cluster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../src/cluster.ts"],"names":[],"mappings":""}
package/lib/cluster.js ADDED
@@ -0,0 +1,108 @@
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(`[Primary] ${(0, utils_1.formatTime)(Date.now())} 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.tap)({
53
+ error: (e) => {
54
+ console.error(`[Primary] ${(0, utils_1.formatTime)(Date.now())} Failed to load secrets`, e);
55
+ },
56
+ }), (0, rxjs_1.retry)({ delay: 5000 }), (0, rxjs_1.repeat)({ delay: 5000 }))
57
+ .pipe((0, utils_1.listWatch)((x) => x.secret.id, (account) => (0, rxjs_1.defer)(() => new rxjs_1.Observable((subscriber) => {
58
+ console.info((0, utils_1.formatTime)(Date.now()), `[Primary] ${(0, utils_1.formatTime)(Date.now())} Starting worker for account ${account.secret.public_data.name} (${account.secret.id})`);
59
+ if (account.secret.public_data.type !== 'api_key_okx')
60
+ return;
61
+ if (!account.secret.public_data.name)
62
+ return;
63
+ if (!account.decrypted_data)
64
+ return;
65
+ if (!account.decrypted_data.access_key)
66
+ return;
67
+ if (!account.decrypted_data.secret_key)
68
+ return;
69
+ if (!account.decrypted_data.passphrase)
70
+ return;
71
+ const worker = cluster_1.default.fork({
72
+ ENCRYPTION_KEY_BASE58: '',
73
+ ACCESS_KEY: account.decrypted_data.access_key,
74
+ SECRET_KEY: account.decrypted_data.secret_key,
75
+ PASSPHRASE: account.decrypted_data.passphrase,
76
+ WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',
77
+ TERMINAL_ID: `@yuants/vendor-okx/worker/${account.secret.public_data.name}`,
78
+ WORKER_LABEL: account.secret.public_data.name,
79
+ });
80
+ worker.on('message', (message) => {
81
+ if (message.type === 'log') {
82
+ logBuffer.next(`[Worker ${worker.process.pid} ${message.label}] ${message.level}: ${message.message}`);
83
+ }
84
+ });
85
+ worker.on('exit', (code, signal) => {
86
+ if (code === 0) {
87
+ console.info(`[Primary] ${(0, utils_1.formatTime)(Date.now())} Worker ${worker.process.pid} exited gracefully`);
88
+ subscriber.complete();
89
+ }
90
+ else {
91
+ console.error(`[Primary] ${(0, utils_1.formatTime)(Date.now())} Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`);
92
+ subscriber.error(new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`));
93
+ }
94
+ });
95
+ return () => {
96
+ worker.kill();
97
+ console.info(`[Primary] ${(0, utils_1.formatTime)(Date.now())} Worker ${worker.process.pid} killed`);
98
+ };
99
+ })).pipe(
100
+ //
101
+ (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.repeat)({ delay: 1000 })), (a, b) => a.secret.updated_at === b.secret.updated_at))
102
+ .subscribe();
103
+ }
104
+ else {
105
+ console.info(`${(0, utils_1.formatTime)(Date.now())} This is the worker process`, process.pid, process.env);
106
+ Promise.resolve().then(() => __importStar(require('./index')));
107
+ }
108
+ //# sourceMappingURL=cluster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../src/cluster.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,2CAA6C;AAC7C,yCAAsD;AACtD,sDAA8B;AAC9B,+BAA+F;AAC/F,qCAA2C;AAE3C,IAAA,wBAAe,GAAE,CAAC;AAElB,IAAI,iBAAO,CAAC,SAAS,EAAE;IACrB,OAAO,CAAC,IAAI,CAAC,aAAa,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,8BAA8B,CAAC,CAAC;IAEhF,MAAM,SAAS,GAAG,IAAI,cAAO,EAAU,CAAC;IAExC,SAAS;SACN,IAAI;IACH,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OAAO,CAAC,IAAI,CAAC,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,6BAA6B,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/F,kDAAO,SAAS,IAAE;CACnB","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { loadSecrets } from '@yuants/secret';\nimport { formatTime, listWatch } from '@yuants/utils';\nimport cluster from 'cluster';\nimport { bufferTime, defer, filter, map, Observable, repeat, retry, Subject, tap } from 'rxjs';\nimport { overrideConsole } from './logger';\n\noverrideConsole();\n\nif (cluster.isPrimary) {\n console.info(`[Primary] ${formatTime(Date.now())} 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; passphrase: string }>({\n terminal: Terminal.fromNodeEnv(),\n encryption_key_base58: process.env.ENCRYPTION_KEY_BASE58!,\n }),\n )\n .pipe(\n //\n tap({\n error: (e) => {\n console.error(`[Primary] ${formatTime(Date.now())} Failed to load secrets`, e);\n },\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 console.info(\n formatTime(Date.now()),\n `[Primary] ${formatTime(Date.now())} Starting worker for account ${\n account.secret.public_data.name\n } (${account.secret.id})`,\n );\n if (account.secret.public_data.type !== 'api_key_okx') 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 if (!account.decrypted_data.passphrase) 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 PASSPHRASE: account.decrypted_data.passphrase,\n WRITE_QUOTE_TO_SQL: account.secret.public_data.write_quote_to_sql ? 'true' : 'false',\n TERMINAL_ID: `@yuants/vendor-okx/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.info(\n `[Primary] ${formatTime(Date.now())} Worker ${worker.process.pid} exited gracefully`,\n );\n subscriber.complete();\n } else {\n console.error(\n `[Primary] ${formatTime(Date.now())} Worker ${\n worker.process.pid\n } 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.info(`[Primary] ${formatTime(Date.now())} 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(`${formatTime(Date.now())} This is the worker process`, process.pid, process.env);\n import('./index');\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { IExtensionContext } from '@yuants/extension';
2
+ declare const _default: (context: IExtensionContext) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+B,MAAM,mBAAmB,CAAC;kCAC1D,iBAAiB;AAA1C,wBAqFE"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const extension_1 = require("@yuants/extension");
4
+ exports.default = (context) => {
5
+ context.registerDeployProvider({
6
+ make_json_schema: () => ({
7
+ type: 'object',
8
+ properties: {
9
+ env: {
10
+ type: 'object',
11
+ required: ['HOST_URL'],
12
+ properties: {
13
+ //
14
+ PUBLIC_ONLY: { type: 'boolean' },
15
+ HOST_URL: { type: 'string' },
16
+ TERMINAL_ID: { type: 'string' },
17
+ ENCRYPTION_KEY_BASE58: { type: 'string' },
18
+ },
19
+ },
20
+ },
21
+ }),
22
+ make_docker_compose_file: async (ctx, envCtx) => {
23
+ var _a;
24
+ return {
25
+ [`okx-${ctx.env.ACCESS_KEY}`.replace(/\s/g, '')]: {
26
+ image: `ghcr.io/no-trade-no-life/vendor-okx:${(_a = ctx.version) !== null && _a !== void 0 ? _a : envCtx.version}`,
27
+ restart: 'always',
28
+ environment: (0, extension_1.makeDockerEnvs)(ctx.env),
29
+ },
30
+ };
31
+ },
32
+ make_k8s_resource_objects: async (ctx, envCtx) => {
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
34
+ return {
35
+ deployment: {
36
+ apiVersion: 'apps/v1',
37
+ kind: 'Deployment',
38
+ metadata: {
39
+ labels: {
40
+ 'y.ntnl.io/version': (_a = ctx.version) !== null && _a !== void 0 ? _a : envCtx.version,
41
+ 'y.ntnl.io/manifest_key': ctx.key,
42
+ 'y.ntnl.io/component': 'okx',
43
+ },
44
+ name: `okx-${ctx.key}`.replace(/\s/g, '').toLocaleLowerCase(),
45
+ namespace: 'yuan',
46
+ },
47
+ spec: {
48
+ replicas: 1,
49
+ selector: {
50
+ matchLabels: {
51
+ 'y.ntnl.io/component': 'okx',
52
+ 'y.ntnl.io/manifest_key': ctx.key,
53
+ },
54
+ },
55
+ template: {
56
+ metadata: {
57
+ labels: {
58
+ 'y.ntnl.io/version': (_b = ctx.version) !== null && _b !== void 0 ? _b : envCtx.version,
59
+ 'y.ntnl.io/manifest_key': ctx.key,
60
+ 'y.ntnl.io/component': 'okx',
61
+ },
62
+ },
63
+ spec: {
64
+ containers: [
65
+ {
66
+ env: (0, extension_1.makeK8sEnvs)(ctx.env),
67
+ image: `ghcr.io/no-trade-no-life/vendor-okx:${(_c = ctx.version) !== null && _c !== void 0 ? _c : envCtx.version}`,
68
+ imagePullPolicy: 'IfNotPresent',
69
+ name: 'okx',
70
+ resources: {
71
+ limits: {
72
+ cpu: (_e = (_d = ctx.cpu) === null || _d === void 0 ? void 0 : _d.max) !== null && _e !== void 0 ? _e : '500m',
73
+ memory: (_g = (_f = ctx.memory) === null || _f === void 0 ? void 0 : _f.max) !== null && _g !== void 0 ? _g : '256Mi',
74
+ },
75
+ requests: {
76
+ cpu: (_j = (_h = ctx.cpu) === null || _h === void 0 ? void 0 : _h.min) !== null && _j !== void 0 ? _j : '100m',
77
+ memory: (_l = (_k = ctx.memory) === null || _k === void 0 ? void 0 : _k.min) !== null && _l !== void 0 ? _l : '128Mi',
78
+ },
79
+ },
80
+ },
81
+ ],
82
+ hostname: 'okx',
83
+ },
84
+ },
85
+ },
86
+ },
87
+ };
88
+ },
89
+ });
90
+ };
91
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAAA,iDAAmF;AACnF,kBAAe,CAAC,OAA0B,EAAE,EAAE;IAC5C,OAAO,CAAC,sBAAsB,CAAC;QAC7B,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;YACvB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,EAAE;oBACH,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,CAAC,UAAU,CAAC;oBACtB,UAAU,EAAE;wBACV,EAAE;wBACF,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;wBAChC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBAC5B,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBAC/B,qBAAqB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;qBAC1C;iBACF;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iCAC7B;6BACF;4BACD,IAAI,EAAE;gCACJ,UAAU,EAAE;oCACV;wCACE,GAAG,EAAE,IAAA,uBAAW,EAAC,GAAG,CAAC,GAAG,CAAC;wCACzB,KAAK,EAAE,uCAAuC,MAAA,GAAG,CAAC,OAAO,mCAAI,MAAM,CAAC,OAAO,EAAE;wCAC7E,eAAe,EAAE,cAAc;wCAC/B,IAAI,EAAE,KAAK;wCACX,SAAS,EAAE;4CACT,MAAM,EAAE;gDACN,GAAG,EAAE,MAAA,MAAA,GAAG,CAAC,GAAG,0CAAE,GAAG,mCAAI,MAAM;gDAC3B,MAAM,EAAE,MAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,GAAG,mCAAI,OAAO;6CACnC;4CACD,QAAQ,EAAE;gDACR,GAAG,EAAE,MAAA,MAAA,GAAG,CAAC,GAAG,0CAAE,GAAG,mCAAI,MAAM;gDAC3B,MAAM,EAAE,MAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,GAAG,mCAAI,OAAO;6CACnC;yCACF;qCACF;iCACF;gCACD,QAAQ,EAAE,KAAK;6BAChB;yBACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { IExtensionContext, makeDockerEnvs, makeK8sEnvs } from '@yuants/extension';\nexport default (context: IExtensionContext) => {\n context.registerDeployProvider({\n make_json_schema: () => ({\n type: 'object',\n properties: {\n env: {\n type: 'object',\n required: ['HOST_URL'],\n properties: {\n //\n PUBLIC_ONLY: { type: 'boolean' },\n HOST_URL: { type: 'string' },\n TERMINAL_ID: { type: 'string' },\n ENCRYPTION_KEY_BASE58: { type: 'string' },\n },\n },\n },\n }),\n make_docker_compose_file: async (ctx, envCtx) => {\n return {\n [`okx-${ctx.env!.ACCESS_KEY}`.replace(/\\s/g, '')]: {\n image: `ghcr.io/no-trade-no-life/vendor-okx:${ctx.version ?? envCtx.version}`,\n restart: 'always',\n\n environment: makeDockerEnvs(ctx.env),\n },\n };\n },\n make_k8s_resource_objects: async (ctx, envCtx) => {\n return {\n deployment: {\n apiVersion: 'apps/v1',\n kind: 'Deployment',\n metadata: {\n labels: {\n 'y.ntnl.io/version': ctx.version ?? envCtx.version,\n 'y.ntnl.io/manifest_key': ctx.key,\n 'y.ntnl.io/component': 'okx',\n },\n name: `okx-${ctx.key}`.replace(/\\s/g, '').toLocaleLowerCase(),\n namespace: 'yuan',\n },\n spec: {\n replicas: 1,\n selector: {\n matchLabels: {\n 'y.ntnl.io/component': 'okx',\n 'y.ntnl.io/manifest_key': ctx.key,\n },\n },\n template: {\n metadata: {\n labels: {\n 'y.ntnl.io/version': ctx.version ?? envCtx.version,\n 'y.ntnl.io/manifest_key': ctx.key,\n 'y.ntnl.io/component': 'okx',\n },\n },\n spec: {\n containers: [\n {\n env: makeK8sEnvs(ctx.env),\n image: `ghcr.io/no-trade-no-life/vendor-okx:${ctx.version ?? envCtx.version}`,\n imagePullPolicy: 'IfNotPresent',\n name: 'okx',\n resources: {\n limits: {\n cpu: ctx.cpu?.max ?? '500m',\n memory: ctx.memory?.max ?? '256Mi',\n },\n requests: {\n cpu: ctx.cpu?.min ?? '100m',\n memory: ctx.memory?.min ?? '128Mi',\n },\n },\n },\n ],\n hostname: 'okx',\n },\n },\n },\n },\n };\n },\n });\n};\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import './interest_rate';
2
+ import './legacy_index';
3
+ import './ohlc';
4
+ import './quote';
5
+ import './account';
6
+ import './order';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,CAAC;AACxB,OAAO,QAAQ,CAAC;AAChB,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC;AACnB,OAAO,SAAS,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./interest_rate");
4
+ require("./legacy_index");
5
+ require("./ohlc");
6
+ require("./quote");
7
+ require("./account");
8
+ require("./order");
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,2BAAyB;AACzB,0BAAwB;AACxB,kBAAgB;AAChB,mBAAiB;AACjB,qBAAmB;AACnB,mBAAiB","sourcesContent":["import './interest_rate';\nimport './legacy_index';\nimport './ohlc';\nimport './quote';\nimport './account';\nimport './order';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interest_rate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":""}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
3
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
4
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
6
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
7
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
8
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
9
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
10
+ function fulfill(value) { resume("next", value); }
11
+ function reject(value) { resume("throw", value); }
12
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const data_series_1 = require("@yuants/data-series");
16
+ const protocol_1 = require("@yuants/protocol");
17
+ const sql_1 = require("@yuants/sql");
18
+ const utils_1 = require("@yuants/utils");
19
+ const rxjs_1 = require("rxjs");
20
+ const api_1 = require("./api");
21
+ const product_1 = require("./product");
22
+ (0, sql_1.createSQLWriter)(protocol_1.Terminal.fromNodeEnv(), {
23
+ data$: product_1.usdtSwapProducts$.pipe((0, rxjs_1.mergeAll)(), (0, rxjs_1.map)((x) => ({
24
+ series_id: (0, utils_1.encodePath)(x.datasource_id, x.product_id),
25
+ table_name: 'interest_rate',
26
+ cron_pattern: '0 * * * * *',
27
+ cron_timezone: 'UTC',
28
+ disabled: false,
29
+ replay_count: 0,
30
+ }))),
31
+ tableName: 'series_collecting_task',
32
+ writeInterval: 1000,
33
+ conflictKeys: ['series_id', 'table_name'],
34
+ });
35
+ (0, data_series_1.createSeriesProvider)(protocol_1.Terminal.fromNodeEnv(), {
36
+ tableName: 'interest_rate',
37
+ series_id_prefix_parts: ['OKX'],
38
+ reversed: true,
39
+ serviceOptions: { concurrent: 1 },
40
+ queryFn: function ({ series_id, started_at, ended_at }) {
41
+ return __asyncGenerator(this, arguments, function* () {
42
+ const start = started_at || 0;
43
+ const end = ended_at || Date.now();
44
+ const [datasource_id, product_id] = (0, utils_1.decodePath)(series_id);
45
+ const [instType, instId] = (0, utils_1.decodePath)(product_id);
46
+ if (instType === 'SWAP') {
47
+ let current_end = end;
48
+ while (true) {
49
+ // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点
50
+ const res = yield __await(api_1.client.getFundingRateHistory({
51
+ instId: instId,
52
+ after: `${current_end}`,
53
+ }));
54
+ if (res.code !== '0') {
55
+ throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;
56
+ }
57
+ // 如果没有数据了,就退出
58
+ if (res.data.length === 0) {
59
+ break;
60
+ }
61
+ console.info((0, utils_1.formatTime)(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));
62
+ const data = res.data.map((v) => ({
63
+ series_id: series_id,
64
+ product_id,
65
+ datasource_id,
66
+ created_at: (0, utils_1.formatTime)(+v.fundingTime),
67
+ long_rate: `${-v.fundingRate}`,
68
+ short_rate: `${v.fundingRate}`,
69
+ settlement_price: '',
70
+ }));
71
+ yield yield __await(data);
72
+ current_end = +res.data[res.data.length - 1].fundingTime;
73
+ if (current_end <= start) {
74
+ break;
75
+ }
76
+ // for API rate limit
77
+ yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
78
+ }
79
+ }
80
+ if (instType === 'MARGIN') {
81
+ // MARGIN/BTC-USDT
82
+ const [base, quote] = instId.split('-');
83
+ let current_end = end;
84
+ while (true) {
85
+ const resBase = yield __await(api_1.client.getLendingRateHistory({ ccy: base, after: `${current_end}` }));
86
+ const resQuote = yield __await(api_1.client.getLendingRateHistory({ ccy: quote, after: `${current_end}` }));
87
+ if (resBase.code !== '0') {
88
+ throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;
89
+ }
90
+ if (resBase.data.length === 0) {
91
+ break;
92
+ }
93
+ console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));
94
+ if (resQuote.code !== '0') {
95
+ throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;
96
+ }
97
+ if (resQuote.data.length === 0) {
98
+ break;
99
+ }
100
+ console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));
101
+ // 做多时,借入 quote 的资金,做空时,借入 base 的资金
102
+ // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate
103
+ const mapTsToBaseRate = new Map();
104
+ resBase.data.forEach((v) => {
105
+ mapTsToBaseRate.set(v.ts, v.rate);
106
+ });
107
+ const data = [];
108
+ resQuote.data.forEach((v) => {
109
+ if (!mapTsToBaseRate.has(v.ts))
110
+ return;
111
+ const long_rate = +v.rate / 365 / 24; // 转换为小时利率
112
+ const short_rate = +mapTsToBaseRate.get(v.ts) / 365 / 24; // 转换为小时利率
113
+ data.push({
114
+ series_id,
115
+ product_id,
116
+ datasource_id,
117
+ created_at: (0, utils_1.formatTime)(+v.ts),
118
+ long_rate: `${-long_rate}`,
119
+ short_rate: `${-short_rate}`,
120
+ settlement_price: '',
121
+ });
122
+ });
123
+ yield yield __await(data);
124
+ current_end = new Date(data[data.length - 1].created_at).getTime();
125
+ if (current_end <= start) {
126
+ break;
127
+ }
128
+ // for API rate limit
129
+ yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
130
+ }
131
+ }
132
+ });
133
+ },
134
+ });
135
+ //# sourceMappingURL=interest_rate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,+BAA+B;AAC/B,uCAA8C;AAE9C,IAAA,qBAAe,EAAwB,mBAAQ,CAAC,WAAW,EAAE,EAAE;IAC7D,KAAK,EAAE,2BAAiB,CAAC,IAAI,CAC3B,IAAA,eAAQ,GAAE,EACV,IAAA,UAAG,EACD,CAAC,CAAC,EAAyB,EAAE,CAAC,CAAC;QAC7B,SAAS,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,UAAU,CAAC;QACpD,UAAU,EAAE,eAAe;QAC3B,YAAY,EAAE,aAAa;QAC3B,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,CAAC;KAChB,CAAC,CACH,CACF;IACD,SAAS,EAAE,wBAAwB;IACnC,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;CAC1C,CAAC,CAAC;AAEH,IAAA,kCAAoB,EAAgB,mBAAQ,CAAC,WAAW,EAAE,EAAE;IAC1D,SAAS,EAAE,eAAe;IAC1B,sB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,UAAU;wBACrE,IAAI,CAAC,IAAI,CAAC;4BACR,SAAS;4BACT,UAAU;4BACV,aAAa;4BACb,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE;4BAC1B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;4BAC5B,gBAAgB,EAAE,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,oBAAM,IAAI,CAAA,CAAC;oBACX,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider, ISeriesCollectingTask } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, map, mergeAll, timer } from 'rxjs';\nimport { client } from './api';\nimport { usdtSwapProducts$ } from './product';\n\ncreateSQLWriter<ISeriesCollectingTask>(Terminal.fromNodeEnv(), {\n data$: usdtSwapProducts$.pipe(\n mergeAll(),\n map(\n (x): ISeriesCollectingTask => ({\n series_id: encodePath(x.datasource_id, x.product_id),\n table_name: 'interest_rate',\n cron_pattern: '0 * * * * *', // 每小时执行一次\n cron_timezone: 'UTC',\n disabled: false,\n replay_count: 0,\n }),\n ),\n ),\n tableName: 'series_collecting_task',\n writeInterval: 1000,\n conflictKeys: ['series_id', 'table_name'],\n});\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [datasource_id, product_id] = decodePath(series_id);\n const [instType, instId] = decodePath(product_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await client.getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id,\n datasource_id,\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await client.getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await client.getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id,\n datasource_id,\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=legacy_index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy_index.d.ts","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":""}