@yuants/vendor-binance 0.7.8 → 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.
- package/dist/api/client.js +70 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/private-api.js +162 -0
- package/dist/api/private-api.js.map +1 -0
- package/dist/api/public-api.js +52 -0
- package/dist/api/public-api.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interest_rate.js +2 -2
- package/dist/interest_rate.js.map +1 -1
- package/dist/legacy_index.js +270 -237
- package/dist/legacy_index.js.map +1 -1
- package/dist/product.js +2 -2
- package/dist/product.js.map +1 -1
- package/dist/quote.js +4 -4
- package/dist/quote.js.map +1 -1
- package/dist/services/account-actions-with-credential.js +34 -0
- package/dist/services/account-actions-with-credential.js.map +1 -0
- package/dist/services/accounts/profile.js +22 -0
- package/dist/services/accounts/profile.js.map +1 -0
- package/dist/services/accounts/spot.js +44 -0
- package/dist/services/accounts/spot.js.map +1 -0
- package/dist/services/accounts/unified.js +56 -0
- package/dist/services/accounts/unified.js.map +1 -0
- package/dist/services/order-actions-with-credential.js +19 -0
- package/dist/services/order-actions-with-credential.js.map +1 -0
- package/dist/services/orders/cancelOrder.js +39 -0
- package/dist/services/orders/cancelOrder.js.map +1 -0
- package/dist/services/orders/listOrders.js +49 -0
- package/dist/services/orders/listOrders.js.map +1 -0
- package/dist/services/orders/order-utils.js +118 -0
- package/dist/services/orders/order-utils.js.map +1 -0
- package/dist/services/orders/submitOrder.js +70 -0
- package/dist/services/orders/submitOrder.js.map +1 -0
- package/lib/api/client.d.ts +16 -0
- package/lib/api/client.d.ts.map +1 -0
- package/lib/api/client.js +80 -0
- package/lib/api/client.js.map +1 -0
- package/lib/api/private-api.d.ts +477 -0
- package/lib/api/private-api.d.ts.map +1 -0
- package/lib/api/private-api.js +183 -0
- package/lib/api/private-api.js.map +1 -0
- package/lib/api/public-api.d.ts +150 -0
- package/lib/api/public-api.d.ts.map +1 -0
- package/lib/api/public-api.js +61 -0
- package/lib/api/public-api.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/interest_rate.js +2 -2
- package/lib/interest_rate.js.map +1 -1
- package/lib/legacy_index.js +270 -237
- package/lib/legacy_index.js.map +1 -1
- package/lib/product.js +2 -2
- package/lib/product.js.map +1 -1
- package/lib/quote.js +4 -4
- package/lib/quote.js.map +1 -1
- package/lib/services/account-actions-with-credential.d.ts +2 -0
- package/lib/services/account-actions-with-credential.d.ts.map +1 -0
- package/lib/services/account-actions-with-credential.js +36 -0
- package/lib/services/account-actions-with-credential.js.map +1 -0
- package/lib/services/accounts/profile.d.ts +7 -0
- package/lib/services/accounts/profile.d.ts.map +1 -0
- package/lib/services/accounts/profile.js +26 -0
- package/lib/services/accounts/profile.js.map +1 -0
- package/lib/services/accounts/spot.d.ts +4 -0
- package/lib/services/accounts/spot.d.ts.map +1 -0
- package/lib/services/accounts/spot.js +48 -0
- package/lib/services/accounts/spot.js.map +1 -0
- package/lib/services/accounts/unified.d.ts +4 -0
- package/lib/services/accounts/unified.d.ts.map +1 -0
- package/lib/services/accounts/unified.js +60 -0
- package/lib/services/accounts/unified.js.map +1 -0
- package/lib/services/order-actions-with-credential.d.ts +2 -0
- package/lib/services/order-actions-with-credential.d.ts.map +1 -0
- package/lib/services/order-actions-with-credential.js +21 -0
- package/lib/services/order-actions-with-credential.js.map +1 -0
- package/lib/services/orders/cancelOrder.d.ts +4 -0
- package/lib/services/orders/cancelOrder.d.ts.map +1 -0
- package/lib/services/orders/cancelOrder.js +43 -0
- package/lib/services/orders/cancelOrder.js.map +1 -0
- package/lib/services/orders/listOrders.d.ts +4 -0
- package/lib/services/orders/listOrders.d.ts.map +1 -0
- package/lib/services/orders/listOrders.js +53 -0
- package/lib/services/orders/listOrders.js.map +1 -0
- package/lib/services/orders/order-utils.d.ts +12 -0
- package/lib/services/orders/order-utils.d.ts.map +1 -0
- package/lib/services/orders/order-utils.js +131 -0
- package/lib/services/orders/order-utils.js.map +1 -0
- package/lib/services/orders/submitOrder.d.ts +4 -0
- package/lib/services/orders/submitOrder.d.ts.map +1 -0
- package/lib/services/orders/submitOrder.js +74 -0
- package/lib/services/orders/submitOrder.js.map +1 -0
- package/package.json +1 -1
- package/temp/package-deps.json +22 -9
- package/dist/api.js +0 -248
- package/dist/api.js.map +0 -1
- package/lib/api.d.ts +0 -576
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -256
- 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,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AAC,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"]}
|
|
@@ -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,gBAAgB,oBAa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AAA,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 @@
|
|
|
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 @@
|
|
|
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,KAA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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
package/temp/package-deps.json
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/vendor-binance/
|
|
3
|
-
"apps/vendor-binance/CHANGELOG.
|
|
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": "
|
|
11
|
-
"apps/vendor-binance/src/api.ts": "
|
|
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": "
|
|
14
|
-
"apps/vendor-binance/src/interest_rate.ts": "
|
|
15
|
-
"apps/vendor-binance/src/legacy_index.ts": "
|
|
16
|
-
"apps/vendor-binance/src/product.ts": "
|
|
17
|
-
"apps/vendor-binance/src/quote.ts": "
|
|
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",
|
package/dist/api.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { GlobalPrometheusRegistry } from '@yuants/protocol';
|
|
2
|
-
import { formatTime } from '@yuants/utils';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import CryptoJS from 'crypto-js';
|
|
5
|
-
const MetricBinanceApiUsedWeight = GlobalPrometheusRegistry.gauge('binance_api_used_weight', '');
|
|
6
|
-
export const isError = (x) => x.code !== undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Binance 币安 API
|
|
9
|
-
*
|
|
10
|
-
* https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/CHANGELOG
|
|
11
|
-
*/
|
|
12
|
-
export class ApiClient {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
/**
|
|
16
|
-
* 获取交易规则和交易对
|
|
17
|
-
*
|
|
18
|
-
* https://binance-docs.github.io/apidocs/futures/cn/#0f3f2d5ee7
|
|
19
|
-
*/
|
|
20
|
-
this.getFutureExchangeInfo = () => this.request('GET', 'https://fapi.binance.com/fapi/v1/exchangeInfo');
|
|
21
|
-
/**
|
|
22
|
-
* 查询资金费率历史
|
|
23
|
-
*
|
|
24
|
-
* https://binance-docs.github.io/apidocs/futures/cn/#31dbeb24c4
|
|
25
|
-
*/
|
|
26
|
-
this.getFutureFundingRate = (params) => this.request('GET', 'https://fapi.binance.com/fapi/v1/fundingRate', params);
|
|
27
|
-
/**
|
|
28
|
-
* 最新标记价格和资金费率
|
|
29
|
-
*
|
|
30
|
-
* 采集各大交易所数据加权平均
|
|
31
|
-
*
|
|
32
|
-
* 权重: 带symbol为1;不带symbol为10
|
|
33
|
-
*
|
|
34
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price
|
|
35
|
-
*/
|
|
36
|
-
this.getFuturePremiumIndex = (params) => this.request('GET', 'https://fapi.binance.com/fapi/v1/premiumIndex', params);
|
|
37
|
-
/**
|
|
38
|
-
* 当前最优挂单
|
|
39
|
-
*
|
|
40
|
-
* 返回当前最优的挂单(最高买单,最低卖单)
|
|
41
|
-
*
|
|
42
|
-
* 权重: 单交易对2,无交易对5
|
|
43
|
-
*
|
|
44
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker
|
|
45
|
-
*/
|
|
46
|
-
this.getFutureBookTicker = (params) => this.request('GET', 'https://fapi.binance.com/fapi/v1/ticker/bookTicker', params);
|
|
47
|
-
/**
|
|
48
|
-
* 获取未平仓合约数
|
|
49
|
-
*
|
|
50
|
-
* 权重: 1
|
|
51
|
-
*
|
|
52
|
-
* 更新速率: 3s
|
|
53
|
-
*
|
|
54
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest
|
|
55
|
-
*/
|
|
56
|
-
this.getFutureOpenInterest = (params) => this.request('GET', 'https://fapi.binance.com/fapi/v1/openInterest', params);
|
|
57
|
-
/**
|
|
58
|
-
* 查询账户信息(USER_DATA)
|
|
59
|
-
*
|
|
60
|
-
* 查询账户信息
|
|
61
|
-
*
|
|
62
|
-
* 权重: 20
|
|
63
|
-
*
|
|
64
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Information
|
|
65
|
-
*/
|
|
66
|
-
this.getUnifiedAccountInfo = () => this.request('GET', 'https://papi.binance.com/papi/v1/account');
|
|
67
|
-
/**
|
|
68
|
-
* 获取UM账户信息
|
|
69
|
-
*
|
|
70
|
-
* 现有UM账户资产和仓位信息
|
|
71
|
-
*
|
|
72
|
-
* 权重: 5
|
|
73
|
-
*
|
|
74
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Account-Detail
|
|
75
|
-
*/
|
|
76
|
-
this.getUnifiedUmAccount = () => this.request('GET', 'https://papi.binance.com/papi/v1/um/account');
|
|
77
|
-
/**
|
|
78
|
-
* 查看当前全部UM挂单(USER_DATA)
|
|
79
|
-
*
|
|
80
|
-
* 查看当前全部UM挂单,请小心使用不带symbol参数的调用
|
|
81
|
-
*
|
|
82
|
-
* 权重: 带symbol 1 - 不带 40
|
|
83
|
-
*/
|
|
84
|
-
this.getUnifiedUmOpenOrders = (params) => this.request('GET', 'https://papi.binance.com/papi/v1/um/openOrders', params);
|
|
85
|
-
/**
|
|
86
|
-
* 查询账户余额(USER_DATA)
|
|
87
|
-
*
|
|
88
|
-
* 查询账户余额
|
|
89
|
-
*
|
|
90
|
-
* 权重: 20
|
|
91
|
-
*
|
|
92
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Balance
|
|
93
|
-
*/
|
|
94
|
-
this.getUnifiedAccountBalance = (params) => this.request('GET', 'https://papi.binance.com/papi/v1/balance', params);
|
|
95
|
-
/**
|
|
96
|
-
* 账户信息 (USER_DATA)
|
|
97
|
-
*
|
|
98
|
-
* 权重: 20
|
|
99
|
-
*
|
|
100
|
-
* https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data
|
|
101
|
-
*/
|
|
102
|
-
this.getSpotAccountInfo = (params) => this.request('GET', 'https://api.binance.com/api/v3/account', params);
|
|
103
|
-
/**
|
|
104
|
-
* 用户万向划转(USER_DATA)
|
|
105
|
-
*
|
|
106
|
-
* 用户万向划转
|
|
107
|
-
*
|
|
108
|
-
* 您需要开通api key 允许万向划转权限来调用此接口。
|
|
109
|
-
*
|
|
110
|
-
* 权重: 900
|
|
111
|
-
*
|
|
112
|
-
* https://developers.binance.com/docs/zh-CN/wallet/asset/user-universal-transfer
|
|
113
|
-
*/
|
|
114
|
-
this.postAssetTransfer = (params) => this.request('POST', 'https://api.binance.com/sapi/v1/asset/transfer', params);
|
|
115
|
-
/**
|
|
116
|
-
* 统一账户资金归集(TRADE)
|
|
117
|
-
*
|
|
118
|
-
* 资金归集到统一账户钱包
|
|
119
|
-
*
|
|
120
|
-
* 权重: 750
|
|
121
|
-
*
|
|
122
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Fund-Auto-collection
|
|
123
|
-
*
|
|
124
|
-
* ISSUE(2024-07-18): 目前这是唯一能够将资金从原 U 本位合约账户转入统一账户的接口。
|
|
125
|
-
*/
|
|
126
|
-
this.postUnifiedAccountAutoCollection = () => this.request('POST', 'https://papi.binance.com/papi/v1/auto-collection');
|
|
127
|
-
/**
|
|
128
|
-
* 获取充值地址(支持多网络)(USER_DATA)
|
|
129
|
-
*
|
|
130
|
-
* 获取充值地址
|
|
131
|
-
*
|
|
132
|
-
* 权重: 10
|
|
133
|
-
*
|
|
134
|
-
* https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-address
|
|
135
|
-
*/
|
|
136
|
-
this.getDepositAddress = (params) => this.request('GET', 'https://api.binance.com/sapi/v1/capital/deposit/address', params);
|
|
137
|
-
/**
|
|
138
|
-
* 查询子账户列表(适用主账户)
|
|
139
|
-
*
|
|
140
|
-
* 权重: 1
|
|
141
|
-
*
|
|
142
|
-
* https://developers.binance.com/docs/zh-CN/sub_account/account-management/Query-Sub-account-List
|
|
143
|
-
*/
|
|
144
|
-
this.getSubAccountList = (params) => this.request('GET', 'https://api.binance.com/sapi/v1/sub-account/list');
|
|
145
|
-
/**
|
|
146
|
-
* 提币(USER_DATA)
|
|
147
|
-
*
|
|
148
|
-
* 权重: 600
|
|
149
|
-
*
|
|
150
|
-
* https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw
|
|
151
|
-
*/
|
|
152
|
-
this.postWithdraw = (params) => this.request('POST', 'https://api.binance.com/sapi/v1/capital/withdraw/apply', params);
|
|
153
|
-
/**
|
|
154
|
-
* 获取提币历史(支持多网络)(USER_DATA)
|
|
155
|
-
*
|
|
156
|
-
* 获取提币历史 (支持多网络)
|
|
157
|
-
*
|
|
158
|
-
* 请求权重(IP)#
|
|
159
|
-
* 18000 请求限制: 每秒10次
|
|
160
|
-
*
|
|
161
|
-
* 本接口特别采用每秒UID速率限制,用户的总秒级 UID 速率限制为180000/秒。从该接口收到的响应包含key X-SAPI-USED-UID-WEIGHT-1S,该key定义了当前 UID 使用的权重
|
|
162
|
-
*
|
|
163
|
-
* https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw-history
|
|
164
|
-
*/
|
|
165
|
-
this.getWithdrawHistory = (params) => this.request('GET', 'https://api.binance.com/sapi/v1/capital/withdraw/history', params);
|
|
166
|
-
/**
|
|
167
|
-
* 获取充值历史(支持多网络)
|
|
168
|
-
*
|
|
169
|
-
* 权重: 1
|
|
170
|
-
*
|
|
171
|
-
* https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-history
|
|
172
|
-
*/
|
|
173
|
-
this.getDepositHistory = (params) => this.request('GET', 'https://api.binance.com/sapi/v1/capital/deposit/hisrec', params);
|
|
174
|
-
/**
|
|
175
|
-
* UM下单(TRADE)
|
|
176
|
-
*
|
|
177
|
-
* 权重: 1
|
|
178
|
-
*
|
|
179
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/New-UM-Order
|
|
180
|
-
*/
|
|
181
|
-
this.postUmOrder = (params) => this.request('POST', 'https://papi.binance.com/papi/v1/um/order', params);
|
|
182
|
-
this.deleteUmOrder = (params) => this.request('DELETE', 'https://papi.binance.com/papi/v1/um/order', params);
|
|
183
|
-
/**
|
|
184
|
-
* 获取所有全仓杠杆交易对(MARKET_DATA)
|
|
185
|
-
*
|
|
186
|
-
* 权重: 1
|
|
187
|
-
*
|
|
188
|
-
* https://developers.binance.com/docs/zh-CN/margin_trading/market-data/Get-All-Cross-Margin-Pairs
|
|
189
|
-
*/
|
|
190
|
-
this.getMarginAllPairs = (params) => this.request('GET', 'https://api.binance.com/sapi/v1/margin/allPairs', params);
|
|
191
|
-
/**
|
|
192
|
-
* 获取UM损益资金流水(USER_DATA)
|
|
193
|
-
*
|
|
194
|
-
* 权重: 30
|
|
195
|
-
*
|
|
196
|
-
* https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Income-History
|
|
197
|
-
*/
|
|
198
|
-
this.getUMIncome = (params) => this.request('GET', 'https://api.binance.com/papi/v1/um/income', params);
|
|
199
|
-
}
|
|
200
|
-
async request(method, path, params = {}) {
|
|
201
|
-
const url = new URL(path);
|
|
202
|
-
params.recvWindow = 5000;
|
|
203
|
-
params.timestamp = Date.now();
|
|
204
|
-
for (const key in params) {
|
|
205
|
-
if (params[key] === undefined)
|
|
206
|
-
continue;
|
|
207
|
-
url.searchParams.set(key, params[key]);
|
|
208
|
-
}
|
|
209
|
-
if (!this.config.auth) {
|
|
210
|
-
console.info(formatTime(Date.now()), method, url.href);
|
|
211
|
-
const res = await fetch(url.href, { method });
|
|
212
|
-
const usedWeight1M = res.headers.get('x-mbx-used-weight-1m');
|
|
213
|
-
console.info(formatTime(Date.now()), 'response', method, url.href, res.status, `usedWeight1M=${usedWeight1M !== null && usedWeight1M !== void 0 ? usedWeight1M : 'N/A'}`);
|
|
214
|
-
if (usedWeight1M) {
|
|
215
|
-
MetricBinanceApiUsedWeight.set(+usedWeight1M);
|
|
216
|
-
}
|
|
217
|
-
return res.json();
|
|
218
|
-
}
|
|
219
|
-
const secret_key = this.config.auth.secret_key;
|
|
220
|
-
const signData = url.search.slice(1);
|
|
221
|
-
const str = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(signData, secret_key));
|
|
222
|
-
url.searchParams.set('signature', str);
|
|
223
|
-
const headers = {
|
|
224
|
-
'Content-Type': 'application/json;charset=utf-8',
|
|
225
|
-
'X-MBX-APIKEY': this.config.auth.public_key,
|
|
226
|
-
};
|
|
227
|
-
console.info(formatTime(Date.now()), method, url.href, JSON.stringify(headers), url.searchParams.toString(), signData);
|
|
228
|
-
const res = await fetch(url.href, {
|
|
229
|
-
method,
|
|
230
|
-
headers,
|
|
231
|
-
});
|
|
232
|
-
const usedWeight1M = res.headers.get('x-mbx-used-weight-1m');
|
|
233
|
-
console.info(formatTime(Date.now()), 'response', method, url.href, res.status, `usedWeight1M=${usedWeight1M !== null && usedWeight1M !== void 0 ? usedWeight1M : 'N/A'}`);
|
|
234
|
-
if (usedWeight1M) {
|
|
235
|
-
MetricBinanceApiUsedWeight.set(+usedWeight1M);
|
|
236
|
-
}
|
|
237
|
-
return res.json();
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
export const client = new ApiClient({
|
|
241
|
-
auth: process.env.PUBLIC_ONLY
|
|
242
|
-
? undefined
|
|
243
|
-
: {
|
|
244
|
-
public_key: process.env.ACCESS_KEY,
|
|
245
|
-
secret_key: process.env.SECRET_KEY,
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
//# sourceMappingURL=api.js.map
|