@yuants/vendor-binance 0.7.7 → 0.8.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 (102) hide show
  1. package/dist/api/client.js +70 -0
  2. package/dist/api/client.js.map +1 -0
  3. package/dist/api/private-api.js +162 -0
  4. package/dist/api/private-api.js.map +1 -0
  5. package/dist/api/public-api.js +52 -0
  6. package/dist/api/public-api.js.map +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/interest_rate.js +2 -2
  10. package/dist/interest_rate.js.map +1 -1
  11. package/dist/legacy_index.js +270 -237
  12. package/dist/legacy_index.js.map +1 -1
  13. package/dist/product.js +2 -2
  14. package/dist/product.js.map +1 -1
  15. package/dist/quote.js +4 -4
  16. package/dist/quote.js.map +1 -1
  17. package/dist/services/account-actions-with-credential.js +34 -0
  18. package/dist/services/account-actions-with-credential.js.map +1 -0
  19. package/dist/services/accounts/profile.js +22 -0
  20. package/dist/services/accounts/profile.js.map +1 -0
  21. package/dist/services/accounts/spot.js +44 -0
  22. package/dist/services/accounts/spot.js.map +1 -0
  23. package/dist/services/accounts/unified.js +56 -0
  24. package/dist/services/accounts/unified.js.map +1 -0
  25. package/dist/services/order-actions-with-credential.js +19 -0
  26. package/dist/services/order-actions-with-credential.js.map +1 -0
  27. package/dist/services/orders/cancelOrder.js +39 -0
  28. package/dist/services/orders/cancelOrder.js.map +1 -0
  29. package/dist/services/orders/listOrders.js +49 -0
  30. package/dist/services/orders/listOrders.js.map +1 -0
  31. package/dist/services/orders/order-utils.js +118 -0
  32. package/dist/services/orders/order-utils.js.map +1 -0
  33. package/dist/services/orders/submitOrder.js +70 -0
  34. package/dist/services/orders/submitOrder.js.map +1 -0
  35. package/lib/api/client.d.ts +16 -0
  36. package/lib/api/client.d.ts.map +1 -0
  37. package/lib/api/client.js +80 -0
  38. package/lib/api/client.js.map +1 -0
  39. package/lib/api/private-api.d.ts +477 -0
  40. package/lib/api/private-api.d.ts.map +1 -0
  41. package/lib/api/private-api.js +183 -0
  42. package/lib/api/private-api.js.map +1 -0
  43. package/lib/api/public-api.d.ts +150 -0
  44. package/lib/api/public-api.d.ts.map +1 -0
  45. package/lib/api/public-api.js +61 -0
  46. package/lib/api/public-api.js.map +1 -0
  47. package/lib/index.d.ts +2 -0
  48. package/lib/index.d.ts.map +1 -1
  49. package/lib/index.js +2 -0
  50. package/lib/index.js.map +1 -1
  51. package/lib/interest_rate.js +2 -2
  52. package/lib/interest_rate.js.map +1 -1
  53. package/lib/legacy_index.js +270 -237
  54. package/lib/legacy_index.js.map +1 -1
  55. package/lib/product.js +2 -2
  56. package/lib/product.js.map +1 -1
  57. package/lib/quote.js +4 -4
  58. package/lib/quote.js.map +1 -1
  59. package/lib/services/account-actions-with-credential.d.ts +2 -0
  60. package/lib/services/account-actions-with-credential.d.ts.map +1 -0
  61. package/lib/services/account-actions-with-credential.js +36 -0
  62. package/lib/services/account-actions-with-credential.js.map +1 -0
  63. package/lib/services/accounts/profile.d.ts +7 -0
  64. package/lib/services/accounts/profile.d.ts.map +1 -0
  65. package/lib/services/accounts/profile.js +26 -0
  66. package/lib/services/accounts/profile.js.map +1 -0
  67. package/lib/services/accounts/spot.d.ts +4 -0
  68. package/lib/services/accounts/spot.d.ts.map +1 -0
  69. package/lib/services/accounts/spot.js +48 -0
  70. package/lib/services/accounts/spot.js.map +1 -0
  71. package/lib/services/accounts/unified.d.ts +4 -0
  72. package/lib/services/accounts/unified.d.ts.map +1 -0
  73. package/lib/services/accounts/unified.js +60 -0
  74. package/lib/services/accounts/unified.js.map +1 -0
  75. package/lib/services/order-actions-with-credential.d.ts +2 -0
  76. package/lib/services/order-actions-with-credential.d.ts.map +1 -0
  77. package/lib/services/order-actions-with-credential.js +21 -0
  78. package/lib/services/order-actions-with-credential.js.map +1 -0
  79. package/lib/services/orders/cancelOrder.d.ts +4 -0
  80. package/lib/services/orders/cancelOrder.d.ts.map +1 -0
  81. package/lib/services/orders/cancelOrder.js +43 -0
  82. package/lib/services/orders/cancelOrder.js.map +1 -0
  83. package/lib/services/orders/listOrders.d.ts +4 -0
  84. package/lib/services/orders/listOrders.d.ts.map +1 -0
  85. package/lib/services/orders/listOrders.js +53 -0
  86. package/lib/services/orders/listOrders.js.map +1 -0
  87. package/lib/services/orders/order-utils.d.ts +12 -0
  88. package/lib/services/orders/order-utils.d.ts.map +1 -0
  89. package/lib/services/orders/order-utils.js +131 -0
  90. package/lib/services/orders/order-utils.js.map +1 -0
  91. package/lib/services/orders/submitOrder.d.ts +4 -0
  92. package/lib/services/orders/submitOrder.d.ts.map +1 -0
  93. package/lib/services/orders/submitOrder.js +74 -0
  94. package/lib/services/orders/submitOrder.js.map +1 -0
  95. package/package.json +3 -3
  96. package/temp/package-deps.json +24 -11
  97. package/dist/api.js +0 -248
  98. package/dist/api.js.map +0 -1
  99. package/lib/api.d.ts +0 -576
  100. package/lib/api.d.ts.map +0 -1
  101. package/lib/api.js +0 -256
  102. package/lib/api.js.map +0 -1
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listOrders = void 0;
4
+ const utils_1 = require("@yuants/utils");
5
+ const client_1 = require("../../api/client");
6
+ const private_api_1 = require("../../api/private-api");
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
+ });
30
+ }
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) => ({
37
+ order_id: `${order.orderId}`,
38
+ account_id,
39
+ product_id: (0, utils_1.encodePath)('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 ? +order.price : undefined,
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
+ throw new Error(`Unsupported account_id for listOrders: ${account_id}`);
51
+ };
52
+ exports.listOrders = listOrders;
53
+ //# sourceMappingURL=listOrders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAuD;AACvD,6CAA8C;AAC9C,uDAA+F;AAC/F,+CAKuB;AAEhB,MAAM,UAAU,GAA4C,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;IAClG,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACpC,MAAM,GAAG,GAAG,MAAM,IAAA,oCAAsB,EAAC,UAAU,CAAC,CAAC;QACrD,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;YACnB,MAAM,IAAI,K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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"]}
@@ -0,0 +1,12 @@
1
+ import { IOrder } from '@yuants/data-order';
2
+ export declare const decodeFutureSymbol: (product_id: string) => string;
3
+ export declare const decodeSpotSymbol: (product_id: string) => string;
4
+ export declare const mapOrderDirectionToSide: (direction?: IOrder['order_direction']) => "BUY" | "SELL";
5
+ export declare const mapOrderDirectionToPositionSide: (direction?: IOrder['order_direction']) => "LONG" | "SHORT";
6
+ export declare const mapOrderTypeToOrdType: (order_type?: IOrder['order_type']) => "LIMIT" | "MARKET";
7
+ export declare const mapBinanceOrderTypeToYuants: (binanceType?: string) => IOrder['order_type'];
8
+ export declare const mapBinanceSideToYuantsDirection: (side?: string, positionSide?: string) => IOrder['order_direction'] | undefined;
9
+ export declare const mapSpotSideToOrderDirection: (side?: string) => IOrder['order_direction'];
10
+ export declare const deriveClientOrderId: (order: IOrder) => string;
11
+ export declare const mapBinanceOrderStatus: (status?: string) => IOrder['order_status'];
12
+ //# sourceMappingURL=order-utils.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapBinanceOrderStatus = exports.deriveClientOrderId = exports.mapSpotSideToOrderDirection = exports.mapBinanceSideToYuantsDirection = exports.mapBinanceOrderTypeToYuants = exports.mapOrderTypeToOrdType = exports.mapOrderDirectionToPositionSide = exports.mapOrderDirectionToSide = exports.decodeSpotSymbol = exports.decodeFutureSymbol = void 0;
4
+ const utils_1 = require("@yuants/utils");
5
+ const crypto_1 = require("crypto");
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}`);
10
+ }
11
+ return symbol;
12
+ };
13
+ exports.decodeFutureSymbol = decodeFutureSymbol;
14
+ const decodeSpotSymbol = (product_id) => {
15
+ 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;
19
+ }
20
+ }
21
+ catch (err) {
22
+ // ignore decode errors and fall back to raw product id
23
+ }
24
+ if (!product_id.includes('/')) {
25
+ return product_id;
26
+ }
27
+ throw new Error(`Unsupported product_id for Binance spot: ${product_id}`);
28
+ };
29
+ exports.decodeSpotSymbol = decodeSpotSymbol;
30
+ const mapOrderDirectionToSide = (direction) => {
31
+ switch (direction) {
32
+ case 'OPEN_LONG':
33
+ case 'CLOSE_SHORT':
34
+ return 'BUY';
35
+ case 'OPEN_SHORT':
36
+ case 'CLOSE_LONG':
37
+ return 'SELL';
38
+ default:
39
+ throw new Error(`Unsupported order_direction: ${direction}`);
40
+ }
41
+ };
42
+ exports.mapOrderDirectionToSide = mapOrderDirectionToSide;
43
+ const mapOrderDirectionToPositionSide = (direction) => {
44
+ switch (direction) {
45
+ case 'OPEN_LONG':
46
+ case 'CLOSE_LONG':
47
+ return 'LONG';
48
+ case 'OPEN_SHORT':
49
+ case 'CLOSE_SHORT':
50
+ return 'SHORT';
51
+ default:
52
+ throw new Error(`Unsupported order_direction for positionSide: ${direction}`);
53
+ }
54
+ };
55
+ exports.mapOrderDirectionToPositionSide = mapOrderDirectionToPositionSide;
56
+ const mapOrderTypeToOrdType = (order_type) => {
57
+ switch (order_type) {
58
+ case 'LIMIT':
59
+ case 'MAKER':
60
+ return 'LIMIT';
61
+ case 'MARKET':
62
+ return 'MARKET';
63
+ default:
64
+ throw new Error(`Unsupported order_type: ${order_type}`);
65
+ }
66
+ };
67
+ exports.mapOrderTypeToOrdType = mapOrderTypeToOrdType;
68
+ const mapBinanceOrderTypeToYuants = (binanceType) => {
69
+ switch (binanceType) {
70
+ case 'LIMIT':
71
+ return 'LIMIT';
72
+ case 'MARKET':
73
+ return 'MARKET';
74
+ default:
75
+ return 'LIMIT';
76
+ }
77
+ };
78
+ exports.mapBinanceOrderTypeToYuants = mapBinanceOrderTypeToYuants;
79
+ const mapBinanceSideToYuantsDirection = (side, positionSide) => {
80
+ if (!side || !positionSide) {
81
+ return undefined;
82
+ }
83
+ if (positionSide === 'LONG') {
84
+ return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';
85
+ }
86
+ if (positionSide === 'SHORT') {
87
+ return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';
88
+ }
89
+ return undefined;
90
+ };
91
+ exports.mapBinanceSideToYuantsDirection = mapBinanceSideToYuantsDirection;
92
+ const mapSpotSideToOrderDirection = (side) => {
93
+ if (side === 'SELL') {
94
+ return 'CLOSE_LONG';
95
+ }
96
+ return 'OPEN_LONG';
97
+ };
98
+ exports.mapSpotSideToOrderDirection = mapSpotSideToOrderDirection;
99
+ const deriveClientOrderId = (order) => {
100
+ if (order.order_id)
101
+ return `${order.order_id}`;
102
+ const payload = JSON.stringify({
103
+ account_id: order.account_id,
104
+ product_id: order.product_id,
105
+ order_direction: order.order_direction,
106
+ order_type: order.order_type,
107
+ price: order.price,
108
+ volume: order.volume,
109
+ });
110
+ return `YUANTS${(0, crypto_1.createHash)('sha256').update(payload).digest('hex').slice(0, 24)}`;
111
+ };
112
+ exports.deriveClientOrderId = deriveClientOrderId;
113
+ const BinanceOrderStatusMap = {
114
+ NEW: 'ACCEPTED',
115
+ PARTIALLY_FILLED: 'TRADED',
116
+ FILLED: 'TRADED',
117
+ PENDING_NEW: 'ACCEPTED',
118
+ PENDING_CANCEL: 'CANCELLED',
119
+ CANCELED: 'CANCELLED',
120
+ CANCELLED: 'CANCELLED',
121
+ REJECTED: 'CANCELLED',
122
+ EXPIRED: 'CANCELLED',
123
+ };
124
+ const mapBinanceOrderStatus = (status) => {
125
+ var _a;
126
+ if (!status)
127
+ return 'ACCEPTED';
128
+ return (_a = BinanceOrderStatusMap[status]) !== null && _a !== void 0 ? _a : 'ACCEPTED';
129
+ };
130
+ exports.mapBinanceOrderStatus = mapBinanceOrderStatus;
131
+ //# sourceMappingURL=order-utils.js.map
@@ -0,0 +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;IAClD,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,MAAM,EAAE;QACzC,MAAM,IAAI,KAAK,CAAC,+CAA+C,UAAU,EAAE,CAAC,CAAC;KAC9E;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AANW,QAAA,kBAAkB,sBAM7B;AAEK,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAE,EAAE;IACrD,IAAI;QACF,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,EAAE,MAAK,MAAM,IAAI,MAAM,EAAE;YAChD,OAAO,MAAM,CAAC;SACf;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,uDAAuD;KACxD;IACD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC7B,OAAO,UAAU,CAAC;KACnB;IACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,UAAU,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC;AAbW,QAAA,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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 [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"]}
@@ -0,0 +1,4 @@
1
+ import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';
2
+ import { ICredential } from '../../api/private-api';
3
+ export declare const submitOrder: IActionHandlerOfSubmitOrder<ICredential>;
4
+ //# sourceMappingURL=submitOrder.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.submitOrder = void 0;
4
+ const client_1 = require("../../api/client");
5
+ const private_api_1 = require("../../api/private-api");
6
+ const order_utils_1 = require("./order-utils");
7
+ const submitUnifiedOrder = async (credential, order) => {
8
+ const symbol = (0, order_utils_1.decodeFutureSymbol)(order.product_id);
9
+ if (!order.volume) {
10
+ throw new Error('Binance submitOrder requires order.volume to be set');
11
+ }
12
+ const side = (0, order_utils_1.mapOrderDirectionToSide)(order.order_direction);
13
+ const positionSide = (0, order_utils_1.mapOrderDirectionToPositionSide)(order.order_direction);
14
+ const type = (0, order_utils_1.mapOrderTypeToOrdType)(order.order_type);
15
+ const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;
16
+ const reduceOnly = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;
17
+ const res = await (0, private_api_1.postUmOrder)(credential, {
18
+ symbol,
19
+ side,
20
+ positionSide,
21
+ type,
22
+ quantity: order.volume,
23
+ price: order.price,
24
+ timeInForce,
25
+ reduceOnly,
26
+ newClientOrderId: (0, order_utils_1.deriveClientOrderId)(order),
27
+ });
28
+ if ((0, client_1.isApiError)(res)) {
29
+ throw new Error(`Binance submit unified order failed: ${res.code} ${res.msg}`);
30
+ }
31
+ return { order_id: `${res.orderId}` };
32
+ };
33
+ const submitSpotOrder = async (credential, order) => {
34
+ const symbol = (0, order_utils_1.decodeSpotSymbol)(order.product_id);
35
+ if (!order.volume) {
36
+ throw new Error('Binance submitOrder requires order.volume to be set');
37
+ }
38
+ const side = (0, order_utils_1.mapOrderDirectionToSide)(order.order_direction);
39
+ const type = (0, order_utils_1.mapOrderTypeToOrdType)(order.order_type);
40
+ const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;
41
+ const params = {
42
+ symbol,
43
+ side,
44
+ type,
45
+ quantity: order.volume,
46
+ newClientOrderId: (0, order_utils_1.deriveClientOrderId)(order),
47
+ };
48
+ if (type === 'LIMIT') {
49
+ if (order.price === undefined) {
50
+ throw new Error('Binance spot LIMIT order requires price');
51
+ }
52
+ params.price = order.price;
53
+ params.timeInForce = timeInForce;
54
+ }
55
+ if (order.price !== undefined && type === 'MARKET') {
56
+ params.price = order.price;
57
+ }
58
+ const res = await (0, private_api_1.postSpotOrder)(credential, params);
59
+ if ((0, client_1.isApiError)(res)) {
60
+ throw new Error(`Binance submit spot order failed: ${res.code} ${res.msg}`);
61
+ }
62
+ return { order_id: `${res.orderId}` };
63
+ };
64
+ const submitOrder = async (credential, order) => {
65
+ if (order.account_id.includes('/unified/')) {
66
+ return submitUnifiedOrder(credential, order);
67
+ }
68
+ if (order.account_id.includes('/spot/')) {
69
+ return submitSpotOrder(credential, order);
70
+ }
71
+ throw new Error(`Unsupported account_id for submitOrder: ${order.account_id}`);
72
+ };
73
+ exports.submitOrder = submitOrder;
74
+ //# sourceMappingURL=submitOrder.js.map
@@ -0,0 +1 @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IAAI,IAAI,KAAK,QAAQ,EAAE;QAClD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;KAC5B;IACD,MAAM,GAAG,GAAG,MAAM,IAAA,2BAAa,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACpD,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KAC7E;IACD,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;AACxC,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 { 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-binance",
3
- "version": "0.7.7",
3
+ "version": "0.8.0",
4
4
  "bin": "lib/cli.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@yuants/protocol": "0.50.4",
13
- "@yuants/data-account": "0.7.0",
13
+ "@yuants/data-account": "0.7.1",
14
14
  "@yuants/cache": "0.3.0",
15
15
  "@yuants/data-quote": "0.2.37",
16
16
  "@yuants/utils": "0.11.0",
@@ -18,7 +18,7 @@
18
18
  "@yuants/sql": "0.9.24",
19
19
  "@yuants/data-product": "0.4.15",
20
20
  "@yuants/data-ohlc": "0.4.16",
21
- "@yuants/data-order": "0.5.0",
21
+ "@yuants/data-order": "0.6.0",
22
22
  "@yuants/data-interest-rate": "0.1.42",
23
23
  "@yuants/transfer": "0.2.33",
24
24
  "rxjs": "~7.5.6",
@@ -1,24 +1,37 @@
1
1
  {
2
- "apps/vendor-binance/CHANGELOG.json": "7ccebcf19347b5ad938ffc205eca8f2aa5ee1c07",
3
- "apps/vendor-binance/CHANGELOG.md": "78df8622290b96c03f55ca18424597cd68f4dfe9",
2
+ "apps/vendor-binance/AGENTS.md": "008794c59d22e7c94cb924501617014c2181073b",
3
+ "apps/vendor-binance/CHANGELOG.json": "873a37e52b6d11537148d56a127aca3e44914379",
4
+ "apps/vendor-binance/CHANGELOG.md": "ebd87237778e3424e1bc2c424f37d2f76a7ef812",
4
5
  "apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
6
+ "apps/vendor-binance/SESSION_NOTES.md": "14ffb6e43fda6b0b4f8d577781563884a8026f15",
5
7
  "apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
6
8
  "apps/vendor-binance/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
7
9
  "apps/vendor-binance/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
8
10
  "apps/vendor-binance/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
9
11
  "apps/vendor-binance/etc/vendor-binance.api.md": "2094b84e9b5e7503f5c42b31fffee8d7db47fe7b",
10
- "apps/vendor-binance/package.json": "1a14ad25d1ad4ddb19f8304c47ca1d3907600f24",
11
- "apps/vendor-binance/src/api.ts": "d38a20cecdc405023b098d4c01446c0565d2e9fb",
12
+ "apps/vendor-binance/package.json": "121e9aabb629fcc6ad9f1c833824fee37ad1df26",
13
+ "apps/vendor-binance/src/api/client.ts": "bce65e7525e12ac6ecfb69899f5ed2056ee80404",
14
+ "apps/vendor-binance/src/api/private-api.ts": "1c858f64fa8b498a453dd39b2f808c7b3f6b1cdd",
15
+ "apps/vendor-binance/src/api/public-api.ts": "a1ba3d006c6ebca42fda068dc3bcbf604984a917",
12
16
  "apps/vendor-binance/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
13
- "apps/vendor-binance/src/index.ts": "7573aa8600e289793c2e834dee11fef5a664efae",
14
- "apps/vendor-binance/src/interest_rate.ts": "ee82ea130495c151b67850a8b90ca972cb8a8d84",
15
- "apps/vendor-binance/src/legacy_index.ts": "4a240f03ae64527d1e73ab56af4056529b217ce5",
16
- "apps/vendor-binance/src/product.ts": "ea88fc2e6d0e57ee01d13131b26eb052d8f29fb7",
17
- "apps/vendor-binance/src/quote.ts": "3184973a00240676040c8a4898c6a20563a9a6a6",
17
+ "apps/vendor-binance/src/index.ts": "30281e0e54ae7528487ae0808d15f4c560f383a2",
18
+ "apps/vendor-binance/src/interest_rate.ts": "dd7f7d529e4916fa3d50cafaff3bd99e2a8b3533",
19
+ "apps/vendor-binance/src/legacy_index.ts": "0b56f9a9d4d34ca0a136d267e03ae984b86d8149",
20
+ "apps/vendor-binance/src/product.ts": "78d38412464870975ff74f7d20bbf2b1b6796127",
21
+ "apps/vendor-binance/src/quote.ts": "37ff0ab9b1521fa2d2e6e9187a43a89df361d802",
22
+ "apps/vendor-binance/src/services/account-actions-with-credential.ts": "0f53b961fc5885deaca1c5776e82a95f5acd9917",
23
+ "apps/vendor-binance/src/services/accounts/profile.ts": "63205996e6525d103d1829814e04f7a352e15541",
24
+ "apps/vendor-binance/src/services/accounts/spot.ts": "3c2826d454a94ad519dd4183ef4bb45a9840f75a",
25
+ "apps/vendor-binance/src/services/accounts/unified.ts": "0d4103dc3f9a5ce171872f5d5a2758a3307dde53",
26
+ "apps/vendor-binance/src/services/order-actions-with-credential.ts": "dc6caeffcbdecb9bc20404463a87133a196e0c5e",
27
+ "apps/vendor-binance/src/services/orders/cancelOrder.ts": "44b6f87bca28108e0aebe4ef469172ba0c86b402",
28
+ "apps/vendor-binance/src/services/orders/listOrders.ts": "b81b8de6a20de37a692a57569b93bdfb9b96a9ed",
29
+ "apps/vendor-binance/src/services/orders/order-utils.ts": "04f6af66ecaba2d405cb6791bf64412fabc64d0d",
30
+ "apps/vendor-binance/src/services/orders/submitOrder.ts": "2d6a9ed669d1d6922d3b496d566d23ed63dc403f",
18
31
  "apps/vendor-binance/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
19
32
  "apps/vendor-binance/.rush/temp/shrinkwrap-deps.json": "7b773443e30eca79d696c3c880b16f7ffcb15b02",
20
33
  "libraries/protocol/temp/package-deps.json": "35bc77333a1c85db1cd130579963e8cefa00f56c",
21
- "libraries/data-account/temp/package-deps.json": "23ce351fb7d34192c8885a00c1f0e8d49f592a9c",
34
+ "libraries/data-account/temp/package-deps.json": "e7b28ee5c9f5236a894a8034de5a037cc7ecb088",
22
35
  "libraries/cache/temp/package-deps.json": "49789a92426969daa31f0c956bb56bd783929765",
23
36
  "libraries/data-quote/temp/package-deps.json": "752ea44d75cbe7a652ace79629c02ca92a92cf1d",
24
37
  "libraries/utils/temp/package-deps.json": "c58f1ca8f498315d9a0219ca8c498299a41d297b",
@@ -26,7 +39,7 @@
26
39
  "libraries/sql/temp/package-deps.json": "e3b6f24485a429fb24cacbf0d6150f55ca394706",
27
40
  "libraries/data-product/temp/package-deps.json": "0a4e14971c7dc350b84712fb16c07fefad351619",
28
41
  "libraries/data-ohlc/temp/package-deps.json": "6e10227e1c394ad0b5a71e0f810914760e9b7956",
29
- "libraries/data-order/temp/package-deps.json": "921c6745e9a502669524f7a7d276bff69c25491c",
42
+ "libraries/data-order/temp/package-deps.json": "0e2f026ee9847657a72801c106c040fcf905e7b5",
30
43
  "libraries/data-interest-rate/temp/package-deps.json": "11bb199efb64628f67b1165e11d6c85dd7114a9a",
31
44
  "libraries/transfer/temp/package-deps.json": "708a4caf79d042cad56a39f0b00d399bca04af40",
32
45
  "libraries/extension/temp/package-deps.json": "fd20507284f9fd74b4de6f9855c8cead9cc132e8",