@yuants/vendor-huobi 0.14.5 → 0.15.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.
Files changed (163) hide show
  1. package/dist/__archived/account-info.js +45 -0
  2. package/dist/__archived/account-info.js.map +1 -0
  3. package/dist/__archived/api.js +51 -0
  4. package/dist/__archived/api.js.map +1 -0
  5. package/dist/__archived/transfer.js +285 -0
  6. package/dist/__archived/transfer.js.map +1 -0
  7. package/dist/index.js +3 -51
  8. package/dist/index.js.map +1 -1
  9. package/dist/{accounts → services/accounts}/spot.js +7 -4
  10. package/dist/services/accounts/spot.js.map +1 -0
  11. package/dist/{accounts → services/accounts}/super-margin.js +2 -2
  12. package/dist/services/accounts/super-margin.js.map +1 -0
  13. package/dist/services/accounts/swap.js +37 -0
  14. package/dist/services/accounts/swap.js.map +1 -0
  15. package/dist/services/exchange.js +75 -0
  16. package/dist/services/exchange.js.map +1 -0
  17. package/dist/services/market-data/interest_rate.js +63 -0
  18. package/dist/services/market-data/interest_rate.js.map +1 -0
  19. package/dist/{quote.js → services/market-data/quote.js} +9 -9
  20. package/dist/services/market-data/quote.js.map +1 -0
  21. package/dist/services/orders/listOrders.js +44 -0
  22. package/dist/services/orders/listOrders.js.map +1 -0
  23. package/dist/{orders → services/orders}/submitOrder.js +9 -8
  24. package/dist/services/orders/submitOrder.js.map +1 -0
  25. package/dist/{product.js → services/product.js} +16 -12
  26. package/dist/services/product.js.map +1 -0
  27. package/dist/{uid.js → services/uid.js} +1 -15
  28. package/dist/services/uid.js.map +1 -0
  29. package/lib/__archived/account-info.d.ts +1 -0
  30. package/lib/__archived/account-info.d.ts.map +1 -0
  31. package/lib/__archived/account-info.js +45 -0
  32. package/lib/__archived/account-info.js.map +1 -0
  33. package/lib/__archived/api.d.ts +1 -0
  34. package/lib/__archived/api.d.ts.map +1 -0
  35. package/lib/__archived/api.js +51 -0
  36. package/lib/__archived/api.js.map +1 -0
  37. package/lib/__archived/transfer.d.ts +1 -0
  38. package/lib/__archived/transfer.d.ts.map +1 -0
  39. package/lib/__archived/transfer.js +285 -0
  40. package/lib/__archived/transfer.js.map +1 -0
  41. package/lib/index.d.ts +3 -4
  42. package/lib/index.d.ts.map +1 -1
  43. package/lib/index.js +3 -51
  44. package/lib/index.js.map +1 -1
  45. package/lib/{accounts → services/accounts}/spot.d.ts +1 -1
  46. package/lib/services/accounts/spot.d.ts.map +1 -0
  47. package/lib/{accounts → services/accounts}/spot.js +7 -4
  48. package/lib/services/accounts/spot.js.map +1 -0
  49. package/lib/{accounts → services/accounts}/super-margin.d.ts +1 -1
  50. package/lib/services/accounts/super-margin.d.ts.map +1 -0
  51. package/lib/{accounts → services/accounts}/super-margin.js +2 -2
  52. package/lib/services/accounts/super-margin.js.map +1 -0
  53. package/lib/services/accounts/swap.d.ts +4 -0
  54. package/lib/services/accounts/swap.d.ts.map +1 -0
  55. package/lib/services/accounts/swap.js +41 -0
  56. package/lib/services/accounts/swap.js.map +1 -0
  57. package/lib/services/exchange.d.ts +2 -0
  58. package/lib/services/exchange.d.ts.map +1 -0
  59. package/lib/services/exchange.js +77 -0
  60. package/lib/services/exchange.js.map +1 -0
  61. package/lib/services/market-data/interest_rate.d.ts.map +1 -0
  62. package/lib/{interest_rate.js → services/market-data/interest_rate.js} +34 -30
  63. package/lib/services/market-data/interest_rate.js.map +1 -0
  64. package/lib/services/market-data/quote.d.ts.map +1 -0
  65. package/lib/{quote.js → services/market-data/quote.js} +9 -9
  66. package/lib/services/market-data/quote.js.map +1 -0
  67. package/lib/services/orders/listOrders.d.ts +4 -0
  68. package/lib/services/orders/listOrders.d.ts.map +1 -0
  69. package/lib/services/orders/listOrders.js +48 -0
  70. package/lib/services/orders/listOrders.js.map +1 -0
  71. package/lib/{orders → services/orders}/submitOrder.d.ts +1 -1
  72. package/lib/services/orders/submitOrder.d.ts.map +1 -0
  73. package/lib/{orders → services/orders}/submitOrder.js +7 -6
  74. package/lib/services/orders/submitOrder.js.map +1 -0
  75. package/lib/services/product.d.ts +4 -0
  76. package/lib/services/product.d.ts.map +1 -0
  77. package/lib/{product.js → services/product.js} +18 -13
  78. package/lib/services/product.js.map +1 -0
  79. package/lib/{uid.d.ts → services/uid.d.ts} +0 -5
  80. package/lib/services/uid.d.ts.map +1 -0
  81. package/lib/{uid.js → services/uid.js} +2 -17
  82. package/lib/services/uid.js.map +1 -0
  83. package/package.json +14 -13
  84. package/temp/package-deps.json +31 -33
  85. package/dist/account-actions-with-credentials.js +0 -30
  86. package/dist/account-actions-with-credentials.js.map +0 -1
  87. package/dist/account-info.js +0 -75
  88. package/dist/account-info.js.map +0 -1
  89. package/dist/accounts/list.js +0 -8
  90. package/dist/accounts/list.js.map +0 -1
  91. package/dist/accounts/spot.js.map +0 -1
  92. package/dist/accounts/super-margin.js.map +0 -1
  93. package/dist/accounts/swap.js +0 -80
  94. package/dist/accounts/swap.js.map +0 -1
  95. package/dist/api.js +0 -34
  96. package/dist/api.js.map +0 -1
  97. package/dist/cli.js +0 -3
  98. package/dist/cli.js.map +0 -1
  99. package/dist/interest_rate.js +0 -59
  100. package/dist/interest_rate.js.map +0 -1
  101. package/dist/order-actions-with-credentials.js +0 -15
  102. package/dist/order-actions-with-credentials.js.map +0 -1
  103. package/dist/order-actions.js +0 -17
  104. package/dist/order-actions.js.map +0 -1
  105. package/dist/orders/submitOrder.js.map +0 -1
  106. package/dist/product.js.map +0 -1
  107. package/dist/quote.js.map +0 -1
  108. package/dist/transfer.js +0 -248
  109. package/dist/transfer.js.map +0 -1
  110. package/dist/uid.js.map +0 -1
  111. package/lib/account-actions-with-credentials.d.ts +0 -2
  112. package/lib/account-actions-with-credentials.d.ts.map +0 -1
  113. package/lib/account-actions-with-credentials.js +0 -32
  114. package/lib/account-actions-with-credentials.js.map +0 -1
  115. package/lib/account-info.d.ts +0 -35
  116. package/lib/account-info.d.ts.map +0 -1
  117. package/lib/account-info.js +0 -83
  118. package/lib/account-info.js.map +0 -1
  119. package/lib/accounts/list.d.ts +0 -4
  120. package/lib/accounts/list.d.ts.map +0 -1
  121. package/lib/accounts/list.js +0 -12
  122. package/lib/accounts/list.js.map +0 -1
  123. package/lib/accounts/spot.d.ts.map +0 -1
  124. package/lib/accounts/spot.js.map +0 -1
  125. package/lib/accounts/super-margin.d.ts.map +0 -1
  126. package/lib/accounts/super-margin.js.map +0 -1
  127. package/lib/accounts/swap.d.ts +0 -4
  128. package/lib/accounts/swap.d.ts.map +0 -1
  129. package/lib/accounts/swap.js +0 -84
  130. package/lib/accounts/swap.js.map +0 -1
  131. package/lib/api.d.ts +0 -15
  132. package/lib/api.d.ts.map +0 -1
  133. package/lib/api.js +0 -41
  134. package/lib/api.js.map +0 -1
  135. package/lib/cli.d.ts +0 -3
  136. package/lib/cli.d.ts.map +0 -1
  137. package/lib/cli.js +0 -5
  138. package/lib/cli.js.map +0 -1
  139. package/lib/interest_rate.d.ts.map +0 -1
  140. package/lib/interest_rate.js.map +0 -1
  141. package/lib/order-actions-with-credentials.d.ts +0 -2
  142. package/lib/order-actions-with-credentials.d.ts.map +0 -1
  143. package/lib/order-actions-with-credentials.js +0 -17
  144. package/lib/order-actions-with-credentials.js.map +0 -1
  145. package/lib/order-actions.d.ts +0 -7
  146. package/lib/order-actions.d.ts.map +0 -1
  147. package/lib/order-actions.js +0 -21
  148. package/lib/order-actions.js.map +0 -1
  149. package/lib/orders/submitOrder.d.ts.map +0 -1
  150. package/lib/orders/submitOrder.js.map +0 -1
  151. package/lib/product.d.ts +0 -3
  152. package/lib/product.d.ts.map +0 -1
  153. package/lib/product.js.map +0 -1
  154. package/lib/quote.d.ts.map +0 -1
  155. package/lib/quote.js.map +0 -1
  156. package/lib/transfer.d.ts +0 -19
  157. package/lib/transfer.d.ts.map +0 -1
  158. package/lib/transfer.js +0 -255
  159. package/lib/transfer.js.map +0 -1
  160. package/lib/uid.d.ts.map +0 -1
  161. package/lib/uid.js.map +0 -1
  162. /package/lib/{interest_rate.d.ts → services/market-data/interest_rate.d.ts} +0 -0
  163. /package/lib/{quote.d.ts → services/market-data/quote.d.ts} +0 -0
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const exchange_1 = require("@yuants/exchange");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const utils_1 = require("@yuants/utils");
6
+ const private_api_1 = require("../api/private-api");
7
+ const spot_1 = require("./accounts/spot");
8
+ const super_margin_1 = require("./accounts/super-margin");
9
+ const swap_1 = require("./accounts/swap");
10
+ const listOrders_1 = require("./orders/listOrders");
11
+ const submitOrder_1 = require("./orders/submitOrder");
12
+ const product_1 = require("./product");
13
+ const terminal = protocol_1.Terminal.fromNodeEnv();
14
+ (0, exchange_1.provideExchangeServices)(terminal, {
15
+ name: 'HTX',
16
+ credentialSchema: {
17
+ type: 'object',
18
+ required: ['access_key', 'secret_key'],
19
+ properties: {
20
+ access_key: { type: 'string' },
21
+ secret_key: { type: 'string' },
22
+ },
23
+ },
24
+ getCredentialId: async (credential) => {
25
+ const res = await (0, private_api_1.getUid)(credential);
26
+ return (0, utils_1.encodePath)('HTX', res.data);
27
+ },
28
+ listProducts: product_1.listProducts,
29
+ getPositions: async (credential) => {
30
+ const [swap, spot, superMargin] = await Promise.all([
31
+ (0, swap_1.getSwapAccountInfo)(credential),
32
+ (0, spot_1.getSpotAccountInfo)(credential, 'spot'),
33
+ (0, super_margin_1.getSuperMarginAccountInfo)(credential, 'super-margin'),
34
+ ]);
35
+ return [...swap, ...spot, ...superMargin];
36
+ },
37
+ getOrders: async (credential) => {
38
+ const swapOrders = await (0, listOrders_1.listSwapOrders)(credential);
39
+ return swapOrders;
40
+ },
41
+ submitOrder: submitOrder_1.submitOrder,
42
+ cancelOrder: async (credential, order) => {
43
+ throw new Error('Not Implemented');
44
+ },
45
+ modifyOrder: async (credential, order) => {
46
+ throw new Error('Not Implemented');
47
+ },
48
+ getPositionsByProductId: async (credential, product_id) => {
49
+ const [, instType] = (0, utils_1.decodePath)(product_id);
50
+ if (instType === 'SPOT') {
51
+ const positions = await (0, spot_1.getSpotAccountInfo)(credential, product_id);
52
+ return positions.filter((pos) => pos.product_id === product_id);
53
+ }
54
+ if (instType === 'SWAP') {
55
+ const positions = await (0, swap_1.getSwapAccountInfo)(credential);
56
+ return positions.filter((pos) => pos.product_id === product_id);
57
+ }
58
+ if (instType === 'SUPER-MARGIN') {
59
+ const positions = await (0, super_margin_1.getSuperMarginAccountInfo)(credential, product_id);
60
+ return positions.filter((pos) => pos.product_id === product_id);
61
+ }
62
+ throw (0, utils_1.newError)('UnsupportedProductId', { product_id });
63
+ },
64
+ getOrdersByProductId: async (credential, product_id) => {
65
+ const [, instType] = (0, utils_1.decodePath)(product_id);
66
+ // if (instType === 'SPOT') {
67
+ // const orders = await listSpotOrders(credential, product_id);
68
+ // return orders.filter((order) => order.product_id === product_id);
69
+ // }
70
+ if (instType === 'SWAP') {
71
+ const orders = await (0, listOrders_1.listSwapOrders)(credential);
72
+ return orders.filter((order) => order.product_id === product_id);
73
+ }
74
+ throw (0, utils_1.newError)('UnsupportedProductId', { product_id });
75
+ },
76
+ });
77
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AACA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAAiE;AACjE,oDAAyD;AACzD,0CAAqD;AACrD,0DAAoE;AACpE,0CAAqD;AACrD,oDAAqD;AACrD,sDAAmD;AACnD,uCAAyC;AAEzC,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,KAAK;IACX,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;QACtC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9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sB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACzD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, encodePath, newError } from '@yuants/utils';\nimport { ICredential, getUid } from '../api/private-api';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getSuperMarginAccountInfo } from './accounts/super-margin';\nimport { getSwapAccountInfo } from './accounts/swap';\nimport { listSwapOrders } from './orders/listOrders';\nimport { submitOrder } from './orders/submitOrder';\nimport { listProducts } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'HTX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId: async (credential) => {\n const res = await getUid(credential);\n return encodePath('HTX', res.data);\n },\n listProducts,\n getPositions: async (credential) => {\n const [swap, spot, superMargin] = await Promise.all([\n getSwapAccountInfo(credential),\n getSpotAccountInfo(credential, 'spot'),\n getSuperMarginAccountInfo(credential, 'super-margin'),\n ]);\n return [...swap, ...spot, ...superMargin];\n },\n getOrders: async (credential) => {\n const swapOrders = await listSwapOrders(credential);\n return swapOrders;\n },\n submitOrder,\n cancelOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n modifyOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n getPositionsByProductId: async (credential, product_id) => {\n const [, instType] = decodePath(product_id);\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SWAP') {\n const positions = await getSwapAccountInfo(credential);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SUPER-MARGIN') {\n const positions = await getSuperMarginAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n getOrdersByProductId: async (credential: ICredential, product_id: string): Promise<IOrder[]> => {\n const [, instType] = decodePath(product_id);\n // if (instType === 'SPOT') {\n // const orders = await listSpotOrders(credential, product_id);\n // return orders.filter((order) => order.product_id === product_id);\n // }\n if (instType === 'SWAP') {\n const orders = await listSwapOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n});\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../../../src/services/market-data/interest_rate.ts"],"names":[],"mappings":""}
@@ -16,45 +16,49 @@ const data_series_1 = require("@yuants/data-series");
16
16
  const protocol_1 = require("@yuants/protocol");
17
17
  const utils_1 = require("@yuants/utils");
18
18
  const rxjs_1 = require("rxjs");
19
- const public_api_1 = require("./api/public-api");
19
+ const public_api_1 = require("../../api/public-api");
20
20
  (0, data_series_1.createSeriesProvider)(protocol_1.Terminal.fromNodeEnv(), {
21
21
  tableName: 'interest_rate',
22
- series_id_prefix_parts: ['HUOBI-SWAP'],
22
+ series_id_prefix_parts: ['HTX'],
23
23
  reversed: true,
24
24
  serviceOptions: { concurrent: 10 },
25
25
  queryFn: function ({ series_id, started_at }) {
26
26
  return __asyncGenerator(this, arguments, function* () {
27
27
  const [datasource_id, product_id] = (0, utils_1.decodePath)(series_id);
28
- let current_page = 0;
29
- let total_page = 1;
30
- while (true) {
31
- // 向前翻页,时间降序
32
- const res = yield __await((0, public_api_1.getSwapHistoricalFundingRate)({
33
- contract_code: product_id,
34
- page_index: current_page,
35
- }));
36
- if (res.status !== 'ok') {
37
- throw `API failed: ${res.status}`;
28
+ const [, instType] = (0, utils_1.decodePath)(product_id);
29
+ if (instType === 'SWAP') {
30
+ let current_page = 0;
31
+ let total_page = 1;
32
+ while (true) {
33
+ // 向前翻页,时间降序
34
+ const res = yield __await((0, public_api_1.getSwapHistoricalFundingRate)({
35
+ contract_code: product_id,
36
+ page_index: current_page,
37
+ }));
38
+ if (res.status !== 'ok') {
39
+ throw `API failed: ${res.status}`;
40
+ }
41
+ if (res.data.data.length === 0)
42
+ break;
43
+ yield yield __await(res.data.data.map((v) => ({
44
+ series_id,
45
+ datasource_id,
46
+ product_id,
47
+ created_at: (0, utils_1.formatTime)(+v.funding_time),
48
+ long_rate: `${-v.funding_rate}`,
49
+ short_rate: `${v.funding_rate}`,
50
+ settlement_price: '',
51
+ })));
52
+ total_page = res.data.total_page;
53
+ current_page++;
54
+ if (current_page >= total_page)
55
+ break;
56
+ if (+res.data.data[res.data.data.length - 1].funding_time <= started_at)
57
+ break;
58
+ yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
38
59
  }
39
- if (res.data.data.length === 0)
40
- break;
41
- yield yield __await(res.data.data.map((v) => ({
42
- series_id,
43
- datasource_id,
44
- product_id,
45
- created_at: (0, utils_1.formatTime)(+v.funding_time),
46
- long_rate: `${-v.funding_rate}`,
47
- short_rate: `${v.funding_rate}`,
48
- settlement_price: '',
49
- })));
50
- total_page = res.data.total_page;
51
- current_page++;
52
- if (current_page >= total_page)
53
- break;
54
- if (+res.data.data[res.data.data.length - 1].funding_time <= started_at)
55
- break;
56
- yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
57
60
  }
61
+ throw (0, utils_1.newError)('UNSUPPORTED_INST_TYPE', { instType });
58
62
  });
59
63
  },
60
64
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/market-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qDAA2D;AAC3D,+CAA4C;AAC5C,yCAAiE;AACjE,+BAA6C;AAC7C,qDAAoE;AAEpE,IAAA,kCAAoB,EAAgB,mBAAQ,CAAC,WAAW,EAAE,EAAE;IAC1D,SAAS,EAAE,eAAe;IAC1B,sBAAsB,EAAE,CAAC,KAAK,CAAC;IAC/B,QAAQ,EAAE,IAAI;IACd,cAA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AAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU;wBAAE,MAAM;oBAC/E,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;YACD,MAAM,IAAA,gBAAQ,EAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime, newError } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getSwapHistoricalFundingRate } from '../../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['HTX'],\n reversed: true,\n serviceOptions: { concurrent: 10 },\n queryFn: async function* ({ series_id, started_at }) {\n const [datasource_id, product_id] = decodePath(series_id);\n const [, instType] = decodePath(product_id);\n\n if (instType === 'SWAP') {\n let current_page = 0;\n let total_page = 1;\n while (true) {\n // 向前翻页,时间降序\n const res = await getSwapHistoricalFundingRate({\n contract_code: product_id,\n page_index: current_page,\n });\n if (res.status !== 'ok') {\n throw `API failed: ${res.status}`;\n }\n if (res.data.data.length === 0) break;\n yield res.data.data.map(\n (v): IInterestRate => ({\n series_id,\n datasource_id,\n product_id,\n created_at: formatTime(+v.funding_time),\n long_rate: `${-v.funding_rate}`,\n short_rate: `${v.funding_rate}`,\n settlement_price: '',\n }),\n );\n total_page = res.data.total_page;\n current_page++;\n if (current_page >= total_page) break;\n if (+res.data.data[res.data.data.length - 1].funding_time <= started_at) break;\n await firstValueFrom(timer(1000));\n }\n }\n throw newError('UNSUPPORTED_INST_TYPE', { instType });\n },\n});\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../../src/services/market-data/quote.ts"],"names":[],"mappings":""}
@@ -4,14 +4,14 @@ const protocol_1 = require("@yuants/protocol");
4
4
  const sql_1 = require("@yuants/sql");
5
5
  const utils_1 = require("@yuants/utils");
6
6
  const rxjs_1 = require("rxjs");
7
- const public_api_1 = require("./api/public-api");
7
+ const public_api_1 = require("../../api/public-api");
8
8
  const swapBboTick$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSwapMarketBbo)({})).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
9
9
  const quote1$ = swapBboTick$.pipe((0, rxjs_1.mergeMap)((res) => res.ticks || []), (0, rxjs_1.map)((tick) => {
10
10
  const [ask_price = '', ask_volume = ''] = tick.ask || [];
11
11
  const [bid_price = '', bid_volume = ''] = tick.bid || [];
12
12
  return {
13
- datasource_id: 'HUOBI-SWAP',
14
- product_id: tick.contract_code,
13
+ datasource_id: 'HTX',
14
+ product_id: (0, utils_1.encodePath)('HTX', 'SWAP', tick.contract_code),
15
15
  ask_price: `${ask_price}`,
16
16
  bid_price: `${bid_price}`,
17
17
  ask_volume: `${ask_volume}`,
@@ -21,15 +21,15 @@ const quote1$ = swapBboTick$.pipe((0, rxjs_1.mergeMap)((res) => res.ticks || [])
21
21
  const mapSwapContractCodeToBboTick$ = (0, rxjs_1.defer)(() => swapBboTick$).pipe((0, rxjs_1.mergeMap)((res) => (0, rxjs_1.from)(res.ticks).pipe((0, rxjs_1.map)((tick) => [tick.contract_code, tick]), (0, rxjs_1.toArray)(), (0, rxjs_1.map)((ticks) => Object.fromEntries(ticks)))), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
22
22
  const swapTradeTick$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSwapMarketTrade)({})).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
23
23
  const quote2$ = swapTradeTick$.pipe((0, rxjs_1.mergeMap)((res) => { var _a; return ((_a = res.tick) === null || _a === void 0 ? void 0 : _a.data) || []; }), (0, rxjs_1.map)((tick) => ({
24
- datasource_id: 'HUOBI-SWAP',
25
- product_id: tick.contract_code,
24
+ datasource_id: 'HTX',
25
+ product_id: (0, utils_1.encodePath)('HTX', 'SWAP', tick.contract_code),
26
26
  last_price: `${tick.price}`,
27
27
  })));
28
28
  const mapSwapContractCodeToTradeTick$ = (0, rxjs_1.defer)(() => swapTradeTick$).pipe((0, rxjs_1.mergeMap)((res) => (0, rxjs_1.from)(res.tick.data).pipe((0, rxjs_1.map)((tick) => [tick.contract_code, tick]), (0, rxjs_1.toArray)(), (0, rxjs_1.map)((ticks) => Object.fromEntries(ticks)))), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
29
29
  const swapFundingRateTick$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSwapBatchFundingRate)({})).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
30
30
  const quote3$ = swapFundingRateTick$.pipe((0, rxjs_1.mergeMap)((res) => res.data || []), (0, rxjs_1.map)((tick) => ({
31
- datasource_id: 'HUOBI-SWAP',
32
- product_id: tick.contract_code,
31
+ datasource_id: 'HTX',
32
+ product_id: (0, utils_1.encodePath)('HTX', 'SWAP', tick.contract_code),
33
33
  interest_rate_long: `${-tick.funding_rate}`,
34
34
  interest_rate_short: `${tick.funding_rate}`,
35
35
  interest_rate_next_settled_at: (0, utils_1.formatTime)(+tick.funding_time),
@@ -37,8 +37,8 @@ const quote3$ = swapFundingRateTick$.pipe((0, rxjs_1.mergeMap)((res) => res.data
37
37
  const mapSwapContractCodeToFundingRateTick$ = (0, rxjs_1.defer)(() => swapFundingRateTick$).pipe((0, rxjs_1.mergeMap)((res) => (0, rxjs_1.from)(res.data).pipe((0, rxjs_1.map)((tick) => [tick.contract_code, tick]), (0, rxjs_1.toArray)(), (0, rxjs_1.map)((ticks) => Object.fromEntries(ticks)))), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
38
38
  const swapOpenInterest$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSwapOpenInterest)({})).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
39
39
  const quote4$ = swapOpenInterest$.pipe((0, rxjs_1.mergeMap)((res) => res.data || []), (0, rxjs_1.map)((tick) => ({
40
- datasource_id: 'HUOBI-SWAP',
41
- product_id: tick.contract_code,
40
+ datasource_id: 'HTX',
41
+ product_id: (0, utils_1.encodePath)('HTX', 'SWAP', tick.contract_code),
42
42
  open_interest: `${tick.volume}`,
43
43
  })));
44
44
  if (process.env.WRITE_QUOTE_TO_SQL === 'true') {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/market-data/quote.ts"],"names":[],"mappings":";;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAA6G;AAC7G,qDAK8B;AAE9B,MAAM,YAAY,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,6BAAgB,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACzD,IAAA,aAAM,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,IAAA,YAAK,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,IAAA,kBAAW,EAAC,CAAC,CAAC,CACf,CAAC;AAEF,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAC/B,IAAA,eAAQ,EAAC,CAAC,GAAG,EAAE,EAA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ACtB,+BAA+B;AAC/B,4FAA4F;AAC5F,qBAAqB;AACrB,2CAA2C;AAC3C,0BAA0B;AAC1B,sCAAsC;AACtC,kFAAkF;AAClF,mDAAmD;AACnD,8DAA8D;AAC9D,8DAA8D;AAC9D,qDAAqD;AACrD,kFAAkF;AAClF,kFAAkF;AAClF,gEAAgE;AAChE,eAAe;AACf,cAAc;AACd,WAAW;AACX,SAAS;AACT,OAAO;AACP,MAAM","sourcesContent":["import { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, groupBy, map, merge, mergeMap, repeat, retry, scan, shareReplay, toArray } from 'rxjs';\nimport {\n getSwapBatchFundingRate,\n getSwapMarketBbo,\n getSwapMarketTrade,\n getSwapOpenInterest,\n} from '../../api/public-api';\n\nconst swapBboTick$ = defer(() => getSwapMarketBbo({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote1$ = swapBboTick$.pipe(\n mergeMap((res) => res.ticks || []),\n map((tick): Partial<IQuote> => {\n const [ask_price = '', ask_volume = ''] = tick.ask || [];\n const [bid_price = '', bid_volume = ''] = tick.bid || [];\n return {\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n ask_price: `${ask_price}`,\n bid_price: `${bid_price}`,\n ask_volume: `${ask_volume}`,\n bid_volume: `${bid_volume}`,\n };\n }),\n);\n\nconst mapSwapContractCodeToBboTick$ = defer(() => swapBboTick$).pipe(\n mergeMap((res) =>\n from(res.ticks).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst swapTradeTick$ = defer(() => getSwapMarketTrade({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote2$ = swapTradeTick$.pipe(\n mergeMap((res) => res.tick?.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n last_price: `${tick.price}`,\n }),\n ),\n);\n\nconst mapSwapContractCodeToTradeTick$ = defer(() => swapTradeTick$).pipe(\n mergeMap((res) =>\n from(res.tick.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\nconst swapFundingRateTick$ = defer(() => getSwapBatchFundingRate({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote3$ = swapFundingRateTick$.pipe(\n mergeMap((res) => res.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n interest_rate_long: `${-tick.funding_rate}`,\n interest_rate_short: `${tick.funding_rate}`,\n interest_rate_next_settled_at: formatTime(+tick.funding_time),\n }),\n ),\n);\n\nconst mapSwapContractCodeToFundingRateTick$ = defer(() => swapFundingRateTick$).pipe(\n mergeMap((res) =>\n from(res.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst swapOpenInterest$ = defer(() => getSwapOpenInterest({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote4$ = swapOpenInterest$.pipe(\n mergeMap((res) => res.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n open_interest: `${tick.volume}`,\n }),\n ),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n // 合并不同来源的数据并进行合并,避免死锁\n merge(quote1$, quote2$, quote3$, quote4$)\n .pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>));\n }),\n )\n .pipe(\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: 'quote',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n\nconst mapSwapContractCodeToOpenInterest$ = defer(() => swapOpenInterest$).pipe(\n mergeMap((res) =>\n from(res.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\n// provideTicks(Terminal.fromNodeEnv(), 'HUOBI-SWAP', (product_id) => {\n// return defer(async () => {\n// const products = await firstValueFrom(perpetualContractProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n\n// return [\n// of(theProduct),\n// mapSwapContractCodeToBboTick$,\n// mapSwapContractCodeToTradeTick$,\n// mapSwapContractCodeToFundingRateTick$,\n// mapSwapContractCodeToOpenInterest$,\n// ] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(([theProduct, bboTick, tradeTick, fundingRateTick, openInterest]): ITick => {\n// return {\n// datasource_id: 'HUOBI-SWAP',\n// product_id,\n// updated_at: Date.now(),\n// settlement_scheduled_at: +fundingRateTick[product_id].funding_time,\n// price: +tradeTick[product_id].price,\n// ask: bboTick[product_id].ask?.[0] ?? undefined,\n// bid: bboTick[product_id].bid?.[0] ?? undefined,\n// volume: +tradeTick[product_id].amount,\n// interest_rate_for_long: -+fundingRateTick[product_id].funding_rate,\n// interest_rate_for_short: +fundingRateTick[product_id].funding_rate,\n// open_interest: +openInterest[product_id]?.volume,\n// };\n// }),\n// ),\n// ),\n// );\n// });\n"]}
@@ -0,0 +1,4 @@
1
+ import { IOrder } from '@yuants/data-order';
2
+ import { ICredential } from '../../api/private-api';
3
+ export declare const listSwapOrders: (credential: ICredential) => Promise<IOrder[]>;
4
+ //# sourceMappingURL=listOrders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAqB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEvE,eAAO,MAAM,cAAc,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CA8C9E,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listSwapOrders = void 0;
4
+ const private_api_1 = require("../../api/private-api");
5
+ const listSwapOrders = async (credential) => {
6
+ var _a;
7
+ const orders = [];
8
+ let page_index = 1;
9
+ const page_size = 50;
10
+ while (true) {
11
+ const ordersRes = await (0, private_api_1.getSwapOpenOrders)(credential, { page_index, page_size });
12
+ if (!((_a = ordersRes.data) === null || _a === void 0 ? void 0 : _a.orders) || ordersRes.data.orders.length === 0) {
13
+ break;
14
+ }
15
+ const pageOrders = ordersRes.data.orders.map((v) => {
16
+ return {
17
+ order_id: v.order_id_str,
18
+ account_id: `huobi/swap`,
19
+ product_id: v.contract_code,
20
+ order_type: ['lightning'].includes(v.order_price_type)
21
+ ? 'MARKET'
22
+ : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(v.order_price_type)
23
+ ? 'LIMIT'
24
+ : ['fok'].includes(v.order_price_type)
25
+ ? 'FOK'
26
+ : v.order_price_type.includes('ioc')
27
+ ? 'IOC'
28
+ : 'STOP',
29
+ order_direction: v.direction === 'open'
30
+ ? v.offset === 'buy'
31
+ ? 'OPEN_LONG'
32
+ : 'OPEN_SHORT'
33
+ : v.offset === 'buy'
34
+ ? 'CLOSE_SHORT'
35
+ : 'CLOSE_LONG',
36
+ volume: v.volume,
37
+ submit_at: v.created_at,
38
+ price: v.price,
39
+ traded_volume: v.trade_volume,
40
+ };
41
+ });
42
+ orders.push(...pageOrders);
43
+ page_index++;
44
+ }
45
+ return orders;
46
+ };
47
+ exports.listSwapOrders = listSwapOrders;
48
+ //# sourceMappingURL=listOrders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,uDAAuE;AAEhE,MAAM,cAAc,GAAG,KAAK,EAAE,UAAuB,EAAqB,EAAE;;IACjF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,OAAO,IAAI,EAAE;QACX,MAAM,SAAS,GAAG,MAAM,IAAA,+BAAiB,EAAC,UAAU,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,CAAA,MAAA,SAAS,CAAC,IAAI,0CAAE,MAAM,CAAA,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACjE,MAAM;SACP;QAED,MAAM,UAAU,GAAa,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAU,EAAE;YACnE,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,YAAY;gBACxB,UAAU,EAAE,YAAY;gBACxB,UAAU,EAAE,CAAC,CAAC,aAAa;gBAC3B,UAAU,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;oBACpD,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,QAAQ,CAClF,CAAC,CAAC,gBAAgB,CACnB;wBACH,CAAC,CAAC,OAAO;wBACT,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;4BACtC,CAAC,CAAC,KAAK;4BACP,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC;gCACpC,CAAC,CAAC,KAAK;gCACP,CAAC,CAAC,MAAM;gBACV,eAAe,EACb,CAAC,CAAC,SAAS,KAAK,MAAM;oBACpB,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK;wBAClB,CAAC,CAAC,WAAW;wBACb,CAAC,CAAC,YAAY;oBAChB,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK;wBACpB,CAAC,CAAC,aAAa;wBACf,CAAC,CAAC,YAAY;gBAClB,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,SAAS,EAAE,CAAC,CAAC,UAAU;gBACvB,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,aAAa,EAAE,CAAC,CAAC,YAAY;aAC9B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;QAC3B,UAAU,EAAE,CAAC;KACd;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA9CW,QAAA,cAAc,kBA8CzB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { getSwapOpenOrders, ICredential } from '../../api/private-api';\n\nexport const listSwapOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const orders: IOrder[] = [];\n let page_index = 1;\n const page_size = 50;\n\n while (true) {\n const ordersRes = await getSwapOpenOrders(credential, { page_index, page_size });\n if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n break;\n }\n\n const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n return {\n order_id: v.order_id_str,\n account_id: `huobi/swap`, // Placeholder, will be adjusted if needed\n product_id: v.contract_code,\n order_type: ['lightning'].includes(v.order_price_type)\n ? 'MARKET'\n : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n v.order_price_type,\n )\n ? 'LIMIT'\n : ['fok'].includes(v.order_price_type)\n ? 'FOK'\n : v.order_price_type.includes('ioc')\n ? 'IOC'\n : 'STOP', // unreachable code\n order_direction:\n v.direction === 'open'\n ? v.offset === 'buy'\n ? 'OPEN_LONG'\n : 'OPEN_SHORT'\n : v.offset === 'buy'\n ? 'CLOSE_SHORT'\n : 'CLOSE_LONG',\n volume: v.volume,\n submit_at: v.created_at,\n price: v.price,\n traded_volume: v.trade_volume,\n };\n });\n\n orders.push(...pageOrders);\n page_index++;\n }\n return orders;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import { IOrder } from '@yuants/data-order';
2
- import { ICredential } from '../api/private-api';
2
+ import { ICredential } from '../../api/private-api';
3
3
  export declare const submitOrder: (credential: ICredential, order: IOrder) => Promise<{
4
4
  order_id: string;
5
5
  }>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EACL,WAAW,EAMZ,MAAM,uBAAuB,CAAC;AAqG/B,eAAO,MAAM,WAAW,eAAgB,WAAW,SAAS,MAAM,KAAG,QAAQ;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAShG,CAAC"}
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.submitOrder = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const rxjs_1 = require("rxjs");
6
- const private_api_1 = require("../api/private-api");
7
- const public_api_1 = require("../api/public-api");
6
+ const private_api_1 = require("../../api/private-api");
7
+ const public_api_1 = require("../../api/public-api");
8
8
  const product_1 = require("../product");
9
9
  const uid_1 = require("../uid");
10
10
  /**
@@ -50,7 +50,7 @@ async function handleSuperMarginOrder(order, credential) {
50
50
  // 获取账户余额, 产品信息和价格
51
51
  const [balanceRes, mapProductIdToProduct, priceRes] = await Promise.all([
52
52
  (0, private_api_1.getSpotAccountBalance)(credential, superMarginAccountUid),
53
- (0, rxjs_1.firstValueFrom)(product_1.spotProductService.mapProductIdToProduct$),
53
+ (0, rxjs_1.firstValueFrom)(product_1.productService.mapProductIdToProduct$),
54
54
  (0, public_api_1.getSpotTick)({ symbol: order.product_id }),
55
55
  ]);
56
56
  const balance = balanceRes.data.list
@@ -86,13 +86,14 @@ async function handleSuperMarginOrder(order, credential) {
86
86
  return { order_id: result.data.orderId.toString() };
87
87
  }
88
88
  const submitOrder = (credential, order) => {
89
- if (order.account_id.includes('swap')) {
89
+ const [, instType] = (0, utils_1.decodePath)(order.product_id);
90
+ if (instType === 'SWAP') {
90
91
  return handleSwapOrder(order, credential);
91
92
  }
92
- if (order.account_id.includes('super-margin')) {
93
+ if (instType === 'SUPER-MARGIN') {
93
94
  return handleSuperMarginOrder(order, credential);
94
95
  }
95
- throw new Error(`Unsupported account_id for order submission: ${order.account_id}`);
96
+ throw (0, utils_1.newError)('UNSUPPORTED_INST_TYPE', { order_type: instType });
96
97
  };
97
98
  exports.submitOrder = submitOrder;
98
99
  //# sourceMappingURL=submitOrder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAA8E;AAC9E,+BAAsC;AACtC,uDAO+B;AAC/B,qDAAmD;AACnD,wCAA4C;AAC5C,gCAAoD;AAEpD;;GAEG;AACH,KAAK,UAAU,eAAe,CAAC,KAAa,EAAE,UAAuB;;IACnE,SAAS;IACT,MAAM,YAAY,GAAG,MAAM,IAAA,sCAAwB,EAAC,UAAU,CAAC,CAA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pE,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, newError, roundToStep } from '@yuants/utils';\nimport { firstValueFrom } from 'rxjs';\nimport {\n ICredential,\n getCrossMarginLoanInfo,\n getSpotAccountBalance,\n getSwapCrossPositionInfo,\n postSpotOrder,\n postSwapOrder,\n} from '../../api/private-api';\nimport { getSpotTick } from '../../api/public-api';\nimport { productService } from '../product';\nimport { superMarginAccountUidCache } from '../uid';\n\n/**\n * 处理 swap 账户订单提交\n */\nasync function handleSwapOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取仓位信息\n const positionInfo = await getSwapCrossPositionInfo(credential);\n const mapContractCodeToRate = Object.fromEntries(\n positionInfo.data.map((v) => [v.contract_code, v.lever_rate]),\n );\n\n const lever_rate = mapContractCodeToRate[order.product_id] ?? 20;\n const params = {\n contract_code: order.product_id,\n contract_type: 'swap',\n price: order.price,\n volume: order.volume,\n offset:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'OPEN_SHORT' ? 'open' : 'close',\n direction:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell',\n // dynamically adjust the leverage\n lever_rate,\n order_price_type: order.order_type === 'MARKET' ? 'market' : 'limit',\n };\n\n const result = await postSwapOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.status !== 'ok') {\n throw new Error(`Failed to submit swap order: status=${result.status}`);\n }\n return { order_id: result.data.order_id_str };\n}\n\n/**\n * 处理 super-margin 账户订单提交\n */\nasync function handleSuperMarginOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取可贷款金额\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Super margin account UID not found');\n const loanInfo = await getCrossMarginLoanInfo(credential);\n const usdtLoanable = loanInfo.data.find((v) => v.currency === 'usdt');\n if (!usdtLoanable) throw new Error('USDT loanable amount not found');\n const loanable = +usdtLoanable['loanable-amt'];\n\n // 获取账户余额, 产品信息和价格\n const [balanceRes, mapProductIdToProduct, priceRes] = await Promise.all([\n getSpotAccountBalance(credential, superMarginAccountUid),\n firstValueFrom(productService.mapProductIdToProduct$),\n getSpotTick({ symbol: order.product_id }),\n ]);\n\n const balance = balanceRes.data.list\n .filter((v) => v.currency === 'usdt' && v.type === 'trade')\n .reduce((acc, cur) => acc + +cur.balance, 0);\n\n if (!mapProductIdToProduct) throw new Error('Product map not found');\n\n const theProduct = mapProductIdToProduct.get(order.product_id);\n const price = priceRes.tick.close;\n const borrow_amount =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? Math.max(Math.min(loanable, order.volume * price - balance), 0)\n : undefined;\n\n const params = {\n symbol: order.product_id,\n 'account-id': '' + superMarginAccountUid,\n amount:\n '' +\n (order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? roundToStep(order.volume * price, theProduct?.volume_step!)\n : order.volume),\n 'borrow-amount': '' + borrow_amount,\n type: `${\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell'\n }-${'LIMIT' === order.order_type ? 'limit' : 'market'}`,\n 'trade-purpose':\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? '1' // auto borrow\n : '2', // auto repay\n price: order.order_type === 'MARKET' ? undefined : '' + order.price,\n source: 'super-margin-api',\n };\n\n const result = await postSpotOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.success === false) {\n throw new Error(`Failed to submit super margin order: code=${result.code} message=${result.message}`);\n }\n\n return { order_id: result.data.orderId.toString() };\n}\n\nexport const submitOrder = (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [, instType] = decodePath(order.product_id);\n if (instType === 'SWAP') {\n return handleSwapOrder(order, credential);\n }\n if (instType === 'SUPER-MARGIN') {\n return handleSuperMarginOrder(order, credential);\n }\n throw newError('UNSUPPORTED_INST_TYPE', { order_type: instType });\n};\n"]}
@@ -0,0 +1,4 @@
1
+ import { IProduct } from '@yuants/data-product';
2
+ export declare const listProducts: () => Promise<IProduct[]>;
3
+ export declare const productService: import("@yuants/data-product").IQueryProductsService;
4
+ //# sourceMappingURL=product.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../src/services/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA+B,MAAM,sBAAsB,CAAC;AAoF7E,eAAO,MAAM,YAAY,QAAa,QAAQ,QAAQ,EAAE,CAGvD,CAAC;AAEF,eAAO,MAAM,cAAc,sDAEzB,CAAC"}
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.spotProductService = exports.swapProductService = void 0;
3
+ exports.productService = exports.listProducts = void 0;
4
4
  const data_product_1 = require("@yuants/data-product");
5
5
  const protocol_1 = require("@yuants/protocol");
6
- const public_api_1 = require("./api/public-api");
6
+ const utils_1 = require("@yuants/utils");
7
+ const public_api_1 = require("../api/public-api");
7
8
  const terminal = protocol_1.Terminal.fromNodeEnv();
8
9
  // Provide QueryProducts service for swap products
9
- exports.swapProductService = (0, data_product_1.provideQueryProductsService)(terminal, 'HUOBI-SWAP', async (req) => {
10
+ const listSwapProducts = async () => {
10
11
  var _a;
11
12
  const products = [];
12
13
  // Get perpetual contract products and cross leverage data in parallel
@@ -19,8 +20,8 @@ exports.swapProductService = (0, data_product_1.provideQueryProductsService)(ter
19
20
  continue; // Only include active contracts
20
21
  const maxLeverage = (_a = crossLeverage === null || crossLeverage === void 0 ? void 0 : crossLeverage.data.find((x) => x.contract_code === symbol.contract_code)) === null || _a === void 0 ? void 0 : _a.list.reduce((acc, cur) => Math.max(acc, cur.lever_rate), 1);
21
22
  products.push({
22
- datasource_id: 'HUOBI-SWAP',
23
- product_id: symbol.contract_code,
23
+ datasource_id: 'HTX',
24
+ product_id: (0, utils_1.encodePath)('HTX', 'SWAP', symbol.contract_code),
24
25
  base_currency: symbol.symbol,
25
26
  quote_currency: 'USDT',
26
27
  value_scale: symbol.contract_size,
@@ -35,16 +36,14 @@ exports.swapProductService = (0, data_product_1.provideQueryProductsService)(ter
35
36
  max_volume: 0,
36
37
  allow_long: true,
37
38
  allow_short: true,
38
- market_id: 'HUOBI/SWAP',
39
+ market_id: 'HTX',
39
40
  no_interest_rate: false,
40
41
  });
41
42
  }
42
43
  return products;
43
- }, {
44
- auto_refresh_interval: 3600000,
45
- });
44
+ };
46
45
  // Provide QueryProducts service for spot products
47
- exports.spotProductService = (0, data_product_1.provideQueryProductsService)(terminal, 'HUOBI-SPOT', async (req) => {
46
+ const listSpotProducts = async () => {
48
47
  const products = [];
49
48
  // Get spot products
50
49
  const spotSymbols = await (0, public_api_1.getSpotSymbols)();
@@ -52,8 +51,8 @@ exports.spotProductService = (0, data_product_1.provideQueryProductsService)(ter
52
51
  if (symbol.state !== 'online')
53
52
  continue; // Only include online symbols
54
53
  products.push({
55
- datasource_id: 'HUOBI-SPOT',
56
- product_id: symbol.sc,
54
+ datasource_id: 'HTX',
55
+ product_id: (0, utils_1.encodePath)('HTX', 'SPOT', symbol.sc),
57
56
  base_currency: symbol.bc,
58
57
  quote_currency: symbol.qc,
59
58
  value_scale: 1,
@@ -73,7 +72,13 @@ exports.spotProductService = (0, data_product_1.provideQueryProductsService)(ter
73
72
  });
74
73
  }
75
74
  return products;
76
- }, {
75
+ };
76
+ const listProducts = async () => {
77
+ const [swapProducts, spotProducts] = await Promise.all([listSwapProducts(), listSpotProducts()]);
78
+ return [...swapProducts, ...spotProducts];
79
+ };
80
+ exports.listProducts = listProducts;
81
+ exports.productService = (0, data_product_1.provideQueryProductsService)(terminal, 'HTX', exports.listProducts, {
77
82
  auto_refresh_interval: 3600000,
78
83
  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ACnB,iBAAiB,EAAE,CAAC;YACpB,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,YAAY;YACvB,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;KACJ;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEK,MAAM,YAAY,GAAG,KAAK,IAAyB,EAAE;IAC1D,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;IACjG,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,YAAY,CAAC,CAAC;AAC5C,CAAC,CAAC;AAHW,QAAA,YAAY,gBAGvB;AAEW,QAAA,cAAc,GAAG,IAAA,0CAA2B,EAAC,QAAQ,EAAE,KAAK,EAAE,oBAAY,EAAE;IACvF,qBAAqB,EAAE,OAAQ;CAChC,CAAC,CAAC","sourcesContent":["import { IProduct, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getPerpetualContractSymbols, getSpotSymbols, getSwapCrossLadderMargin } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// Provide QueryProducts service for swap products\nconst listSwapProducts = async (): Promise<IProduct[]> => {\n const products: IProduct[] = [];\n\n // Get perpetual contract products and cross leverage data in parallel\n const [swapSymbols, crossLeverage] = await Promise.all([\n getPerpetualContractSymbols(),\n getSwapCrossLadderMargin(),\n ]);\n\n for (const symbol of swapSymbols?.data || []) {\n if (symbol.contract_status !== 1) continue; // Only include active contracts\n\n const maxLeverage = crossLeverage?.data\n .find((x) => x.contract_code === symbol.contract_code)\n ?.list.reduce((acc, cur) => Math.max(acc, cur.lever_rate), 1);\n\n products.push({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', symbol.contract_code),\n base_currency: symbol.symbol,\n quote_currency: 'USDT',\n value_scale: symbol.contract_size,\n price_step: symbol.price_tick,\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / (maxLeverage || 1),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'HTX',\n no_interest_rate: false,\n });\n }\n\n return products;\n};\n\n// Provide QueryProducts service for spot products\nconst listSpotProducts = async (): Promise<IProduct[]> => {\n const products: IProduct[] = [];\n\n // Get spot products\n const spotSymbols = await getSpotSymbols();\n\n for (const symbol of spotSymbols?.data || []) {\n if (symbol.state !== 'online') continue; // Only include online symbols\n\n products.push({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SPOT', symbol.sc),\n base_currency: symbol.bc,\n quote_currency: symbol.qc,\n value_scale: 1,\n price_step: 1 / 10 ** symbol.tpp,\n volume_step: 1 / 10 ** symbol.tap,\n name: '',\n value_scale_unit: '',\n margin_rate: 1,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'HUOBI/SPOT',\n no_interest_rate: true,\n });\n }\n\n return products;\n};\n\nexport const listProducts = async (): Promise<IProduct[]> => {\n const [swapProducts, spotProducts] = await Promise.all([listSwapProducts(), listSpotProducts()]);\n return [...swapProducts, ...spotProducts];\n};\n\nexport const productService = provideQueryProductsService(terminal, 'HTX', listProducts, {\n auto_refresh_interval: 3600_000,\n});\n"]}
@@ -4,9 +4,4 @@ export declare const uidCache: import("@yuants/cache").ICache<{
4
4
  }>;
5
5
  export declare const superMarginAccountUidCache: import("@yuants/cache").ICache<number>;
6
6
  export declare const spotAccountUidCache: import("@yuants/cache").ICache<number>;
7
- export declare const getAccountIds: (key: string) => Promise<{
8
- spot: string;
9
- superMargin: string;
10
- swap: string;
11
- }>;
12
7
  //# sourceMappingURL=uid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/services/uid.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ;;;EAAgD,CAAC;AAItE,eAAO,MAAM,0BAA0B,wCAEtC,CAAC;AAEF,eAAO,MAAM,mBAAmB,wCAE/B,CAAC"}
@@ -1,25 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAccountIds = exports.spotAccountUidCache = exports.superMarginAccountUidCache = exports.uidCache = void 0;
3
+ exports.spotAccountUidCache = exports.superMarginAccountUidCache = exports.uidCache = void 0;
4
4
  const cache_1 = require("@yuants/cache");
5
- const private_api_1 = require("./api/private-api");
5
+ const private_api_1 = require("../api/private-api");
6
6
  exports.uidCache = (0, cache_1.createCache)((key) => (0, private_api_1.getUid)(JSON.parse(key)));
7
7
  const huobiAccounts = (0, cache_1.createCache)((key) => (0, private_api_1.getAccount)(JSON.parse(key)));
8
8
  exports.superMarginAccountUidCache = (0, cache_1.createCache)((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'super-margin')) === null || _a === void 0 ? void 0 : _a.id; }));
9
9
  exports.spotAccountUidCache = (0, cache_1.createCache)((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'spot')) === null || _a === void 0 ? void 0 : _a.id; }));
10
- const getAccountIds = async (key) => {
11
- const uid = await exports.uidCache.query(key);
12
- if (!uid)
13
- throw new Error('Failed to get UID');
14
- const account_id = `huobi/${uid}`;
15
- const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;
16
- const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;
17
- const SWAP_ACCOUNT_ID = `${account_id}/swap`;
18
- return {
19
- spot: SPOT_ACCOUNT_ID,
20
- superMargin: SUPER_MARGIN_ACCOUNT_ID,
21
- swap: SWAP_ACCOUNT_ID,
22
- };
23
- };
24
- exports.getAccountIds = getAccountIds;
25
10
  //# sourceMappingURL=uid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/services/uid.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,oDAAwD;AAE3C,QAAA,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,oBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtE,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,wBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAE3D,QAAA,0BAA0B,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAC5D,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACzF,CAAC;AAEW,QAAA,mBAAmB,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CACrD,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACjF,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccount, getUid } from '../api/private-api';\n\nexport const uidCache = createCache((key) => getUid(JSON.parse(key)));\n\nconst huobiAccounts = createCache((key) => getAccount(JSON.parse(key)));\n\nexport const superMarginAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'super-margin')?.id),\n);\n\nexport const spotAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'spot')?.id),\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-huobi",
3
- "version": "0.14.5",
3
+ "version": "0.15.0",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -8,17 +8,18 @@
8
8
  "temp"
9
9
  ],
10
10
  "dependencies": {
11
- "@yuants/protocol": "0.52.1",
12
- "@yuants/data-account": "0.8.1",
13
- "@yuants/data-order": "0.6.3",
14
- "@yuants/transfer": "0.2.36",
15
- "@yuants/utils": "0.12.0",
16
- "@yuants/cache": "0.3.1",
17
- "@yuants/sql": "0.9.27",
18
- "@yuants/data-product": "0.4.18",
19
- "@yuants/data-series": "0.3.48",
20
- "@yuants/data-interest-rate": "0.1.45",
21
- "@yuants/data-quote": "0.2.40",
11
+ "@yuants/protocol": "0.53.0",
12
+ "@yuants/data-account": "0.8.2",
13
+ "@yuants/data-order": "0.6.4",
14
+ "@yuants/transfer": "0.2.37",
15
+ "@yuants/utils": "0.13.0",
16
+ "@yuants/cache": "0.3.2",
17
+ "@yuants/sql": "0.9.28",
18
+ "@yuants/data-product": "0.4.19",
19
+ "@yuants/data-series": "0.3.49",
20
+ "@yuants/data-interest-rate": "0.1.46",
21
+ "@yuants/data-quote": "0.2.41",
22
+ "@yuants/exchange": "0.1.0",
22
23
  "rxjs": "~7.5.6",
23
24
  "crypto-js": "^4.2.0"
24
25
  },
@@ -29,7 +30,7 @@
29
30
  "@rushstack/heft-node-rig": "~1.10.7",
30
31
  "@types/heft-jest": "1.0.3",
31
32
  "@types/node": "22",
32
- "@yuants/extension": "0.2.29",
33
+ "@yuants/extension": "0.2.30",
33
34
  "@yuants/tool-kit": "0.2.1",
34
35
  "typescript": "~4.7.4"
35
36
  },