@yuants/vendor-binance 0.11.4 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/api/public-api.js.map +1 -1
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/public-data/quote.js +16 -2
  5. package/dist/public-data/quote.js.map +1 -1
  6. package/dist/services/accounts/unified.js +73 -54
  7. package/dist/services/accounts/unified.js.map +1 -1
  8. package/dist/services/exchange.js +4 -20
  9. package/dist/services/exchange.js.map +1 -1
  10. package/dist/services/interest-rate-service.js +76 -0
  11. package/dist/services/interest-rate-service.js.map +1 -0
  12. package/dist/services/ohlc-service.js +81 -0
  13. package/dist/services/ohlc-service.js.map +1 -0
  14. package/lib/api/public-api.d.ts +0 -5
  15. package/lib/api/public-api.d.ts.map +1 -1
  16. package/lib/api/public-api.js.map +1 -1
  17. package/lib/index.d.ts +2 -0
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +2 -0
  20. package/lib/index.js.map +1 -1
  21. package/lib/public-data/quote.js +15 -1
  22. package/lib/public-data/quote.js.map +1 -1
  23. package/lib/services/accounts/unified.d.ts +1 -1
  24. package/lib/services/accounts/unified.d.ts.map +1 -1
  25. package/lib/services/accounts/unified.js +74 -55
  26. package/lib/services/accounts/unified.js.map +1 -1
  27. package/lib/services/exchange.js +3 -19
  28. package/lib/services/exchange.js.map +1 -1
  29. package/lib/services/interest-rate-service.d.ts +2 -0
  30. package/lib/services/interest-rate-service.d.ts.map +1 -0
  31. package/lib/services/interest-rate-service.js +78 -0
  32. package/lib/services/interest-rate-service.js.map +1 -0
  33. package/lib/services/ohlc-service.d.ts +2 -0
  34. package/lib/services/ohlc-service.d.ts.map +1 -0
  35. package/lib/services/ohlc-service.js +83 -0
  36. package/lib/services/ohlc-service.js.map +1 -0
  37. package/package.json +15 -15
  38. package/temp/package-deps.json +24 -23
  39. package/dist/services/accounts/spot.js +0 -61
  40. package/dist/services/accounts/spot.js.map +0 -1
  41. package/lib/services/accounts/spot.d.ts +0 -4
  42. package/lib/services/accounts/spot.d.ts.map +0 -1
  43. package/lib/services/accounts/spot.js +0 -65
  44. package/lib/services/accounts/spot.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAA2C;AAE3C,oDAAsD;AACtD,gDAAqD;AACrD,0CAA6D;AAC7D,gDAA2D;AAC3D,sDAAmD;AACnD,oDAAgG;AAChG,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,SAAS;IACf,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;QACtC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC/B;KACF;IACD,eAAe,EAAf,yBAAe;IACf,YAAY,EAAZ,sBAAY;IACZ,YAAY,EAAE,KAAK,WAAW,UAAuB;QACnD,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC1D,IAAA,+BAAqB,EAAC,UAAU,CAAC;YACjC,IAAA,iCAA0B,EAAC,UAAU,CAAC;SACvC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,aAAa,CAAC,CAAC;IACjD,CAAC;IACD,SAAS,EAAE,KAAK,WAAW,UAAuB;QAChD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC/C,IAAA,gCAAmB,EAAC,UAAU,CAAC;YAC/B,IAAA,2BAAc,EAAC,UAAU,CAAC;SAC3B,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,UAAU,CAAC,CAAC;IACtC,CAAC;IACD,uBAAuB,EAAE,KAAK,WAC5B,UAAuB,EACvB,UAAkB;QAElB,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B;QAC5E,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,SAAS,GAAG,MAAM,IAAA,iCAA0B,EAAC,UAAU,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,IAAI,QAAQ,KAAK,aAAa,EAAE;YAC9B,MAAM,SAAS,GAAG,MAAM,IAAA,+BAAqB,EAAC,UAAU,CAAC,CAAC;YAC1D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,oBAAoB,EAApB,iCAAoB;IACpB,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential } from '../api/client';\nimport { listProducts } from '../public-data/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getSpotAccountInfoSnapshot } from './accounts/spot';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { getOrdersByProductId, listSpotOrders, listUnifiedUmOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'BINANCE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const [uFuturePositions, spotPositions] = await Promise.all([\n getUnifiedAccountInfo(credential),\n getSpotAccountInfoSnapshot(credential),\n ]);\n return [...uFuturePositions, ...spotPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders, spotOrders] = await Promise.all([\n listUnifiedUmOrders(credential),\n listSpotOrders(credential),\n ]);\n return [...umOrders, ...spotOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfoSnapshot(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n if (instType === 'USDT-FUTURE') {\n const positions = await getUnifiedAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder,\n cancelOrder,\n});\n"]}
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAE5C,oDAAsD;AACtD,gDAAqD;AACrD,gDAAkD;AAClD,sDAAmD;AACnD,oDAAgG;AAChG,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,SAAS;IACf,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;QACtC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC/B;KACF;IACD,eAAe,EAAf,yBAAe;IACf,YAAY,EAAZ,sBAAY;IACZ,YAAY,EAAE,sBAAY;IAC1B,SAAS,EAAE,KAAK,WAAW,UAAuB;QAChD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC/C,IAAA,gCAAmB,EAAC,UAAU,CAAC;YAC/B,IAAA,2BAAc,EAAC,UAAU,CAAC;SAC3B,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,UAAU,CAAC,CAAC;IACtC,CAAC;IACD,uBAAuB,EAAE,KAAK,WAC5B,UAAuB,EACvB,UAAkB;QAElB,MAAM,SAAS,GAAG,MAAM,IAAA,sBAAY,EAAC,UAAU,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC5E,CAAC;IACD,oBAAoB,EAApB,iCAAoB;IACpB,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;IACX,WAAW,EAAX,yBAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from '../api/client';\nimport { listProducts } from '../public-data/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getPositions } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { getOrdersByProductId, listSpotOrders, listUnifiedUmOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'BINANCE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: getPositions,\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders, spotOrders] = await Promise.all([\n listUnifiedUmOrders(credential),\n listSpotOrders(credential),\n ]);\n return [...umOrders, ...spotOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const positions = await getPositions(credential);\n return positions.filter((position) => position.product_id === product_id);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder,\n cancelOrder,\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interest-rate-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest-rate-service.d.ts","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const exchange_1 = require("@yuants/exchange");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const utils_1 = require("@yuants/utils");
6
+ const private_api_1 = require("../api/private-api");
7
+ const public_api_1 = require("../api/public-api");
8
+ const terminal = protocol_1.Terminal.fromNodeEnv();
9
+ const INGEST_SERVICE_OPTIONS = {
10
+ concurrent: 1,
11
+ max_pending_requests: 20,
12
+ ingress_token_capacity: 2,
13
+ ingress_token_refill_interval: 1000,
14
+ egress_token_capacity: 1,
15
+ egress_token_refill_interval: 1000,
16
+ };
17
+ const WINDOW_MS = 365 * 24 * 3600000;
18
+ const fetchUsdtFutureFundingRateForward = async (req) => {
19
+ const [, instType, symbol] = (0, utils_1.decodePath)(req.product_id);
20
+ if (instType !== 'USDT-FUTURE' || !symbol)
21
+ throw new Error(`Unsupported product_id: ${req.product_id}`);
22
+ const startTime = req.time;
23
+ const res = await (0, public_api_1.getFutureFundingRate)({
24
+ symbol,
25
+ startTime,
26
+ endTime: startTime + WINDOW_MS,
27
+ limit: 1000,
28
+ });
29
+ return (res !== null && res !== void 0 ? res : [])
30
+ .map((v) => {
31
+ const ms = Number(v.fundingTime);
32
+ const rate = Number(v.fundingRate);
33
+ return {
34
+ series_id: req.series_id,
35
+ product_id: req.product_id,
36
+ datasource_id: 'BINANCE',
37
+ created_at: (0, utils_1.formatTime)(ms),
38
+ long_rate: `${-rate}`,
39
+ short_rate: `${rate}`,
40
+ settlement_price: '',
41
+ };
42
+ })
43
+ .filter((x) => Date.parse(x.created_at) >= startTime);
44
+ };
45
+ const fetchMarginBorrowRateForward = async (req) => {
46
+ const [, instType, asset] = (0, utils_1.decodePath)(req.product_id);
47
+ if (instType !== 'MARGIN' || !asset)
48
+ throw new Error(`Unsupported product_id: ${req.product_id}`);
49
+ const startTime = req.time;
50
+ const res = await (0, private_api_1.getMarginInterestRateHistory)({
51
+ asset,
52
+ startTime,
53
+ endTime: startTime + WINDOW_MS,
54
+ limit: 100,
55
+ });
56
+ return (res !== null && res !== void 0 ? res : [])
57
+ .map((v) => {
58
+ return {
59
+ series_id: req.series_id,
60
+ product_id: req.product_id,
61
+ datasource_id: 'BINANCE',
62
+ created_at: (0, utils_1.formatTime)(v.timestamp),
63
+ long_rate: v.dailyInterestRate,
64
+ short_rate: '0',
65
+ settlement_price: '',
66
+ };
67
+ })
68
+ .filter((x) => Date.parse(x.created_at) >= startTime);
69
+ };
70
+ (0, exchange_1.provideInterestRateService)(terminal, {
71
+ product_id_prefix: 'BINANCE/USDT-FUTURE/',
72
+ direction: 'forward',
73
+ }, fetchUsdtFutureFundingRateForward, INGEST_SERVICE_OPTIONS);
74
+ (0, exchange_1.provideInterestRateService)(terminal, {
75
+ product_id_prefix: 'BINANCE/MARGIN/',
76
+ direction: 'forward',
77
+ }, fetchMarginBorrowRateForward, INGEST_SERVICE_OPTIONS);
78
+ //# sourceMappingURL=interest-rate-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":";;AACA,+CAA8D;AAC9D,+CAA6D;AAC7D,yCAAuD;AACvD,oDAAkE;AAClE,kDAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,sBAAsB,GAAoB;IAC9C,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,CAAC;IACzB,6BAA6B,EAAE,IAAI;IACnC,qBAAqB,EAAE,CAAC;IACxB,4BAA4B,EAAE,IAAI;CACnC,CAAC;AAEF,MAAM,SAAS,GAAG,GAAG,GAAG,EAAE,GAAG,OAAQ,CAAC;AAEtC,MAAM,iCAAiC,GAAG,KAAK,EAAE,GAIhD,EAA4B,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;IAExG,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC;IAC3B,MAAM,GAAG,GAAG,MAAM,IAAA,iCAAoB,EAAC;QACrC,MAAM;QACN,SAAS;QACT,OAAO,EAAE,SAAS,GAAG,SAAS;QAC9B,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,EAAE,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAiB,EA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GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,SAAS,CAAC;YACnC,SAAS,EAAE,CAAC,CAAC,iBAAiB;YAC9B,UAAU,EAAE,GAAG;YACf,gBAAgB,EAAE,EAAE;SACrB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,IAAA,qCAA0B,EACxB,QAAQ,EACR;IACE,iBAAiB,EAAE,sBAAsB;IACzC,SAAS,EAAE,SAAS;CACrB,EACD,iCAAiC,EACjC,sBAAsB,CACvB,CAAC;AAEF,IAAA,qCAA0B,EACxB,QAAQ,EACR;IACE,iBAAiB,EAAE,iBAAiB;IACpC,SAAS,EAAE,SAAS;CACrB,EACD,4BAA4B,EAC5B,sBAAsB,CACvB,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getMarginInterestRateHistory } from '../api/private-api';\nimport { getFutureFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\n\nconst WINDOW_MS = 365 * 24 * 3600_000;\n\nconst fetchUsdtFutureFundingRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (instType !== 'USDT-FUTURE' || !symbol) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getFutureFundingRate({\n symbol,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 1000,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n const ms = Number(v.fundingTime);\n const rate = Number(v.fundingRate);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nconst fetchMarginBorrowRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, asset] = decodePath(req.product_id);\n if (instType !== 'MARGIN' || !asset) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getMarginInterestRateHistory({\n asset,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 100,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(v.timestamp),\n long_rate: v.dailyInterestRate,\n short_rate: '0',\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n direction: 'forward',\n },\n fetchUsdtFutureFundingRateForward,\n INGEST_SERVICE_OPTIONS,\n);\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n direction: 'forward',\n },\n fetchMarginBorrowRateForward,\n INGEST_SERVICE_OPTIONS,\n);\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ohlc-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc-service.d.ts","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const exchange_1 = require("@yuants/exchange");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const utils_1 = require("@yuants/utils");
6
+ const client_1 = require("../api/client");
7
+ const terminal = protocol_1.Terminal.fromNodeEnv();
8
+ const INGEST_SERVICE_OPTIONS = {
9
+ concurrent: 1,
10
+ max_pending_requests: 20,
11
+ ingress_token_capacity: 2,
12
+ ingress_token_refill_interval: 1000,
13
+ egress_token_capacity: 1,
14
+ egress_token_refill_interval: 1000,
15
+ };
16
+ const DURATION_TO_BINANCE_INTERVAL = {
17
+ PT1M: '1m',
18
+ PT3M: '3m',
19
+ PT5M: '5m',
20
+ PT15M: '15m',
21
+ PT30M: '30m',
22
+ PT1H: '1h',
23
+ PT2H: '2h',
24
+ PT4H: '4h',
25
+ PT6H: '6h',
26
+ PT8H: '8h',
27
+ PT12H: '12h',
28
+ P1D: '1d',
29
+ P3D: '3d',
30
+ P1W: '1w',
31
+ P1M: '1M',
32
+ };
33
+ const fetchOHLCPageBackward = async (req) => {
34
+ const [, instType, symbol] = (0, utils_1.decodePath)(req.product_id);
35
+ if (!instType || !symbol)
36
+ throw new Error(`Invalid product_id: ${req.product_id}`);
37
+ const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];
38
+ if (!interval)
39
+ throw new Error(`Unsupported duration: ${req.duration}`);
40
+ const offset = (0, utils_1.convertDurationToOffset)(req.duration);
41
+ const endedAtMs = req.time;
42
+ const baseUrl = instType === 'USDT-FUTURE'
43
+ ? 'https://fapi.binance.com/fapi/v1/klines'
44
+ : 'https://api.binance.com/api/v3/klines';
45
+ const res = await (0, client_1.requestPublic)('GET', baseUrl, {
46
+ symbol,
47
+ interval,
48
+ endTime: endedAtMs,
49
+ limit: 1000,
50
+ });
51
+ return (res !== null && res !== void 0 ? res : [])
52
+ .map((k) => ({
53
+ series_id: req.series_id,
54
+ datasource_id: 'BINANCE',
55
+ product_id: req.product_id,
56
+ duration: req.duration,
57
+ created_at: (0, utils_1.formatTime)(k[0]),
58
+ closed_at: (0, utils_1.formatTime)(k[0] + offset),
59
+ open: `${k[1]}`,
60
+ high: `${k[2]}`,
61
+ low: `${k[3]}`,
62
+ close: `${k[4]}`,
63
+ volume: `${k[5]}`,
64
+ open_interest: '0',
65
+ }))
66
+ .filter((x) => Date.parse(x.created_at) < endedAtMs);
67
+ };
68
+ (0, exchange_1.provideOHLCService)(terminal, {
69
+ product_id_prefix: 'BINANCE/USDT-FUTURE/',
70
+ duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
71
+ direction: 'backward',
72
+ }, fetchOHLCPageBackward, INGEST_SERVICE_OPTIONS);
73
+ (0, exchange_1.provideOHLCService)(terminal, {
74
+ product_id_prefix: 'BINANCE/SPOT/',
75
+ duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
76
+ direction: 'backward',
77
+ }, fetchOHLCPageBackward, INGEST_SERVICE_OPTIONS);
78
+ (0, exchange_1.provideOHLCService)(terminal, {
79
+ product_id_prefix: 'BINANCE/MARGIN/',
80
+ duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
81
+ direction: 'backward',
82
+ }, fetchOHLCPageBackward, INGEST_SERVICE_OPTIONS);
83
+ //# sourceMappingURL=ohlc-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":";;AACA,+CAAsD;AACtD,+CAA6D;AAC7D,yCAAgF;AAChF,0CAA8C;AAE9C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,sBAAsB,GAAoB;IAC9C,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,CAAC;IACzB,6BAA6B,EAAE,IAAI;IACnC,qBAAqB,EAAE,CAAC;IACxB,4BAA4B,EAAE,IAAI;CACnC,CAAC;AAEF,MAAM,4BAA4B,GAA2B;IAC3D,IAAI,EAAE,IAAI;IACV,I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,iBAAiB;IACpC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,EACrB,sBAAsB,CACvB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { requestPublic } from '../api/client';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\n\nconst DURATION_TO_BINANCE_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT3M: '3m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT2H: '2h',\n PT4H: '4h',\n PT6H: '6h',\n PT8H: '8h',\n PT12H: '12h',\n P1D: '1d',\n P3D: '3d',\n P1W: '1w',\n P1M: '1M',\n};\n\ntype IBinanceKline = [\n number, // Open time\n string, // Open\n string, // High\n string, // Low\n string, // Close\n string, // Volume\n number, // Close time\n string, // Quote asset volume\n number, // Number of trades\n string, // Taker buy base asset volume\n string, // Taker buy quote asset volume\n string, // Ignore\n];\n\nconst fetchOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (!instType || !symbol) throw new Error(`Invalid product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const baseUrl =\n instType === 'USDT-FUTURE'\n ? 'https://fapi.binance.com/fapi/v1/klines'\n : 'https://api.binance.com/api/v3/klines';\n\n const res = await requestPublic<IBinanceKline[]>('GET', baseUrl, {\n symbol,\n interval,\n endTime: endedAtMs,\n limit: 1000,\n });\n\n return (res ?? [])\n .map(\n (k): IOHLC => ({\n series_id: req.series_id,\n datasource_id: 'BINANCE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k[0]),\n closed_at: formatTime(k[0] + offset),\n open: `${k[1]}`,\n high: `${k[2]}`,\n low: `${k[3]}`,\n close: `${k[4]}`,\n volume: `${k[5]}`,\n open_interest: '0',\n }),\n )\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/SPOT/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-binance",
3
- "version": "0.11.4",
3
+ "version": "0.12.1",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -8,19 +8,19 @@
8
8
  "temp"
9
9
  ],
10
10
  "dependencies": {
11
- "@yuants/protocol": "0.53.3",
12
- "@yuants/data-account": "0.11.0",
13
- "@yuants/cache": "0.3.4",
14
- "@yuants/data-quote": "0.4.0",
15
- "@yuants/utils": "0.15.0",
16
- "@yuants/data-series": "0.3.53",
17
- "@yuants/sql": "0.9.31",
18
- "@yuants/data-product": "0.5.1",
19
- "@yuants/data-ohlc": "0.4.23",
20
- "@yuants/data-order": "0.7.1",
21
- "@yuants/data-interest-rate": "0.1.49",
22
- "@yuants/transfer": "0.2.40",
23
- "@yuants/exchange": "0.8.0",
11
+ "@yuants/protocol": "0.53.4",
12
+ "@yuants/data-account": "0.11.1",
13
+ "@yuants/cache": "0.3.5",
14
+ "@yuants/data-quote": "0.4.1",
15
+ "@yuants/utils": "0.16.0",
16
+ "@yuants/data-series": "0.3.54",
17
+ "@yuants/sql": "0.9.32",
18
+ "@yuants/data-product": "0.5.2",
19
+ "@yuants/data-ohlc": "0.5.0",
20
+ "@yuants/data-order": "0.7.2",
21
+ "@yuants/data-interest-rate": "0.2.0",
22
+ "@yuants/transfer": "0.2.41",
23
+ "@yuants/exchange": "0.8.2",
24
24
  "rxjs": "~7.5.6"
25
25
  },
26
26
  "devDependencies": {
@@ -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.32",
33
+ "@yuants/extension": "0.2.33",
34
34
  "@yuants/tool-kit": "0.2.1",
35
35
  "typescript": "~4.7.4",
36
36
  "ts-node": "~10.9.2"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "apps/vendor-binance/AGENTS.md": "378369925bffa237cd5e8ef459fe2bc2a141337c",
3
- "apps/vendor-binance/CHANGELOG.json": "390e36916be2e24d321d29eeda164b6a2dda15c5",
4
- "apps/vendor-binance/CHANGELOG.md": "461aa990529c3e2fb1c28272f5c28d446251809c",
3
+ "apps/vendor-binance/CHANGELOG.json": "4edeebc3c7f17502729a21554f5e208a63bd987a",
4
+ "apps/vendor-binance/CHANGELOG.md": "624967c564b9ba92f724f9af99d4287b67bf9463",
5
5
  "apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
6
6
  "apps/vendor-binance/SESSION_NOTES.md": "dd49b3364394c502fdcaf687ed5942811d89abe9",
7
7
  "apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
@@ -9,20 +9,21 @@
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": "5a15ddb508ecceb0153685fb5b8464bf454f4e93",
12
+ "apps/vendor-binance/package.json": "1a47aa1461e10951709995db398e7194ea8e54f7",
13
13
  "apps/vendor-binance/src/api/client.ts": "fab85d85d10577f0b6430a551dab46d7c1d2258a",
14
14
  "apps/vendor-binance/src/api/private-api.ts": "982c1902b8417aba1f75df5fa63db76dfc416dac",
15
- "apps/vendor-binance/src/api/public-api.ts": "70dc33214e05ec3ead45271bfae70abdb0623c1e",
16
- "apps/vendor-binance/src/index.ts": "23922476534fcc827c7501e5baa5bd8558f37a66",
15
+ "apps/vendor-binance/src/api/public-api.ts": "3cf90196c9632f2d25ae41a2b6cc9145808af5b3",
16
+ "apps/vendor-binance/src/index.ts": "8a1559cfd02fccf4d9c6686669bf177d86b62106",
17
17
  "apps/vendor-binance/src/legacy_index.ts": "a2b44c041aa7ef1f4b77249e11f84d97cde5525f",
18
18
  "apps/vendor-binance/src/public-data/interest_rate.ts": "a197c30a2cf8acbb389fed8c0687a091320d8113",
19
19
  "apps/vendor-binance/src/public-data/ohlc.ts": "bb4f791f96064eca7d45d361ea36cb8ba0ab8fe0",
20
20
  "apps/vendor-binance/src/public-data/product.ts": "8879f59f4b5ee5925c5becef5fce5492e2f30f42",
21
- "apps/vendor-binance/src/public-data/quote.ts": "392ca103f00f6462528a24d5ba3c00a86554abcc",
21
+ "apps/vendor-binance/src/public-data/quote.ts": "a15d2df38a391bd360cb6a1ac16706de04fd529b",
22
22
  "apps/vendor-binance/src/services/accounts/profile.ts": "1d23b04d19c078e8c21f41efd6ca3db37b0bd206",
23
- "apps/vendor-binance/src/services/accounts/spot.ts": "7561d3054c967b48711a4dcedf96946eeab9fab4",
24
- "apps/vendor-binance/src/services/accounts/unified.ts": "46c772fdad40056462b0b28848d46944954518c8",
25
- "apps/vendor-binance/src/services/exchange.ts": "c989e025b771f5d5c49efcc779ca388dfb1d488d",
23
+ "apps/vendor-binance/src/services/accounts/unified.ts": "26cd40a714936c8ba0e5305ce362f353c2b91435",
24
+ "apps/vendor-binance/src/services/exchange.ts": "0e81f5219d534e0ab560b11c346df28bd3b8ce54",
25
+ "apps/vendor-binance/src/services/interest-rate-service.ts": "a02934aa648db94255e5ae59627fcb2465e52ab9",
26
+ "apps/vendor-binance/src/services/ohlc-service.ts": "7ee3416063d578c7039f84fce62a758bcdd445ad",
26
27
  "apps/vendor-binance/src/services/orders/cancelOrder.ts": "7177ca56fd09b11651edbb38e1962363ac67d4ff",
27
28
  "apps/vendor-binance/src/services/orders/listOrders.ts": "baa21b8e858c1ec593415145cc63fb38a6841d3f",
28
29
  "apps/vendor-binance/src/services/orders/modifyOrder.ts": "0d1ec4d683e43876e9d53ee29cdc5324301b287e",
@@ -31,19 +32,19 @@
31
32
  "apps/vendor-binance/src/services/quotes.ts": "5af233c8c8fb136111754055e79febaa551b993f",
32
33
  "apps/vendor-binance/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
33
34
  "apps/vendor-binance/.rush/temp/shrinkwrap-deps.json": "0408a4d9b00c1701e07aa22f8350e585241c4581",
34
- "libraries/protocol/temp/package-deps.json": "c94931cb0eab7180d90a06d740c1a97c0ac0c6b6",
35
- "libraries/data-account/temp/package-deps.json": "d49586cd2fc2d6d025e585e5a5dd04d37c41263c",
36
- "libraries/cache/temp/package-deps.json": "e1f94620bc6245add32a4f9d379ed2901129d818",
37
- "libraries/data-quote/temp/package-deps.json": "c2f009f818a503342bef588da21c9abd52beea00",
38
- "libraries/utils/temp/package-deps.json": "7f1eab07acae68df931b001594a522f050ace396",
39
- "libraries/data-series/temp/package-deps.json": "a94e2f373c448a6205ee6c47e41d9283a76ee352",
40
- "libraries/sql/temp/package-deps.json": "041074e0102f9a01820c0fddcf82b9eaee226c79",
41
- "libraries/data-product/temp/package-deps.json": "899bba8ace3f04b2035488ff9059e40732ef1d97",
42
- "libraries/data-ohlc/temp/package-deps.json": "8415ee90c49d7e84faaa2565cc1122fdacf73dab",
43
- "libraries/data-order/temp/package-deps.json": "8aa3e27ff80629d417bfe920e85d8525fbb52f42",
44
- "libraries/data-interest-rate/temp/package-deps.json": "5a1011b097b18b96c2d8c932d874f69472621efd",
45
- "libraries/transfer/temp/package-deps.json": "7b0db8291734d10d4f1d9c2c25d9e3918cabc79e",
46
- "libraries/exchange/temp/package-deps.json": "98f6e1318166102a07cf64b69399b35cb4575222",
47
- "libraries/extension/temp/package-deps.json": "3e0a81b0c863c2daf342dfaf284b8fd7d18c8562",
35
+ "libraries/protocol/temp/package-deps.json": "a30b39ceb4cd530ed6bc4e97433f995b026b26d9",
36
+ "libraries/data-account/temp/package-deps.json": "363f171a8ec4ae558e4b20626b06bc8ae145ce8a",
37
+ "libraries/cache/temp/package-deps.json": "2e6c6db8f750a2e173a3c4b9a57d22fbd6f9181d",
38
+ "libraries/data-quote/temp/package-deps.json": "07e342d9dba4d5f5d89b62c74f079425b560cb1f",
39
+ "libraries/utils/temp/package-deps.json": "7a9e2336d7ad44e827d81e9722767d6cdf99fc1f",
40
+ "libraries/data-series/temp/package-deps.json": "71b373ec83ce1188001e341aefaca704aa4a5c38",
41
+ "libraries/sql/temp/package-deps.json": "252d819797cb0a4bbc579075867624b05b19dabb",
42
+ "libraries/data-product/temp/package-deps.json": "4f525fda6d65677f9fbdcd1b4480970dd6ff9e5b",
43
+ "libraries/data-ohlc/temp/package-deps.json": "2115e384567d1b0958c085f455da9bed5a638780",
44
+ "libraries/data-order/temp/package-deps.json": "daedd350fe85f0564f7739c73689fb09664132de",
45
+ "libraries/data-interest-rate/temp/package-deps.json": "0aa2057c1c5c432be87e97b8df22984bdcab307c",
46
+ "libraries/transfer/temp/package-deps.json": "6d0942aa4c50b35a8e47a500fe494fb4a08a99e5",
47
+ "libraries/exchange/temp/package-deps.json": "5267eb70cd2e7df4a645f94133ad3428b52c567e",
48
+ "libraries/extension/temp/package-deps.json": "fcddc4a668ecf969ca593c67ff02543fe69a6829",
48
49
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
49
50
  }
@@ -1,61 +0,0 @@
1
- import { makeSpotPosition } from '@yuants/data-account';
2
- import { encodePath } from '@yuants/utils';
3
- import { isApiError } from '../../api/client';
4
- import { getFundingAsset, getSpotAccountInfo } from '../../api/private-api';
5
- import { getSpotTickerPrice } from '../../api/public-api';
6
- export const getSpotAccountInfoSnapshot = async (credential) => {
7
- const [res, fundingAsset] = await Promise.all([
8
- getSpotAccountInfo(credential, { omitZeroBalances: true }),
9
- getFundingAsset(credential, {
10
- timestamp: Date.now(),
11
- }),
12
- ]);
13
- if (isApiError(res)) {
14
- throw new Error(res.msg);
15
- }
16
- if (isApiError(fundingAsset)) {
17
- throw new Error(fundingAsset.msg);
18
- }
19
- const prices = await getSpotTickerPrice({
20
- symbols: JSON.stringify([
21
- ...new Set([
22
- ...res.balances
23
- .map((balance) => {
24
- const match = balance.asset.match(/^LD(\w+)$/);
25
- let symbol = balance.asset;
26
- if (match) {
27
- symbol = match[1];
28
- }
29
- if (symbol === 'USDT')
30
- return '';
31
- return `${symbol}USDT`;
32
- })
33
- .filter(Boolean),
34
- ...fundingAsset.map((item) => `${item.asset}USDT`),
35
- ]),
36
- ]),
37
- });
38
- const positions = [...res.balances, ...fundingAsset]
39
- .map((balance) => {
40
- var _a, _b;
41
- const volume = +balance.free + +balance.locked;
42
- if (!volume)
43
- return undefined;
44
- const position = makeSpotPosition({
45
- position_id: `spot/${balance.asset}`,
46
- datasource_id: 'BINANCE',
47
- product_id: encodePath('BINANCE', 'SPOT', `${balance.asset}`),
48
- volume,
49
- free_volume: +balance.free,
50
- closable_price: balance.asset === 'USDT'
51
- ? 1
52
- : Array.isArray(prices)
53
- ? +((_b = (_a = prices.find((item) => item.symbol === `${balance.asset}USDT`)) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0)
54
- : 0,
55
- });
56
- return position;
57
- })
58
- .filter((position) => Boolean(position));
59
- return positions;
60
- };
61
- //# sourceMappingURL=spot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAChG,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC5C,kBAAkB,CAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,eAAe,CAAC,UAAU,EAAE;YAC1B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED,MAAM,MAAM,GAAG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tB,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBACvB,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,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","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"]}
@@ -1,4 +0,0 @@
1
- import { IPosition } from '@yuants/data-account';
2
- import { ICredential } from '../../api/private-api';
3
- export declare const getSpotAccountInfoSnapshot: (credential: ICredential) => Promise<IPosition[]>;
4
- //# sourceMappingURL=spot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAuC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzF,eAAO,MAAM,0BAA0B,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAuD7F,CAAC"}
@@ -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,CA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MAAM,CAAC;QAC/C,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAC9B,MAAM,QAAQ,GAAc,IAAA,+BAAgB,EAAC;YAC3C,WAAW,EAAE,QAAQ,OAAO,CAAC,KAAK,EAAE;YACpC,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7D,MAAM;YACN,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI;YAC1B,cAAc,EACZ,OAAO,CAAC,KAAK,KAAK,MAAM;gBACtB,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBACvB,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,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"]}