@yuants/vendor-binance 0.12.0 → 0.12.2
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/public-api.js.map +1 -1
- package/dist/public-data/quote.js +16 -2
- package/dist/public-data/quote.js.map +1 -1
- package/dist/services/accounts/unified.js +73 -54
- package/dist/services/accounts/unified.js.map +1 -1
- package/dist/services/exchange.js +4 -20
- package/dist/services/exchange.js.map +1 -1
- package/lib/api/public-api.d.ts +0 -5
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js.map +1 -1
- package/lib/public-data/quote.js +15 -1
- package/lib/public-data/quote.js.map +1 -1
- package/lib/services/accounts/unified.d.ts +1 -1
- package/lib/services/accounts/unified.d.ts.map +1 -1
- package/lib/services/accounts/unified.js +74 -55
- package/lib/services/accounts/unified.js.map +1 -1
- package/lib/services/exchange.js +3 -19
- package/lib/services/exchange.js.map +1 -1
- package/package.json +15 -15
- package/temp/package-deps.json +21 -22
- package/dist/services/accounts/spot.js +0 -61
- package/dist/services/accounts/spot.js.map +0 -1
- package/lib/services/accounts/spot.d.ts +0 -4
- package/lib/services/accounts/spot.d.ts.map +0 -1
- package/lib/services/accounts/spot.js +0 -65
- package/lib/services/accounts/spot.js.map +0 -1
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpotAccountInfoSnapshot = void 0;
|
|
4
|
-
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const utils_1 = require("@yuants/utils");
|
|
6
|
-
const client_1 = require("../../api/client");
|
|
7
|
-
const private_api_1 = require("../../api/private-api");
|
|
8
|
-
const public_api_1 = require("../../api/public-api");
|
|
9
|
-
const getSpotAccountInfoSnapshot = async (credential) => {
|
|
10
|
-
const [res, fundingAsset] = await Promise.all([
|
|
11
|
-
(0, private_api_1.getSpotAccountInfo)(credential, { omitZeroBalances: true }),
|
|
12
|
-
(0, private_api_1.getFundingAsset)(credential, {
|
|
13
|
-
timestamp: Date.now(),
|
|
14
|
-
}),
|
|
15
|
-
]);
|
|
16
|
-
if ((0, client_1.isApiError)(res)) {
|
|
17
|
-
throw new Error(res.msg);
|
|
18
|
-
}
|
|
19
|
-
if ((0, client_1.isApiError)(fundingAsset)) {
|
|
20
|
-
throw new Error(fundingAsset.msg);
|
|
21
|
-
}
|
|
22
|
-
const prices = await (0, public_api_1.getSpotTickerPrice)({
|
|
23
|
-
symbols: JSON.stringify([
|
|
24
|
-
...new Set([
|
|
25
|
-
...res.balances
|
|
26
|
-
.map((balance) => {
|
|
27
|
-
const match = balance.asset.match(/^LD(\w+)$/);
|
|
28
|
-
let symbol = balance.asset;
|
|
29
|
-
if (match) {
|
|
30
|
-
symbol = match[1];
|
|
31
|
-
}
|
|
32
|
-
if (symbol === 'USDT')
|
|
33
|
-
return '';
|
|
34
|
-
return `${symbol}USDT`;
|
|
35
|
-
})
|
|
36
|
-
.filter(Boolean),
|
|
37
|
-
...fundingAsset.map((item) => `${item.asset}USDT`),
|
|
38
|
-
]),
|
|
39
|
-
]),
|
|
40
|
-
});
|
|
41
|
-
const positions = [...res.balances, ...fundingAsset]
|
|
42
|
-
.map((balance) => {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
const volume = +balance.free + +balance.locked;
|
|
45
|
-
if (!volume)
|
|
46
|
-
return undefined;
|
|
47
|
-
const position = (0, data_account_1.makeSpotPosition)({
|
|
48
|
-
position_id: `spot/${balance.asset}`,
|
|
49
|
-
datasource_id: 'BINANCE',
|
|
50
|
-
product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', `${balance.asset}`),
|
|
51
|
-
volume,
|
|
52
|
-
free_volume: +balance.free,
|
|
53
|
-
closable_price: balance.asset === 'USDT'
|
|
54
|
-
? 1
|
|
55
|
-
: Array.isArray(prices)
|
|
56
|
-
? +((_b = (_a = prices.find((item) => item.symbol === `${balance.asset}USDT`)) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0)
|
|
57
|
-
: 0,
|
|
58
|
-
});
|
|
59
|
-
return position;
|
|
60
|
-
})
|
|
61
|
-
.filter((position) => Boolean(position));
|
|
62
|
-
return positions;
|
|
63
|
-
};
|
|
64
|
-
exports.getSpotAccountInfoSnapshot = getSpotAccountInfoSnapshot;
|
|
65
|
-
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAyF;AACzF,qDAA0D;AAEnD,MAAM,0BAA0B,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAChG,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC5C,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,IAAA,6BAAe,EAAC,UAAU,EAAE;YAC1B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAkB,EAAC;QACtC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;YACtB,GAAG,IAAI,GAAG,CAAC;gBACT,GAAG,GAAG,CAAC,QAAQ;qBACZ,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;oBACf,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK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,GAAG,OAAO,CAAC,KAAK,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;oBAC9E,CAAC,CAAC,CAAC;SACR,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,QAAQ,EAAyB,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvDW,QAAA,0BAA0B,8BAuDrC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getFundingAsset, getSpotAccountInfo, ICredential } from '../../api/private-api';\nimport { getSpotTickerPrice } from '../../api/public-api';\n\nexport const getSpotAccountInfoSnapshot = async (credential: ICredential): Promise<IPosition[]> => {\n const [res, fundingAsset] = await Promise.all([\n getSpotAccountInfo(credential, { omitZeroBalances: true }),\n getFundingAsset(credential, {\n timestamp: Date.now(),\n }),\n ]);\n\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n if (isApiError(fundingAsset)) {\n throw new Error(fundingAsset.msg);\n }\n\n const prices = await getSpotTickerPrice({\n symbols: JSON.stringify([\n ...new Set([\n ...res.balances\n .map((balance) => {\n const match = balance.asset.match(/^LD(\\w+)$/);\n let symbol = balance.asset;\n if (match) {\n symbol = match[1];\n }\n if (symbol === 'USDT') return '';\n return `${symbol}USDT`;\n })\n .filter(Boolean),\n ...fundingAsset.map((item) => `${item.asset}USDT`),\n ]),\n ]),\n });\n\n const positions = [...res.balances, ...fundingAsset]\n .map((balance) => {\n const volume = +balance.free + +balance.locked;\n if (!volume) return undefined;\n const position: IPosition = makeSpotPosition({\n position_id: `spot/${balance.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', `${balance.asset}`),\n volume,\n free_volume: +balance.free,\n closable_price:\n balance.asset === 'USDT'\n ? 1\n : Array.isArray(prices)\n ? +(prices.find((item) => item.symbol === `${balance.asset}USDT`)?.price ?? 0)\n : 0,\n });\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n};\n"]}
|