@yuants/vendor-binance 0.8.7 → 0.10.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 (110) hide show
  1. package/dist/api/client.js +14 -5
  2. package/dist/api/client.js.map +1 -1
  3. package/dist/api/public-api.js +6 -0
  4. package/dist/api/public-api.js.map +1 -1
  5. package/dist/index.js +1 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/legacy_index.js +163 -400
  8. package/dist/legacy_index.js.map +1 -1
  9. package/dist/public-data/interest_rate.js +5 -3
  10. package/dist/public-data/interest_rate.js.map +1 -1
  11. package/dist/public-data/ohlc.js +1 -1
  12. package/dist/public-data/ohlc.js.map +1 -1
  13. package/dist/public-data/product.js +83 -4
  14. package/dist/public-data/product.js.map +1 -1
  15. package/dist/public-data/quote.js +7 -7
  16. package/dist/public-data/quote.js.map +1 -1
  17. package/dist/services/accounts/profile.js +4 -15
  18. package/dist/services/accounts/profile.js.map +1 -1
  19. package/dist/services/accounts/spot.js +1 -1
  20. package/dist/services/accounts/spot.js.map +1 -1
  21. package/dist/services/accounts/unified.js +2 -12
  22. package/dist/services/accounts/unified.js.map +1 -1
  23. package/dist/services/exchange.js +56 -0
  24. package/dist/services/exchange.js.map +1 -0
  25. package/dist/services/orders/cancelOrder.js +5 -3
  26. package/dist/services/orders/cancelOrder.js.map +1 -1
  27. package/dist/services/orders/listOrders.js +44 -35
  28. package/dist/services/orders/listOrders.js.map +1 -1
  29. package/dist/services/orders/modifyOrder.js +6 -3
  30. package/dist/services/orders/modifyOrder.js.map +1 -1
  31. package/dist/services/orders/order-utils.js +29 -7
  32. package/dist/services/orders/order-utils.js.map +1 -1
  33. package/dist/services/orders/submitOrder.js +5 -3
  34. package/dist/services/orders/submitOrder.js.map +1 -1
  35. package/lib/api/client.d.ts.map +1 -1
  36. package/lib/api/client.js +13 -7
  37. package/lib/api/client.js.map +1 -1
  38. package/lib/api/public-api.d.ts +41 -0
  39. package/lib/api/public-api.d.ts.map +1 -1
  40. package/lib/api/public-api.js +8 -1
  41. package/lib/api/public-api.js.map +1 -1
  42. package/lib/index.d.ts +1 -2
  43. package/lib/index.d.ts.map +1 -1
  44. package/lib/index.js +1 -2
  45. package/lib/index.js.map +1 -1
  46. package/lib/legacy_index.d.ts +0 -1
  47. package/lib/legacy_index.js +162 -401
  48. package/lib/legacy_index.js.map +1 -1
  49. package/lib/public-data/interest_rate.js +5 -3
  50. package/lib/public-data/interest_rate.js.map +1 -1
  51. package/lib/public-data/ohlc.js +1 -1
  52. package/lib/public-data/ohlc.js.map +1 -1
  53. package/lib/public-data/product.d.ts +2 -1
  54. package/lib/public-data/product.d.ts.map +1 -1
  55. package/lib/public-data/product.js +84 -3
  56. package/lib/public-data/product.js.map +1 -1
  57. package/lib/public-data/quote.js +7 -7
  58. package/lib/public-data/quote.js.map +1 -1
  59. package/lib/services/accounts/profile.d.ts +1 -5
  60. package/lib/services/accounts/profile.d.ts.map +1 -1
  61. package/lib/services/accounts/profile.js +6 -17
  62. package/lib/services/accounts/profile.js.map +1 -1
  63. package/lib/services/accounts/spot.d.ts +2 -2
  64. package/lib/services/accounts/spot.d.ts.map +1 -1
  65. package/lib/services/accounts/spot.js +1 -1
  66. package/lib/services/accounts/spot.js.map +1 -1
  67. package/lib/services/accounts/unified.d.ts +2 -2
  68. package/lib/services/accounts/unified.d.ts.map +1 -1
  69. package/lib/services/accounts/unified.js +2 -12
  70. package/lib/services/accounts/unified.js.map +1 -1
  71. package/lib/services/exchange.d.ts +2 -0
  72. package/lib/services/exchange.d.ts.map +1 -0
  73. package/lib/services/exchange.js +58 -0
  74. package/lib/services/exchange.js.map +1 -0
  75. package/lib/services/orders/cancelOrder.d.ts.map +1 -1
  76. package/lib/services/orders/cancelOrder.js +5 -3
  77. package/lib/services/orders/cancelOrder.js.map +1 -1
  78. package/lib/services/orders/listOrders.d.ts +4 -2
  79. package/lib/services/orders/listOrders.d.ts.map +1 -1
  80. package/lib/services/orders/listOrders.js +47 -36
  81. package/lib/services/orders/listOrders.js.map +1 -1
  82. package/lib/services/orders/modifyOrder.d.ts.map +1 -1
  83. package/lib/services/orders/modifyOrder.js +6 -3
  84. package/lib/services/orders/modifyOrder.js.map +1 -1
  85. package/lib/services/orders/order-utils.d.ts.map +1 -1
  86. package/lib/services/orders/order-utils.js +29 -7
  87. package/lib/services/orders/order-utils.js.map +1 -1
  88. package/lib/services/orders/submitOrder.d.ts.map +1 -1
  89. package/lib/services/orders/submitOrder.js +5 -3
  90. package/lib/services/orders/submitOrder.js.map +1 -1
  91. package/package.json +2 -1
  92. package/temp/package-deps.json +23 -24
  93. package/dist/cli.js +0 -3
  94. package/dist/cli.js.map +0 -1
  95. package/dist/services/account-actions-with-credential.js +0 -34
  96. package/dist/services/account-actions-with-credential.js.map +0 -1
  97. package/dist/services/order-actions-with-credential.js +0 -21
  98. package/dist/services/order-actions-with-credential.js.map +0 -1
  99. package/lib/cli.d.ts +0 -3
  100. package/lib/cli.d.ts.map +0 -1
  101. package/lib/cli.js +0 -5
  102. package/lib/cli.js.map +0 -1
  103. package/lib/services/account-actions-with-credential.d.ts +0 -2
  104. package/lib/services/account-actions-with-credential.d.ts.map +0 -1
  105. package/lib/services/account-actions-with-credential.js +0 -36
  106. package/lib/services/account-actions-with-credential.js.map +0 -1
  107. package/lib/services/order-actions-with-credential.d.ts +0 -2
  108. package/lib/services/order-actions-with-credential.d.ts.map +0 -1
  109. package/lib/services/order-actions-with-credential.js +0 -23
  110. package/lib/services/order-actions-with-credential.js.map +0 -1
@@ -4,7 +4,7 @@ exports.getUnifiedAccountInfo = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const client_1 = require("../../api/client");
6
6
  const private_api_1 = require("../../api/private-api");
7
- const getUnifiedAccountInfo = async (credential, _accountId) => {
7
+ const getUnifiedAccountInfo = async (credential) => {
8
8
  const [balanceRes, umAccountRes] = await Promise.all([
9
9
  (0, private_api_1.getUnifiedAccountBalance)(credential),
10
10
  (0, private_api_1.getUnifiedUmAccount)(credential),
@@ -15,22 +15,12 @@ const getUnifiedAccountInfo = async (credential, _accountId) => {
15
15
  if ((0, client_1.isApiError)(umAccountRes)) {
16
16
  throw new Error(umAccountRes.msg);
17
17
  }
18
- const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');
19
- if (!usdtBalance) {
20
- throw new Error('USDT balance not found');
21
- }
22
- const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');
23
- if (!usdtAsset) {
24
- throw new Error('USDT asset not found in UM account');
25
- }
26
- const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;
27
- const free = equity - +usdtAsset.initialMargin;
28
18
  const positions = umAccountRes.positions
29
19
  .filter((position) => +position.positionAmt !== 0)
30
20
  .map((position) => ({
31
21
  position_id: `${position.symbol}/${position.positionSide}`,
32
22
  datasource_id: 'BINANCE',
33
- product_id: (0, utils_1.encodePath)('usdt-future', position.symbol),
23
+ product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', position.symbol),
34
24
  direction: position.positionSide === 'LONG'
35
25
  ? 'LONG'
36
26
  : position.positionSide === 'SHORT'
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AAE5F,MAAM,qBAAqB,GAAgD,KAAK,EACrF,UAAU,EACV,UAAU,EACV,EAAE;IACF,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,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,CAAC,MAAM;oBACR,CAAC,CAAC,SAAS;QACf,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW;QAC7B,WAAW,EAAE,CAAC,QAAQ,CAAC,WAAW;QAClC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU;QACpC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW;QACzF,eAAe,EAAE,CAAC,QAAQ,CAAC,gBAAgB;QAC3C,SAAS,EACP,CAAC,QAAQ,CAAC,WAAW;YACrB,CAAC,CAAC,QAAQ,CAAC,UAAU;gBACnB,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAC5F,CAAC,CAAC,CAAC;IAEN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApDW,QAAA,qBAAqB,yBAoDhC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n _accountId,\n) => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');\n if (!usdtBalance) {\n throw new Error('USDT balance not found');\n }\n const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');\n if (!usdtAsset) {\n throw new Error('USDT asset not found in UM account');\n }\n\n const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;\n const free = equity - +usdtAsset.initialMargin;\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('usdt-future', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AAE5F,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED,MAAM,SAAS,GAAgB,YAAY,CAAC,SAAS;SAClD,MAAM,CAAC,CAAC,QAAQ,EA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{ isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exchange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":""}
@@ -0,0 +1,58 @@
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 product_1 = require("../public-data/product");
7
+ const profile_1 = require("./accounts/profile");
8
+ const spot_1 = require("./accounts/spot");
9
+ const unified_1 = require("./accounts/unified");
10
+ const cancelOrder_1 = require("./orders/cancelOrder");
11
+ const listOrders_1 = require("./orders/listOrders");
12
+ const modifyOrder_1 = require("./orders/modifyOrder");
13
+ const submitOrder_1 = require("./orders/submitOrder");
14
+ const terminal = protocol_1.Terminal.fromNodeEnv();
15
+ (0, exchange_1.provideExchangeServices)(terminal, {
16
+ name: 'BINANCE',
17
+ credentialSchema: {
18
+ type: 'object',
19
+ required: ['access_key', 'secret_key'],
20
+ properties: {
21
+ access_key: { type: 'string' },
22
+ secret_key: { type: 'string' },
23
+ },
24
+ },
25
+ getCredentialId: profile_1.getCredentialId,
26
+ listProducts: product_1.listProducts,
27
+ getPositions: async function (credential) {
28
+ const [uFuturePositions, spotPositions] = await Promise.all([
29
+ (0, unified_1.getUnifiedAccountInfo)(credential),
30
+ (0, spot_1.getSpotAccountInfoSnapshot)(credential),
31
+ ]);
32
+ return [...uFuturePositions, ...spotPositions];
33
+ },
34
+ getOrders: async function (credential) {
35
+ const [umOrders, spotOrders] = await Promise.all([
36
+ (0, listOrders_1.listUnifiedUmOrders)(credential),
37
+ (0, listOrders_1.listSpotOrders)(credential),
38
+ ]);
39
+ return [...umOrders, ...spotOrders];
40
+ },
41
+ getPositionsByProductId: async function (credential, product_id) {
42
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // BINANCE/USDT-FUTURE/ADAUSDT
43
+ if (instType === 'SPOT') {
44
+ const positions = await (0, spot_1.getSpotAccountInfoSnapshot)(credential);
45
+ return positions.filter((position) => position.product_id === product_id);
46
+ }
47
+ if (instType === 'USDT-FUTURE') {
48
+ const positions = await (0, unified_1.getUnifiedAccountInfo)(credential);
49
+ return positions.filter((position) => position.product_id === product_id);
50
+ }
51
+ throw new Error(`Unsupported instType: ${instType}`);
52
+ },
53
+ getOrdersByProductId: listOrders_1.getOrdersByProductId,
54
+ submitOrder: submitOrder_1.submitOrder,
55
+ modifyOrder: modifyOrder_1.modifyOrder,
56
+ cancelOrder: cancelOrder_1.cancelOrder,
57
+ });
58
+ //# sourceMappingURL=exchange.js.map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B,EAAE,KAAK,WAC5B,UAAuB,EACvB,UAAkB;QAElB,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B;QAC5E,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,SAAS,GAAG,MAAM,IAAA,iCAA0B,EAAC,UAAU,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,IAAI,QAAQ,KAAK,aAAa,EAAE;YAC9B,MAAM,SAAS,GAAG,MAAM,IAAA,+BAAqB,EAAC,UAAU,CAAC,CAAC;YAC1D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,oBAAoB,EAApB,iCAAoB;IACpB,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential } from '../api/client';\nimport { listProducts } from '../public-data/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getSpotAccountInfoSnapshot } from './accounts/spot';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { getOrdersByProductId, listSpotOrders, listUnifiedUmOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'BINANCE',\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,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const [uFuturePositions, spotPositions] = await Promise.all([\n getUnifiedAccountInfo(credential),\n getSpotAccountInfoSnapshot(credential),\n ]);\n return [...uFuturePositions, ...spotPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders, spotOrders] = await Promise.all([\n listUnifiedUmOrders(credential),\n listSpotOrders(credential),\n ]);\n return [...umOrders, ...spotOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfoSnapshot(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n if (instType === 'USDT-FUTURE') {\n const positions = await getUnifiedAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder,\n cancelOrder,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAkC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA+BpF,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAQhE,CAAC"}
1
+ {"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAkC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAgCpF,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAShE,CAAC"}
@@ -4,6 +4,7 @@ exports.cancelOrder = void 0;
4
4
  const client_1 = require("../../api/client");
5
5
  const private_api_1 = require("../../api/private-api");
6
6
  const order_utils_1 = require("./order-utils");
7
+ const utils_1 = require("@yuants/utils");
7
8
  const cancelUnifiedOrder = async (credential, order) => {
8
9
  if (!order.order_id) {
9
10
  throw new Error('Binance cancelOrder requires order_id');
@@ -31,13 +32,14 @@ const cancelSpotOrder = async (credential, order) => {
31
32
  }
32
33
  };
33
34
  const cancelOrder = async (credential, order) => {
34
- if (order.account_id.includes('/unified/')) {
35
+ const [, TYPE] = (0, utils_1.decodePath)(order.product_id);
36
+ if (TYPE === 'USDT-FUTURE') {
35
37
  return cancelUnifiedOrder(credential, order);
36
38
  }
37
- if (order.account_id.includes('/spot/')) {
39
+ if (TYPE === 'SPOT') {
38
40
  return cancelSpotOrder(credential, order);
39
41
  }
40
- throw new Error(`Unsupported account_id for cancelOrder: ${order.account_id}`);
42
+ throw (0, utils_1.newError)('BINANCE_CANCEL_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });
41
43
  };
42
44
  exports.cancelOrder = cancelOrder;
43
45
  //# sourceMappingURL=cancelOrder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAAoF;AACpF,+CAAqE;AAErE,MAAM,kBAAkB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;IACD,MAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MA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AC;AARW,QAAA,WAAW,eAQtB","sourcesContent":["import { IActionHandlerOfCancelOrder } from '@yuants/data-order';\nimport { isApiError } from '../../api/client';\nimport { deleteSpotOrder, deleteUmOrder, ICredential } from '../../api/private-api';\nimport { decodeFutureSymbol, decodeSpotSymbol } from './order-utils';\n\nconst cancelUnifiedOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('Binance cancelOrder requires order_id');\n }\n const symbol = decodeFutureSymbol(order.product_id);\n const res = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(res)) {\n throw new Error(`Binance cancel unified order failed: ${res.code} ${res.msg}`);\n }\n};\n\nconst cancelSpotOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('Binance cancelOrder requires order_id');\n }\n const symbol = decodeSpotSymbol(order.product_id);\n const res = await deleteSpotOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(res)) {\n throw new Error(`Binance cancel spot order failed: ${res.code} ${res.msg}`);\n }\n};\n\nexport const cancelOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (order.account_id.includes('/unified/')) {\n return cancelUnifiedOrder(credential, order);\n }\n if (order.account_id.includes('/spot/')) {\n return cancelSpotOrder(credential, order);\n }\n throw new Error(`Unsupported account_id for cancelOrder: ${order.account_id}`);\n};\n"]}
1
+ {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAAoF;AACpF,+CAAqE;AACrE,yCAAqD;AAErD,MAAM,kBAAkB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;IACD,MAAM,MAAM,GAAG,IAAA,gCAA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KAC3C;IACD,MAAM,IAAA,gBAAQ,EAAC,+CAA+C,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7E,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IActionHandlerOfCancelOrder } from '@yuants/data-order';\nimport { isApiError } from '../../api/client';\nimport { deleteSpotOrder, deleteUmOrder, ICredential } from '../../api/private-api';\nimport { decodeFutureSymbol, decodeSpotSymbol } from './order-utils';\nimport { decodePath, newError } from '@yuants/utils';\n\nconst cancelUnifiedOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('Binance cancelOrder requires order_id');\n }\n const symbol = decodeFutureSymbol(order.product_id);\n const res = await deleteUmOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(res)) {\n throw new Error(`Binance cancel unified order failed: ${res.code} ${res.msg}`);\n }\n};\n\nconst cancelSpotOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('Binance cancelOrder requires order_id');\n }\n const symbol = decodeSpotSymbol(order.product_id);\n const res = await deleteSpotOrder(credential, {\n symbol,\n orderId: order.order_id,\n });\n if (isApiError(res)) {\n throw new Error(`Binance cancel spot order failed: ${res.code} ${res.msg}`);\n }\n};\n\nexport const cancelOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n const [, TYPE] = decodePath(order.product_id);\n if (TYPE === 'USDT-FUTURE') {\n return cancelUnifiedOrder(credential, order);\n }\n if (TYPE === 'SPOT') {\n return cancelSpotOrder(credential, order);\n }\n throw newError('BINANCE_CANCEL_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });\n};\n"]}
@@ -1,4 +1,6 @@
1
- import { IActionHandlerOfListOrders } from '@yuants/data-order';
1
+ import { IOrder } from '@yuants/data-order';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const listOrders: IActionHandlerOfListOrders<ICredential>;
3
+ export declare const listUnifiedUmOrders: (credential: ICredential) => Promise<IOrder[]>;
4
+ export declare const listSpotOrders: (credential: ICredential) => Promise<IOrder[]>;
5
+ export declare const getOrdersByProductId: (credential: ICredential, product_id: string) => Promise<IOrder[]>;
4
6
  //# sourceMappingURL=listOrders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAU,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAA6C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQ/F,eAAO,MAAM,UAAU,EAAE,0BAA0B,CAAC,WAAW,CA8C9D,CAAC"}
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAA6C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQ/F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAsBnF,CAAC;AAEF,eAAO,MAAM,cAAc,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAoB9E,CAAC;AAEF,eAAO,MAAM,oBAAoB,eACnB,WAAW,cACX,MAAM,KACjB,QAAQ,MAAM,EAAE,CAWlB,CAAC"}
@@ -1,53 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listOrders = void 0;
3
+ exports.getOrdersByProductId = exports.listSpotOrders = exports.listUnifiedUmOrders = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const client_1 = require("../../api/client");
6
6
  const private_api_1 = require("../../api/private-api");
7
7
  const order_utils_1 = require("./order-utils");
8
- const listOrders = async (credential, account_id) => {
9
- if (account_id.includes('/unified/')) {
10
- const res = await (0, private_api_1.getUnifiedUmOpenOrders)(credential);
11
- if ((0, client_1.isApiError)(res)) {
12
- throw new Error(res.msg);
13
- }
14
- return res.map((order) => {
15
- var _a;
16
- return ({
17
- order_id: `${order.orderId}`,
18
- account_id,
19
- product_id: (0, utils_1.encodePath)('usdt-future', order.symbol),
20
- order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
21
- order_direction: (_a = (0, order_utils_1.mapBinanceSideToYuantsDirection)(order.side, order.positionSide)) !== null && _a !== void 0 ? _a : (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),
22
- volume: +order.origQty,
23
- traded_volume: +order.executedQty,
24
- price: order.price === undefined ? undefined : +order.price,
25
- submit_at: order.time,
26
- updated_at: (0, utils_1.formatTime)(order.updateTime),
27
- order_status: (0, order_utils_1.mapBinanceOrderStatus)(order.status),
28
- });
29
- });
8
+ const listUnifiedUmOrders = async (credential) => {
9
+ const res = await (0, private_api_1.getUnifiedUmOpenOrders)(credential);
10
+ if ((0, client_1.isApiError)(res)) {
11
+ throw new Error(res.msg);
30
12
  }
31
- if (account_id.includes('/spot/')) {
32
- const res = await (0, private_api_1.getSpotOpenOrders)(credential);
33
- if ((0, client_1.isApiError)(res)) {
34
- throw new Error(res.msg);
35
- }
36
- return res.map((order) => ({
13
+ return res.map((order) => {
14
+ var _a;
15
+ return ({
37
16
  order_id: `${order.orderId}`,
38
- account_id,
39
- product_id: (0, utils_1.encodePath)('spot', order.symbol),
17
+ account_id: '',
18
+ product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', order.symbol),
40
19
  order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
41
- order_direction: (0, order_utils_1.mapSpotSideToOrderDirection)(order.side),
20
+ order_direction: (_a = (0, order_utils_1.mapBinanceSideToYuantsDirection)(order.side, order.positionSide)) !== null && _a !== void 0 ? _a : (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),
42
21
  volume: +order.origQty,
43
22
  traded_volume: +order.executedQty,
44
- price: order.price ? +order.price : undefined,
23
+ price: order.price === undefined ? undefined : +order.price,
45
24
  submit_at: order.time,
46
25
  updated_at: (0, utils_1.formatTime)(order.updateTime),
47
26
  order_status: (0, order_utils_1.mapBinanceOrderStatus)(order.status),
48
- }));
27
+ });
28
+ });
29
+ };
30
+ exports.listUnifiedUmOrders = listUnifiedUmOrders;
31
+ const listSpotOrders = async (credential) => {
32
+ const res = await (0, private_api_1.getSpotOpenOrders)(credential);
33
+ if ((0, client_1.isApiError)(res)) {
34
+ throw new Error(res.msg);
35
+ }
36
+ return res.map((order) => ({
37
+ order_id: `${order.orderId}`,
38
+ account_id: '',
39
+ product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', order.symbol),
40
+ order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
41
+ order_direction: (0, order_utils_1.mapSpotSideToOrderDirection)(order.side),
42
+ volume: +order.origQty,
43
+ traded_volume: +order.executedQty,
44
+ price: order.price === undefined ? undefined : +order.price,
45
+ submit_at: order.time,
46
+ updated_at: (0, utils_1.formatTime)(order.updateTime),
47
+ order_status: (0, order_utils_1.mapBinanceOrderStatus)(order.status),
48
+ }));
49
+ };
50
+ exports.listSpotOrders = listSpotOrders;
51
+ const getOrdersByProductId = async function (credential, product_id) {
52
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // BINANCE/USDT-FUTURE/ADAUSDT
53
+ if (instType === 'SPOT') {
54
+ const orders = await (0, exports.listSpotOrders)(credential);
55
+ return orders.filter((order) => order.product_id === product_id);
56
+ }
57
+ if (instType === 'USDT-FUTURE') {
58
+ const orders = await (0, exports.listUnifiedUmOrders)(credential);
59
+ return orders.filter((order) => order.product_id === product_id);
49
60
  }
50
- throw new Error(`Unsupported account_id for listOrders: ${account_id}`);
61
+ throw new Error(`Unsupported instType: ${instType}`);
51
62
  };
52
- exports.listOrders = listOrders;
63
+ exports.getOrdersByProductId = getOrdersByProductId;
53
64
  //# sourceMappingURL=listOrders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceR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KAAK,CAAC,MAAM,CAAC;aAClD,CAAC,CAAA;SAAA,CACH,CAAC;KACH;IACD,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACjC,MAAM,GAAG,GAAG,MAAM,IAAA,+BAAiB,EAAC,UAAU,CAAC,CAAC;QAChD,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,GAAG,CAAC,GAAG,CACZ,CAAC,KAAK,EAAU,EAAE,CAAC,CAAC;YAClB,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;YAC5B,UAAU;YACV,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;YAC5C,UAAU,EAAE,IAAA,yCAA2B,EAAC,KAAK,CAAC,IAAI,CAAC;YACnD,eAAe,EAAE,IAAA,yCAA2B,EAAC,KAAK,CAAC,IAAI,CAAC;YACxD,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO;YACtB,aAAa,EAAE,CAAC,KAAK,CAAC,WAAW;YACjC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YAC7C,SAAS,EAAE,KAAK,CAAC,IAAI;YACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC;YACxC,YAAY,EAAE,IAAA,mCAAqB,EAAC,KAAK,CAAC,MAAM,CAAC;SAClD,CAAC,CACH,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,UAAU,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC;AA9CW,QAAA,UAAU,cA8CrB","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotOpenOrders, getUnifiedUmOpenOrders, ICredential } from '../../api/private-api';\nimport {\n mapBinanceOrderStatus,\n mapBinanceOrderTypeToYuants,\n mapBinanceSideToYuantsDirection,\n mapSpotSideToOrderDirection,\n} from './order-utils';\n\nexport const listOrders: IActionHandlerOfListOrders<ICredential> = async (credential, account_id) => {\n if (account_id.includes('/unified/')) {\n const res = await getUnifiedUmOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('usdt-future', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction:\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ??\n (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n }\n if (account_id.includes('/spot/')) {\n const res = await getSpotOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('spot', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction: mapSpotSideToOrderDirection(order.side),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price ? +order.price : undefined,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n }\n throw new Error(`Unsupported account_id for listOrders: ${account_id}`);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAmE;AACnE,6CAA8C;AAC9C,uDAA+F;AAC/F,+CAKuB;AAEhB,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAqB,EAAE;IACtF,MAAM,G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KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;KAClE;IACD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAmB,EAAC,UAAU,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;KAClE;IACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotOpenOrders, getUnifiedUmOpenOrders, ICredential } from '../../api/private-api';\nimport {\n mapBinanceOrderStatus,\n mapBinanceOrderTypeToYuants,\n mapBinanceSideToYuantsDirection,\n mapSpotSideToOrderDirection,\n} from './order-utils';\n\nexport const listUnifiedUmOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const res = await getUnifiedUmOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id: '',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction:\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ??\n (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n};\n\nexport const listSpotOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const res = await getSpotOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id: '',\n product_id: encodePath('BINANCE', 'SPOT', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction: mapSpotSideToOrderDirection(order.side),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n};\n\nexport const getOrdersByProductId = async function (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n if (instType === 'SPOT') {\n const orders = await listSpotOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n if (instType === 'USDT-FUTURE') {\n const orders = await listUnifiedUmOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"modifyOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/modifyOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAA0C,MAAM,uBAAuB,CAAC;AA4D5F,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAQhE,CAAC"}
1
+ {"version":3,"file":"modifyOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/modifyOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAA0C,MAAM,uBAAuB,CAAC;AA8D5F,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAWhE,CAAC"}
@@ -4,6 +4,8 @@ exports.modifyOrder = void 0;
4
4
  const client_1 = require("../../api/client");
5
5
  const private_api_1 = require("../../api/private-api");
6
6
  const order_utils_1 = require("./order-utils");
7
+ const error_1 = require("@yuants/utils/lib/error");
8
+ const path_1 = require("@yuants/utils/lib/path");
7
9
  const modifyUnifiedOrder = async (credential, order) => {
8
10
  const symbol = (0, order_utils_1.decodeFutureSymbol)(order.product_id);
9
11
  const side = (0, order_utils_1.mapOrderDirectionToSide)(order.order_direction);
@@ -50,13 +52,14 @@ const modifySpotOrder = async (credential, order) => {
50
52
  }
51
53
  };
52
54
  const modifyOrder = async (credential, order) => {
53
- if (order.account_id.includes('/unified/')) {
55
+ const [, TYPE] = (0, path_1.decodePath)(order.product_id);
56
+ if (TYPE === 'USDT-FUTURE') {
54
57
  return modifyUnifiedOrder(credential, order);
55
58
  }
56
- if (order.account_id.includes('/spot/')) {
59
+ if (TYPE === 'SPOT') {
57
60
  return modifySpotOrder(credential, order);
58
61
  }
59
- throw new Error(`Unsupported account_id for modifyOrder: ${order.account_id}`);
62
+ throw (0, error_1.newError)('BINANCE_MODIFY_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });
60
63
  };
61
64
  exports.modifyOrder = modifyOrder;
62
65
  //# sourceMappingURL=modifyOrder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../../src/services/orders/modifyOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAA4F;AAC5F,+CAMuB;AAEvB,MAAM,kBAAkB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,MAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,IAAA,qCAAuB,EAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAE5D,MAAM,GAAG,GAAG,MAAM,IAAA,wBAAU,EAAC,UAAU,EAAE;QACvC,MAAM;QACN,IAAI;QACJ,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAA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C5D;QACD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC3B,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;KAClC;IACD,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ,EAAE;QAClD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;KAC5B;IAED,MAAM,GAAG,GAAG,MAAM,IAAA,wCAA0B,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACjE,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KAC7E;AACH,CAAC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAC1C,OAAO,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC9C;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACvC,OAAO,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC3C;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC;AARW,QAAA,WAAW,eAQtB","sourcesContent":["import { IActionHandlerOfModifyOrder } from '@yuants/data-order';\nimport { isApiError } from '../../api/client';\nimport { ICredential, postSpotOrderCancelReplace, putUmOrder } from '../../api/private-api';\nimport {\n decodeFutureSymbol,\n decodeSpotSymbol,\n deriveClientOrderId,\n mapOrderDirectionToSide,\n mapOrderTypeToOrdType,\n} from './order-utils';\n\nconst modifyUnifiedOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n const symbol = decodeFutureSymbol(order.product_id);\n const side = mapOrderDirectionToSide(order.order_direction);\n\n const res = await putUmOrder(credential, {\n symbol,\n side,\n orderId: order.order_id ? parseInt(order.order_id) : undefined,\n // origClientOrderId: order.client_order_id, // TODO: support client_order_id\n quantity: order.volume,\n price: order.price,\n });\n if (isApiError(res)) {\n throw new Error(`Binance modify unified order failed: ${res.code} ${res.msg}`);\n }\n};\n\nconst modifySpotOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n const symbol = decodeSpotSymbol(order.product_id);\n const side = mapOrderDirectionToSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const params: Parameters<typeof postSpotOrderCancelReplace>[1] = {\n symbol,\n side,\n type,\n cancelReplaceMode: 'STOP_ON_FAILURE',\n cancelOrderId: order.order_id ? parseInt(order.order_id) : undefined,\n // cancelOrigClientOrderId: order.client_order_id, // TODO: support client_order_id\n newClientOrderId: deriveClientOrderId(order),\n quantity: order.volume,\n };\n\n if (type === 'LIMIT') {\n if (order.price === undefined) {\n throw new Error('Binance spot LIMIT order requires price');\n }\n params.price = order.price;\n params.timeInForce = timeInForce;\n }\n if (order.price !== undefined && type === 'MARKET') {\n params.price = order.price;\n }\n\n const res = await postSpotOrderCancelReplace(credential, params);\n if (isApiError(res)) {\n throw new Error(`Binance modify spot order failed: ${res.code} ${res.msg}`);\n }\n};\n\nexport const modifyOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n if (order.account_id.includes('/unified/')) {\n return modifyUnifiedOrder(credential, order);\n }\n if (order.account_id.includes('/spot/')) {\n return modifySpotOrder(credential, order);\n }\n throw new Error(`Unsupported account_id for modifyOrder: ${order.account_id}`);\n};\n"]}
1
+ {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../../src/services/orders/modifyOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAA4F;AA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AM,EAAE;QACnB,OAAO,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC3C;IAED,MAAM,IAAA,gBAAQ,EAAC,+CAA+C,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7E,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB","sourcesContent":["import { IActionHandlerOfModifyOrder } from '@yuants/data-order';\nimport { isApiError } from '../../api/client';\nimport { ICredential, postSpotOrderCancelReplace, putUmOrder } from '../../api/private-api';\nimport {\n decodeFutureSymbol,\n decodeSpotSymbol,\n deriveClientOrderId,\n mapOrderDirectionToSide,\n mapOrderTypeToOrdType,\n} from './order-utils';\nimport { newError } from '@yuants/utils/lib/error';\nimport { decodePath } from '@yuants/utils/lib/path';\n\nconst modifyUnifiedOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n const symbol = decodeFutureSymbol(order.product_id);\n const side = mapOrderDirectionToSide(order.order_direction);\n\n const res = await putUmOrder(credential, {\n symbol,\n side,\n orderId: order.order_id ? parseInt(order.order_id) : undefined,\n // origClientOrderId: order.client_order_id, // TODO: support client_order_id\n quantity: order.volume,\n price: order.price,\n });\n if (isApiError(res)) {\n throw new Error(`Binance modify unified order failed: ${res.code} ${res.msg}`);\n }\n};\n\nconst modifySpotOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n const symbol = decodeSpotSymbol(order.product_id);\n const side = mapOrderDirectionToSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const params: Parameters<typeof postSpotOrderCancelReplace>[1] = {\n symbol,\n side,\n type,\n cancelReplaceMode: 'STOP_ON_FAILURE',\n cancelOrderId: order.order_id ? parseInt(order.order_id) : undefined,\n // cancelOrigClientOrderId: order.client_order_id, // TODO: support client_order_id\n newClientOrderId: deriveClientOrderId(order),\n quantity: order.volume,\n };\n\n if (type === 'LIMIT') {\n if (order.price === undefined) {\n throw new Error('Binance spot LIMIT order requires price');\n }\n params.price = order.price;\n params.timeInForce = timeInForce;\n }\n if (order.price !== undefined && type === 'MARKET') {\n params.price = order.price;\n }\n\n const res = await postSpotOrderCancelReplace(credential, params);\n if (isApiError(res)) {\n throw new Error(`Binance modify spot order failed: ${res.code} ${res.msg}`);\n }\n};\n\nexport const modifyOrder: IActionHandlerOfModifyOrder<ICredential> = async (credential, order) => {\n const [, TYPE] = decodePath(order.product_id);\n\n if (TYPE === 'USDT-FUTURE') {\n return modifyUnifiedOrder(credential, order);\n }\n if (TYPE === 'SPOT') {\n return modifySpotOrder(credential, order);\n }\n\n throw newError('BINANCE_MODIFY_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"order-utils.d.ts","sourceRoot":"","sources":["../../../src/services/orders/order-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,eAAO,MAAM,kBAAkB,eAAgB,MAAM,WAMpD,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAAgB,MAAM,WAalD,CAAC;AAEF,eAAO,MAAM,uBAAuB,eAAgB,MAAM,CAAC,iBAAiB,CAAC,mBAW5E,CAAC;AAEF,eAAO,MAAM,+BAA+B,eAAgB,MAAM,CAAC,iBAAiB,CAAC,qBAWpF,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBAAiB,MAAM,CAAC,YAAY,CAAC,uBAUtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,iBAAkB,MAAM,KAAG,MAAM,CAAC,YAAY,CASrF,CAAC;AAEF,eAAO,MAAM,+BAA+B,UACnC,MAAM,iBACE,MAAM,KACpB,MAAM,CAAC,iBAAiB,CAAC,GAAG,SAW9B,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,MAAM,KAAG,MAAM,CAAC,iBAAiB,CAKnF,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,MAAM,WAWhD,CAAC;AAcF,eAAO,MAAM,qBAAqB,YAAa,MAAM,KAAG,MAAM,CAAC,cAAc,CAG5E,CAAC"}
1
+ {"version":3,"file":"order-utils.d.ts","sourceRoot":"","sources":["../../../src/services/orders/order-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,eAAO,MAAM,kBAAkB,eAAgB,MAAM,WAiBpD,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAAgB,MAAM,WAsBlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,eAAgB,MAAM,CAAC,iBAAiB,CAAC,mBAW5E,CAAC;AAEF,eAAO,MAAM,+BAA+B,eAAgB,MAAM,CAAC,iBAAiB,CAAC,qBAWpF,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBAAiB,MAAM,CAAC,YAAY,CAAC,uBAUtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,iBAAkB,MAAM,KAAG,MAAM,CAAC,YAAY,CASrF,CAAC;AAEF,eAAO,MAAM,+BAA+B,UACnC,MAAM,iBACE,MAAM,KACpB,MAAM,CAAC,iBAAiB,CAAC,GAAG,SAW9B,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,MAAM,KAAG,MAAM,CAAC,iBAAiB,CAKnF,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,MAAM,WAWhD,CAAC;AAcF,eAAO,MAAM,qBAAqB,YAAa,MAAM,KAAG,MAAM,CAAC,cAAc,CAG5E,CAAC"}
@@ -4,18 +4,40 @@ exports.mapBinanceOrderStatus = exports.deriveClientOrderId = exports.mapSpotSid
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const crypto_1 = require("crypto");
6
6
  const decodeFutureSymbol = (product_id) => {
7
- const [instType, symbol] = (0, utils_1.decodePath)(product_id);
8
- if (instType !== 'usdt-future' || !symbol) {
9
- throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);
7
+ const parts = (0, utils_1.decodePath)(product_id);
8
+ // Support both old format (usdt-future/symbol) and new format (BINANCE/USDT-FUTURE/symbol)
9
+ if (parts.length === 2) {
10
+ const [instType, symbol] = parts;
11
+ if (instType !== 'usdt-future' || !symbol) {
12
+ throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);
13
+ }
14
+ return symbol;
15
+ }
16
+ else if (parts.length === 3) {
17
+ const [datasource, instType, symbol] = parts;
18
+ if (datasource !== 'BINANCE' || instType !== 'USDT-FUTURE' || !symbol) {
19
+ throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);
20
+ }
21
+ return symbol;
10
22
  }
11
- return symbol;
23
+ throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);
12
24
  };
13
25
  exports.decodeFutureSymbol = decodeFutureSymbol;
14
26
  const decodeSpotSymbol = (product_id) => {
15
27
  try {
16
- const [instType, symbol] = (0, utils_1.decodePath)(product_id);
17
- if ((instType === null || instType === void 0 ? void 0 : instType.toLowerCase()) === 'spot' && symbol) {
18
- return symbol;
28
+ const parts = (0, utils_1.decodePath)(product_id);
29
+ // Support both old format (spot/symbol) and new format (BINANCE/SPOT/symbol)
30
+ if (parts.length === 2) {
31
+ const [instType, symbol] = parts;
32
+ if ((instType === null || instType === void 0 ? void 0 : instType.toLowerCase()) === 'spot' && symbol) {
33
+ return symbol;
34
+ }
35
+ }
36
+ else if (parts.length === 3) {
37
+ const [datasource, instType, symbol] = parts;
38
+ if (datasource === 'BINANCE' && instType === 'SPOT' && symbol) {
39
+ return symbol;
40
+ }
19
41
  }
20
42
  }
21
43
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"order-utils.js","sourceRoot":"","sources":["../../../src/services/orders/order-utils.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,mCAAoC;AAE7B,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAE,EAAE;IACvD,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC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{ IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { createHash } from 'crypto';\n\nexport const decodeFutureSymbol = (product_id: string) => {\n const [instType, symbol] = decodePath(product_id);\n if (instType !== 'usdt-future' || !symbol) {\n throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);\n }\n return symbol;\n};\n\nexport const decodeSpotSymbol = (product_id: string) => {\n try {\n const [instType, symbol] = decodePath(product_id);\n if (instType?.toLowerCase() === 'spot' && symbol) {\n return symbol;\n }\n } catch (err) {\n // ignore decode errors and fall back to raw product id\n }\n if (!product_id.includes('/')) {\n return product_id;\n }\n throw new Error(`Unsupported product_id for Binance spot: ${product_id}`);\n};\n\nexport const mapOrderDirectionToSide = (direction?: IOrder['order_direction']) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'BUY';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'SELL';\n default:\n throw new Error(`Unsupported order_direction: ${direction}`);\n }\n};\n\nexport const mapOrderDirectionToPositionSide = (direction?: IOrder['order_direction']) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'LONG';\n case 'OPEN_SHORT':\n case 'CLOSE_SHORT':\n return 'SHORT';\n default:\n throw new Error(`Unsupported order_direction for positionSide: ${direction}`);\n }\n};\n\nexport const mapOrderTypeToOrdType = (order_type?: IOrder['order_type']) => {\n switch (order_type) {\n case 'LIMIT':\n case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n throw new Error(`Unsupported order_type: ${order_type}`);\n }\n};\n\nexport const mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nexport const mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nexport const mapSpotSideToOrderDirection = (side?: string): IOrder['order_direction'] => {\n if (side === 'SELL') {\n return 'CLOSE_LONG';\n }\n return 'OPEN_LONG';\n};\n\nexport const deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst BinanceOrderStatusMap: Record<string, IOrder['order_status']> = {\n NEW: 'ACCEPTED',\n PARTIALLY_FILLED: 'TRADED',\n FILLED: 'TRADED',\n PENDING_NEW: 'ACCEPTED',\n PENDING_CANCEL: 'CANCELLED',\n CANCELED: 'CANCELLED',\n CANCELLED: 'CANCELLED',\n REJECTED: 'CANCELLED',\n EXPIRED: 'CANCELLED',\n};\n\nexport const mapBinanceOrderStatus = (status?: string): IOrder['order_status'] => {\n if (!status) return 'ACCEPTED';\n return BinanceOrderStatusMap[status] ?? 'ACCEPTED';\n};\n"]}
1
+ {"version":3,"file":"order-utils.js","sourceRoot":"","sources":["../../../src/services/orders/order-utils.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,mCAAoC;AAE7B,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAE,EAAE;IACvD,MAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;IACrC,2FAA2F;IAC3F,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QACjC,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,MAAM,EAAE;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CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACpF,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B;AAEF,MAAM,qBAAqB,GAA2C;IACpE,GAAG,EAAE,UAAU;IACf,gBAAgB,EAAE,QAAQ;IAC1B,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,WAAW;IAC3B,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,WAAW;CACrB,CAAC;AAEK,MAAM,qBAAqB,GAAG,CAAC,MAAe,EAA0B,EAAE;;IAC/E,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC;IAC/B,OAAO,MAAA,qBAAqB,CAAC,MAAM,CAAC,mCAAI,UAAU,CAAC;AACrD,CAAC,CAAC;AAHW,QAAA,qBAAqB,yBAGhC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { createHash } from 'crypto';\n\nexport const decodeFutureSymbol = (product_id: string) => {\n const parts = decodePath(product_id);\n // Support both old format (usdt-future/symbol) and new format (BINANCE/USDT-FUTURE/symbol)\n if (parts.length === 2) {\n const [instType, symbol] = parts;\n if (instType !== 'usdt-future' || !symbol) {\n throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);\n }\n return symbol;\n } else if (parts.length === 3) {\n const [datasource, instType, symbol] = parts;\n if (datasource !== 'BINANCE' || instType !== 'USDT-FUTURE' || !symbol) {\n throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);\n }\n return symbol;\n }\n throw new Error(`Unsupported product_id for Binance futures: ${product_id}`);\n};\n\nexport const decodeSpotSymbol = (product_id: string) => {\n try {\n const parts = decodePath(product_id);\n // Support both old format (spot/symbol) and new format (BINANCE/SPOT/symbol)\n if (parts.length === 2) {\n const [instType, symbol] = parts;\n if (instType?.toLowerCase() === 'spot' && symbol) {\n return symbol;\n }\n } else if (parts.length === 3) {\n const [datasource, instType, symbol] = parts;\n if (datasource === 'BINANCE' && instType === 'SPOT' && symbol) {\n return symbol;\n }\n }\n } catch (err) {\n // ignore decode errors and fall back to raw product id\n }\n if (!product_id.includes('/')) {\n return product_id;\n }\n throw new Error(`Unsupported product_id for Binance spot: ${product_id}`);\n};\n\nexport const mapOrderDirectionToSide = (direction?: IOrder['order_direction']) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'BUY';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'SELL';\n default:\n throw new Error(`Unsupported order_direction: ${direction}`);\n }\n};\n\nexport const mapOrderDirectionToPositionSide = (direction?: IOrder['order_direction']) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'LONG';\n case 'OPEN_SHORT':\n case 'CLOSE_SHORT':\n return 'SHORT';\n default:\n throw new Error(`Unsupported order_direction for positionSide: ${direction}`);\n }\n};\n\nexport const mapOrderTypeToOrdType = (order_type?: IOrder['order_type']) => {\n switch (order_type) {\n case 'LIMIT':\n case 'MAKER':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n throw new Error(`Unsupported order_type: ${order_type}`);\n }\n};\n\nexport const mapBinanceOrderTypeToYuants = (binanceType?: string): IOrder['order_type'] => {\n switch (binanceType) {\n case 'LIMIT':\n return 'LIMIT';\n case 'MARKET':\n return 'MARKET';\n default:\n return 'LIMIT';\n }\n};\n\nexport const mapBinanceSideToYuantsDirection = (\n side?: string,\n positionSide?: string,\n): IOrder['order_direction'] | undefined => {\n if (!side || !positionSide) {\n return undefined;\n }\n if (positionSide === 'LONG') {\n return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (positionSide === 'SHORT') {\n return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';\n }\n return undefined;\n};\n\nexport const mapSpotSideToOrderDirection = (side?: string): IOrder['order_direction'] => {\n if (side === 'SELL') {\n return 'CLOSE_LONG';\n }\n return 'OPEN_LONG';\n};\n\nexport const deriveClientOrderId = (order: IOrder) => {\n if (order.order_id) return `${order.order_id}`;\n const payload = JSON.stringify({\n account_id: order.account_id,\n product_id: order.product_id,\n order_direction: order.order_direction,\n order_type: order.order_type,\n price: order.price,\n volume: order.volume,\n });\n return `YUANTS${createHash('sha256').update(payload).digest('hex').slice(0, 24)}`;\n};\n\nconst BinanceOrderStatusMap: Record<string, IOrder['order_status']> = {\n NEW: 'ACCEPTED',\n PARTIALLY_FILLED: 'TRADED',\n FILLED: 'TRADED',\n PENDING_NEW: 'ACCEPTED',\n PENDING_CANCEL: 'CANCELLED',\n CANCELED: 'CANCELLED',\n CANCELLED: 'CANCELLED',\n REJECTED: 'CANCELLED',\n EXPIRED: 'CANCELLED',\n};\n\nexport const mapBinanceOrderStatus = (status?: string): IOrder['order_status'] => {\n if (!status) return 'ACCEPTED';\n return BinanceOrderStatusMap[status] ?? 'ACCEPTED';\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAA8B,MAAM,uBAAuB,CAAC;AAuEhF,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAQhE,CAAC"}
1
+ {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGjE,OAAO,EAAE,WAAW,EAA8B,MAAM,uBAAuB,CAAC;AAuEhF,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAWhE,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.submitOrder = void 0;
4
+ const utils_1 = require("@yuants/utils");
4
5
  const client_1 = require("../../api/client");
5
6
  const private_api_1 = require("../../api/private-api");
6
7
  const order_utils_1 = require("./order-utils");
@@ -62,13 +63,14 @@ const submitSpotOrder = async (credential, order) => {
62
63
  return { order_id: `${res.orderId}` };
63
64
  };
64
65
  const submitOrder = async (credential, order) => {
65
- if (order.account_id.includes('/unified/')) {
66
+ const [, TYPE] = (0, utils_1.decodePath)(order.product_id);
67
+ if (TYPE === 'USDT-FUTURE') {
66
68
  return submitUnifiedOrder(credential, order);
67
69
  }
68
- if (order.account_id.includes('/spot/')) {
70
+ if (TYPE === 'SPOT') {
69
71
  return submitSpotOrder(credential, order);
70
72
  }
71
- throw new Error(`Unsupported account_id for submitOrder: ${order.account_id}`);
73
+ throw (0, utils_1.newError)('BINANCE_SUBMIT_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });
72
74
  };
73
75
  exports.submitOrder = submitOrder;
74
76
  //# sourceMappingURL=submitOrder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAAgF;AAChF,+CAOuB;AAEvB,MAAM,kBAAkB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,MAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACxE;IACD,MAAM,IAAI,GAAG,IAAA,qCAAuB,EAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAG,IAAA,6CAA+B,EAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC5E,MAAM,IAAI,G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AC,EAAE;QAC1C,OAAO,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC9C;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACvC,OAAO,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC3C;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC;AARW,QAAA,WAAW,eAQtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { isApiError } from '../../api/client';\nimport { ICredential, postSpotOrder, postUmOrder } from '../../api/private-api';\nimport {\n decodeFutureSymbol,\n decodeSpotSymbol,\n deriveClientOrderId,\n mapOrderDirectionToPositionSide,\n mapOrderDirectionToSide,\n mapOrderTypeToOrdType,\n} from './order-utils';\n\nconst submitUnifiedOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const symbol = decodeFutureSymbol(order.product_id);\n if (!order.volume) {\n throw new Error('Binance submitOrder requires order.volume to be set');\n }\n const side = mapOrderDirectionToSide(order.order_direction);\n const positionSide = mapOrderDirectionToPositionSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n const reduceOnly =\n order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;\n\n const res = await postUmOrder(credential, {\n symbol,\n side,\n positionSide,\n type,\n quantity: order.volume,\n price: order.price,\n timeInForce,\n reduceOnly,\n newClientOrderId: deriveClientOrderId(order),\n });\n if (isApiError(res)) {\n throw new Error(`Binance submit unified order failed: ${res.code} ${res.msg}`);\n }\n return { order_id: `${res.orderId}` };\n};\n\nconst submitSpotOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const symbol = decodeSpotSymbol(order.product_id);\n if (!order.volume) {\n throw new Error('Binance submitOrder requires order.volume to be set');\n }\n const side = mapOrderDirectionToSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n const params: Parameters<typeof postSpotOrder>[1] = {\n symbol,\n side,\n type,\n quantity: order.volume,\n newClientOrderId: deriveClientOrderId(order),\n };\n if (type === 'LIMIT') {\n if (order.price === undefined) {\n throw new Error('Binance spot LIMIT order requires price');\n }\n params.price = order.price;\n params.timeInForce = timeInForce;\n }\n if (order.price !== undefined && type === 'MARKET') {\n params.price = order.price;\n }\n const res = await postSpotOrder(credential, params);\n if (isApiError(res)) {\n throw new Error(`Binance submit spot order failed: ${res.code} ${res.msg}`);\n }\n return { order_id: `${res.orderId}` };\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (order.account_id.includes('/unified/')) {\n return submitUnifiedOrder(credential, order);\n }\n if (order.account_id.includes('/spot/')) {\n return submitSpotOrder(credential, order);\n }\n throw new Error(`Unsupported account_id for submitOrder: ${order.account_id}`);\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAAqD;AACrD,6CAA8C;AAC9C,uDAAgF;AAChF,+CAOuB;AAEvB,MAAM,kBAAkB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,MAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACxE;IACD,MAAM,IAAI,GAAG,IAAA,qCAAuB,EAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAG,IAAA,6CAA+B,EAAC,KAAK,CAA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,EAAE,IAAI,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE9C,IAAI,IAAI,KAAK,aAAa,EAAE;QAC1B,OAAO,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC9C;IACD,IAAI,IAAI,KAAK,MAAM,EAAE;QACnB,OAAO,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KAC3C;IAED,MAAM,IAAA,gBAAQ,EAAC,+CAA+C,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7E,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { decodePath, newError } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { ICredential, postSpotOrder, postUmOrder } from '../../api/private-api';\nimport {\n decodeFutureSymbol,\n decodeSpotSymbol,\n deriveClientOrderId,\n mapOrderDirectionToPositionSide,\n mapOrderDirectionToSide,\n mapOrderTypeToOrdType,\n} from './order-utils';\n\nconst submitUnifiedOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const symbol = decodeFutureSymbol(order.product_id);\n if (!order.volume) {\n throw new Error('Binance submitOrder requires order.volume to be set');\n }\n const side = mapOrderDirectionToSide(order.order_direction);\n const positionSide = mapOrderDirectionToPositionSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n const reduceOnly =\n order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;\n\n const res = await postUmOrder(credential, {\n symbol,\n side,\n positionSide,\n type,\n quantity: order.volume,\n price: order.price,\n timeInForce,\n reduceOnly,\n newClientOrderId: deriveClientOrderId(order),\n });\n if (isApiError(res)) {\n throw new Error(`Binance submit unified order failed: ${res.code} ${res.msg}`);\n }\n return { order_id: `${res.orderId}` };\n};\n\nconst submitSpotOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const symbol = decodeSpotSymbol(order.product_id);\n if (!order.volume) {\n throw new Error('Binance submitOrder requires order.volume to be set');\n }\n const side = mapOrderDirectionToSide(order.order_direction);\n const type = mapOrderTypeToOrdType(order.order_type);\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n const params: Parameters<typeof postSpotOrder>[1] = {\n symbol,\n side,\n type,\n quantity: order.volume,\n newClientOrderId: deriveClientOrderId(order),\n };\n if (type === 'LIMIT') {\n if (order.price === undefined) {\n throw new Error('Binance spot LIMIT order requires price');\n }\n params.price = order.price;\n params.timeInForce = timeInForce;\n }\n if (order.price !== undefined && type === 'MARKET') {\n params.price = order.price;\n }\n const res = await postSpotOrder(credential, params);\n if (isApiError(res)) {\n throw new Error(`Binance submit spot order failed: ${res.code} ${res.msg}`);\n }\n return { order_id: `${res.orderId}` };\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const [, TYPE] = decodePath(order.product_id);\n\n if (TYPE === 'USDT-FUTURE') {\n return submitUnifiedOrder(credential, order);\n }\n if (TYPE === 'SPOT') {\n return submitSpotOrder(credential, order);\n }\n\n throw newError('BINANCE_SUBMIT_ORDER_UNSUPPORTED_PRODUCT_TYPE', { order });\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-binance",
3
- "version": "0.8.7",
3
+ "version": "0.10.0",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -20,6 +20,7 @@
20
20
  "@yuants/data-order": "0.6.4",
21
21
  "@yuants/data-interest-rate": "0.1.46",
22
22
  "@yuants/transfer": "0.2.37",
23
+ "@yuants/exchange": "0.1.0",
23
24
  "rxjs": "~7.5.6",
24
25
  "crypto-js": "^4.2.0"
25
26
  },