@yuants/vendor-binance 0.8.6 → 0.9.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.
- package/dist/api/client.js +2 -4
- package/dist/api/client.js.map +1 -1
- package/dist/legacy_index.js +11 -214
- package/dist/legacy_index.js.map +1 -1
- package/dist/public-data/interest_rate.js +5 -3
- package/dist/public-data/interest_rate.js.map +1 -1
- package/dist/public-data/ohlc.js +1 -1
- package/dist/public-data/ohlc.js.map +1 -1
- package/dist/public-data/product.js +1 -1
- package/dist/public-data/product.js.map +1 -1
- package/dist/public-data/quote.js +5 -5
- package/dist/public-data/quote.js.map +1 -1
- package/dist/services/accounts/spot.js +1 -1
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/accounts/unified.js +1 -1
- package/dist/services/accounts/unified.js.map +1 -1
- package/dist/services/orders/cancelOrder.js +5 -3
- package/dist/services/orders/cancelOrder.js.map +1 -1
- package/dist/services/orders/listOrders.js +2 -2
- package/dist/services/orders/listOrders.js.map +1 -1
- package/dist/services/orders/modifyOrder.js +6 -3
- package/dist/services/orders/modifyOrder.js.map +1 -1
- package/dist/services/orders/order-utils.js +29 -7
- package/dist/services/orders/order-utils.js.map +1 -1
- package/dist/services/orders/submitOrder.js +5 -3
- package/dist/services/orders/submitOrder.js.map +1 -1
- package/lib/api/client.d.ts.map +1 -1
- package/lib/api/client.js +1 -6
- package/lib/api/client.js.map +1 -1
- package/lib/legacy_index.js +10 -213
- package/lib/legacy_index.js.map +1 -1
- package/lib/public-data/interest_rate.js +5 -3
- package/lib/public-data/interest_rate.js.map +1 -1
- package/lib/public-data/ohlc.js +1 -1
- package/lib/public-data/ohlc.js.map +1 -1
- package/lib/public-data/product.js +1 -1
- package/lib/public-data/product.js.map +1 -1
- package/lib/public-data/quote.js +5 -5
- package/lib/public-data/quote.js.map +1 -1
- package/lib/services/accounts/spot.js +1 -1
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/accounts/unified.js +1 -1
- package/lib/services/accounts/unified.js.map +1 -1
- package/lib/services/orders/cancelOrder.d.ts.map +1 -1
- package/lib/services/orders/cancelOrder.js +5 -3
- package/lib/services/orders/cancelOrder.js.map +1 -1
- package/lib/services/orders/listOrders.js +2 -2
- package/lib/services/orders/listOrders.js.map +1 -1
- package/lib/services/orders/modifyOrder.d.ts.map +1 -1
- package/lib/services/orders/modifyOrder.js +6 -3
- package/lib/services/orders/modifyOrder.js.map +1 -1
- package/lib/services/orders/order-utils.d.ts.map +1 -1
- package/lib/services/orders/order-utils.js +29 -7
- package/lib/services/orders/order-utils.js.map +1 -1
- package/lib/services/orders/submitOrder.d.ts.map +1 -1
- package/lib/services/orders/submitOrder.js +5 -3
- package/lib/services/orders/submitOrder.js.map +1 -1
- package/package.json +14 -14
- package/temp/package-deps.json +29 -30
- package/dist/cli.js +0 -3
- package/dist/cli.js.map +0 -1
- package/lib/cli.d.ts +0 -3
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js +0 -5
- package/lib/cli.js.map +0 -1
|
@@ -30,7 +30,7 @@ const getUnifiedAccountInfo = async (credential, _accountId) => {
|
|
|
30
30
|
.map((position) => ({
|
|
31
31
|
position_id: `${position.symbol}/${position.positionSide}`,
|
|
32
32
|
datasource_id: 'BINANCE',
|
|
33
|
-
product_id: (0, utils_1.encodePath)('
|
|
33
|
+
product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', position.symbol),
|
|
34
34
|
direction: position.positionSide === 'LONG'
|
|
35
35
|
? 'LONG'
|
|
36
36
|
: 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,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B,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('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"]}
|
|
@@ -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;
|
|
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
|
-
|
|
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 (
|
|
39
|
+
if (TYPE === 'SPOT') {
|
|
38
40
|
return cancelSpotOrder(credential, order);
|
|
39
41
|
}
|
|
40
|
-
throw
|
|
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;
|
|
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,gCAAkB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,IAAA,2BAAa,EAAC,UAAU,EAAE;QAC1C,MAAM;QACN,OAAO,EAAE,KAAK,CAAC,QAAQ;KACxB,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KAChF;AACH,CAAC,CAAC;AAEF,MAAM,eAAe,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC5F,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;IACD,MAAM,MAAM,GAAG,IAAA,8BAAgB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAe,EAAC,UAAU,EAAE;QAC5C,MAAM;QACN,OAAO,EAAE,KAAK,CAAC,QAAQ;KACxB,CAAC,CAAC;IACH,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,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9C,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;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"]}
|
|
@@ -16,7 +16,7 @@ const listOrders = async (credential, account_id) => {
|
|
|
16
16
|
return ({
|
|
17
17
|
order_id: `${order.orderId}`,
|
|
18
18
|
account_id,
|
|
19
|
-
product_id: (0, utils_1.encodePath)('
|
|
19
|
+
product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', order.symbol),
|
|
20
20
|
order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
|
|
21
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
22
|
volume: +order.origQty,
|
|
@@ -36,7 +36,7 @@ const listOrders = async (credential, account_id) => {
|
|
|
36
36
|
return res.map((order) => ({
|
|
37
37
|
order_id: `${order.orderId}`,
|
|
38
38
|
account_id,
|
|
39
|
-
product_id: (0, utils_1.encodePath)('
|
|
39
|
+
product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', order.symbol),
|
|
40
40
|
order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
|
|
41
41
|
order_direction: (0, order_utils_1.mapSpotSideToOrderDirection)(order.side),
|
|
42
42
|
volume: +order.origQty,
|
|
@@ -1 +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,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,GAAG,CAAC,GAAG,CACZ,CAAC,KAAK,EAAU,EAAE;;YAAC,OAAA,CAAC;gBAClB,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;gBAC5B,UAAU;gBACV,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC;
|
|
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,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,GAAG,CAAC,GAAG,CACZ,CAAC,KAAK,EAAU,EAAE;;YAAC,OAAA,CAAC;gBAClB,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;gBAC5B,UAAU;gBACV,UAAU,EAAE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K,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('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 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('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 ? +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 +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;
|
|
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
|
-
|
|
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 (
|
|
59
|
+
if (TYPE === 'SPOT') {
|
|
57
60
|
return modifySpotOrder(credential, order);
|
|
58
61
|
}
|
|
59
|
-
throw
|
|
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;
|
|
1
|
+
{"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../../src/services/orders/modifyOrder.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,uDAA4F;AAC5F,+CAMuB;AACvB,mDAAmD;AACnD,iDAAoD;AAEpD,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,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;KACvB,CAAC;IAEF,IAAI,IAAI,KAAK,OAAO,EAAE;QACpB,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC5D;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,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,IAAA,iBAAU,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 { 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,
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
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;YACzC,MAAM,IAAI,KAAK,CAAC,+CAA+C,UAAU,EAAE,CAAC,CAAC;SAC9E;QACD,OAAO,MAAM,CAAC;KACf;SAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QAC7C,IAAI,UAAU,KAAK,SAAS,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,MAAM,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,+CAA+C,UAAU,EAAE,CAAC,CAAC;SAC9E;QACD,OAAO,MAAM,CAAC;KACf;IACD,MAAM,IAAI,KA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W;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;
|
|
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
|
-
|
|
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 (
|
|
70
|
+
if (TYPE === 'SPOT') {
|
|
69
71
|
return submitSpotOrder(credential, order);
|
|
70
72
|
}
|
|
71
|
-
throw
|
|
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,GAAG,IAAA,mCAAqB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrD,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5G,MAAM,UAAU,GACd,KAAK,CAAC,eAAe,KAAK,YAAY,IAAI,KAAK,CAAC,eAAe,KAAK,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzG,MAAM,GAAG,GAAG,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AC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,MAAM,CAAC,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.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"temp"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@yuants/protocol": "0.
|
|
12
|
-
"@yuants/data-account": "0.8.
|
|
13
|
-
"@yuants/cache": "0.3.
|
|
14
|
-
"@yuants/data-quote": "0.2.
|
|
15
|
-
"@yuants/utils": "0.
|
|
16
|
-
"@yuants/data-series": "0.3.
|
|
17
|
-
"@yuants/sql": "0.9.
|
|
18
|
-
"@yuants/data-product": "0.4.
|
|
19
|
-
"@yuants/data-ohlc": "0.4.
|
|
20
|
-
"@yuants/data-order": "0.6.
|
|
21
|
-
"@yuants/data-interest-rate": "0.1.
|
|
22
|
-
"@yuants/transfer": "0.2.
|
|
11
|
+
"@yuants/protocol": "0.53.0",
|
|
12
|
+
"@yuants/data-account": "0.8.2",
|
|
13
|
+
"@yuants/cache": "0.3.2",
|
|
14
|
+
"@yuants/data-quote": "0.2.41",
|
|
15
|
+
"@yuants/utils": "0.13.0",
|
|
16
|
+
"@yuants/data-series": "0.3.49",
|
|
17
|
+
"@yuants/sql": "0.9.28",
|
|
18
|
+
"@yuants/data-product": "0.4.19",
|
|
19
|
+
"@yuants/data-ohlc": "0.4.20",
|
|
20
|
+
"@yuants/data-order": "0.6.4",
|
|
21
|
+
"@yuants/data-interest-rate": "0.1.46",
|
|
22
|
+
"@yuants/transfer": "0.2.37",
|
|
23
23
|
"rxjs": "~7.5.6",
|
|
24
24
|
"crypto-js": "^4.2.0"
|
|
25
25
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@rushstack/heft-node-rig": "~1.10.7",
|
|
31
31
|
"@types/heft-jest": "1.0.3",
|
|
32
32
|
"@types/node": "22",
|
|
33
|
-
"@yuants/extension": "0.2.
|
|
33
|
+
"@yuants/extension": "0.2.30",
|
|
34
34
|
"@yuants/tool-kit": "0.2.1",
|
|
35
35
|
"typescript": "~4.7.4",
|
|
36
36
|
"ts-node": "~10.9.2"
|
package/temp/package-deps.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-binance/AGENTS.md": "378369925bffa237cd5e8ef459fe2bc2a141337c",
|
|
3
|
-
"apps/vendor-binance/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-binance/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-binance/CHANGELOG.json": "5f4ef1d89d445fe14f7d194e6214bcd69d746cc4",
|
|
4
|
+
"apps/vendor-binance/CHANGELOG.md": "c48cd3691fb0cade88f1eaa92fc96be6ad970ab2",
|
|
5
5
|
"apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
|
|
6
6
|
"apps/vendor-binance/SESSION_NOTES.md": "de8229b25654f9be78047580112c7987990dd34a",
|
|
7
7
|
"apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
@@ -9,41 +9,40 @@
|
|
|
9
9
|
"apps/vendor-binance/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-binance/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-binance/etc/vendor-binance.api.md": "2094b84e9b5e7503f5c42b31fffee8d7db47fe7b",
|
|
12
|
-
"apps/vendor-binance/package.json": "
|
|
13
|
-
"apps/vendor-binance/src/api/client.ts": "
|
|
12
|
+
"apps/vendor-binance/package.json": "155686888e68e489afeeea1d3528e872736f0b05",
|
|
13
|
+
"apps/vendor-binance/src/api/client.ts": "398778fae5899ad1c65231e3fa65a38b7608cbef",
|
|
14
14
|
"apps/vendor-binance/src/api/private-api.ts": "e7643bd482e4d8f4eefe39aee578e5ea52094b2b",
|
|
15
15
|
"apps/vendor-binance/src/api/public-api.ts": "04671c8732103fac9267c4133a8b96642452daa9",
|
|
16
|
-
"apps/vendor-binance/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
|
|
17
16
|
"apps/vendor-binance/src/index.ts": "50cef2ecce48b30f38bf67728cf1b13afadf9e69",
|
|
18
|
-
"apps/vendor-binance/src/legacy_index.ts": "
|
|
19
|
-
"apps/vendor-binance/src/public-data/interest_rate.ts": "
|
|
20
|
-
"apps/vendor-binance/src/public-data/ohlc.ts": "
|
|
21
|
-
"apps/vendor-binance/src/public-data/product.ts": "
|
|
22
|
-
"apps/vendor-binance/src/public-data/quote.ts": "
|
|
17
|
+
"apps/vendor-binance/src/legacy_index.ts": "7928656d6780752a496b3fcd3151c75cef622661",
|
|
18
|
+
"apps/vendor-binance/src/public-data/interest_rate.ts": "a95d6d8784a9d5b0a82105247a36ae793df82ae0",
|
|
19
|
+
"apps/vendor-binance/src/public-data/ohlc.ts": "bb4f791f96064eca7d45d361ea36cb8ba0ab8fe0",
|
|
20
|
+
"apps/vendor-binance/src/public-data/product.ts": "483b34454f13e5a3c8fbc7b4bd76bf25153da9f5",
|
|
21
|
+
"apps/vendor-binance/src/public-data/quote.ts": "8b14291f4d2abbe55f2e648d1336c89558d925a7",
|
|
23
22
|
"apps/vendor-binance/src/services/account-actions-with-credential.ts": "0f53b961fc5885deaca1c5776e82a95f5acd9917",
|
|
24
23
|
"apps/vendor-binance/src/services/accounts/profile.ts": "63205996e6525d103d1829814e04f7a352e15541",
|
|
25
|
-
"apps/vendor-binance/src/services/accounts/spot.ts": "
|
|
26
|
-
"apps/vendor-binance/src/services/accounts/unified.ts": "
|
|
24
|
+
"apps/vendor-binance/src/services/accounts/spot.ts": "50e9d46466b1f46c0d53ee6e5b3f71cca6120b03",
|
|
25
|
+
"apps/vendor-binance/src/services/accounts/unified.ts": "d2f06fdced4cf6e947f8dbc6c234a3587f14e3cc",
|
|
27
26
|
"apps/vendor-binance/src/services/order-actions-with-credential.ts": "d7ea63781f6c4d3a47e453a48935692c3c9e761d",
|
|
28
|
-
"apps/vendor-binance/src/services/orders/cancelOrder.ts": "
|
|
29
|
-
"apps/vendor-binance/src/services/orders/listOrders.ts": "
|
|
30
|
-
"apps/vendor-binance/src/services/orders/modifyOrder.ts": "
|
|
31
|
-
"apps/vendor-binance/src/services/orders/order-utils.ts": "
|
|
32
|
-
"apps/vendor-binance/src/services/orders/submitOrder.ts": "
|
|
27
|
+
"apps/vendor-binance/src/services/orders/cancelOrder.ts": "7177ca56fd09b11651edbb38e1962363ac67d4ff",
|
|
28
|
+
"apps/vendor-binance/src/services/orders/listOrders.ts": "71456fd11e2a18c2eba16095f4bf24c0e65177cd",
|
|
29
|
+
"apps/vendor-binance/src/services/orders/modifyOrder.ts": "0d1ec4d683e43876e9d53ee29cdc5324301b287e",
|
|
30
|
+
"apps/vendor-binance/src/services/orders/order-utils.ts": "e5278e306dc0e21f7e010424ead327249b1139cc",
|
|
31
|
+
"apps/vendor-binance/src/services/orders/submitOrder.ts": "1e05c8900c9d5e774953a4df22b07639fa927b29",
|
|
33
32
|
"apps/vendor-binance/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
34
33
|
"apps/vendor-binance/.rush/temp/shrinkwrap-deps.json": "7b773443e30eca79d696c3c880b16f7ffcb15b02",
|
|
35
|
-
"libraries/protocol/temp/package-deps.json": "
|
|
36
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
37
|
-
"libraries/cache/temp/package-deps.json": "
|
|
38
|
-
"libraries/data-quote/temp/package-deps.json": "
|
|
39
|
-
"libraries/utils/temp/package-deps.json": "
|
|
40
|
-
"libraries/data-series/temp/package-deps.json": "
|
|
41
|
-
"libraries/sql/temp/package-deps.json": "
|
|
42
|
-
"libraries/data-product/temp/package-deps.json": "
|
|
43
|
-
"libraries/data-ohlc/temp/package-deps.json": "
|
|
44
|
-
"libraries/data-order/temp/package-deps.json": "
|
|
45
|
-
"libraries/data-interest-rate/temp/package-deps.json": "
|
|
46
|
-
"libraries/transfer/temp/package-deps.json": "
|
|
47
|
-
"libraries/extension/temp/package-deps.json": "
|
|
34
|
+
"libraries/protocol/temp/package-deps.json": "00d9a96a90bfc0e57ef3b9547151f2970a600402",
|
|
35
|
+
"libraries/data-account/temp/package-deps.json": "bf8b41c4d878dab0f39ea684fffaf6bc3c74c988",
|
|
36
|
+
"libraries/cache/temp/package-deps.json": "70044bb56d863988aa90d8dcea9e3919bf65d38f",
|
|
37
|
+
"libraries/data-quote/temp/package-deps.json": "2e78640ce117ae07bba4895ac82ea35501a60501",
|
|
38
|
+
"libraries/utils/temp/package-deps.json": "4a683c07df7c75079b700111b9f6beb36c74ff7d",
|
|
39
|
+
"libraries/data-series/temp/package-deps.json": "28ff94f0aeb81e62c78b686e6da9ec2a4a327855",
|
|
40
|
+
"libraries/sql/temp/package-deps.json": "d227fb17cbb9f6e3b445a3b88e0d9978f5c1c823",
|
|
41
|
+
"libraries/data-product/temp/package-deps.json": "c9a00b88e1570374aeb333756f59975d7dcc7400",
|
|
42
|
+
"libraries/data-ohlc/temp/package-deps.json": "5138d2df7a458d21837124761460440fdcf7ec0e",
|
|
43
|
+
"libraries/data-order/temp/package-deps.json": "4a0272551da88c9eb52150775640b12c31786de8",
|
|
44
|
+
"libraries/data-interest-rate/temp/package-deps.json": "ea6718a7984f99121aeb4b5613d304fd2243787e",
|
|
45
|
+
"libraries/transfer/temp/package-deps.json": "93c56bf224a26133b0ef6bb8efa294fec3efbc55",
|
|
46
|
+
"libraries/extension/temp/package-deps.json": "96f8e94be2cbcfe210f7324dfc45b04a4f93d80b",
|
|
48
47
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
49
48
|
}
|
package/dist/cli.js
DELETED
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,CAAC","sourcesContent":["#!/usr/bin/env node\nimport './index';\n"]}
|
package/lib/cli.d.ts
DELETED
package/lib/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,CAAC"}
|
package/lib/cli.js
DELETED
package/lib/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AACA,mBAAiB","sourcesContent":["#!/usr/bin/env node\nimport './index';\n"]}
|