@yuants/vendor-binance 0.9.0 → 0.10.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 (74) hide show
  1. package/dist/api/client.js +14 -3
  2. package/dist/api/client.js.map +1 -1
  3. package/dist/api/public-api.js +6 -0
  4. package/dist/api/public-api.js.map +1 -1
  5. package/dist/index.js +1 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/legacy_index.js +163 -197
  8. package/dist/legacy_index.js.map +1 -1
  9. package/dist/public-data/product.js +82 -3
  10. package/dist/public-data/product.js.map +1 -1
  11. package/dist/public-data/quote.js +2 -2
  12. package/dist/public-data/quote.js.map +1 -1
  13. package/dist/services/accounts/profile.js +4 -15
  14. package/dist/services/accounts/profile.js.map +1 -1
  15. package/dist/services/accounts/spot.js.map +1 -1
  16. package/dist/services/accounts/unified.js +1 -11
  17. package/dist/services/accounts/unified.js.map +1 -1
  18. package/dist/services/exchange.js +56 -0
  19. package/dist/services/exchange.js.map +1 -0
  20. package/dist/services/orders/listOrders.js +44 -35
  21. package/dist/services/orders/listOrders.js.map +1 -1
  22. package/lib/api/client.d.ts.map +1 -1
  23. package/lib/api/client.js +13 -2
  24. package/lib/api/client.js.map +1 -1
  25. package/lib/api/public-api.d.ts +41 -0
  26. package/lib/api/public-api.d.ts.map +1 -1
  27. package/lib/api/public-api.js +8 -1
  28. package/lib/api/public-api.js.map +1 -1
  29. package/lib/index.d.ts +1 -2
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +1 -2
  32. package/lib/index.js.map +1 -1
  33. package/lib/legacy_index.d.ts +0 -1
  34. package/lib/legacy_index.js +162 -198
  35. package/lib/legacy_index.js.map +1 -1
  36. package/lib/public-data/product.d.ts +2 -1
  37. package/lib/public-data/product.d.ts.map +1 -1
  38. package/lib/public-data/product.js +83 -2
  39. package/lib/public-data/product.js.map +1 -1
  40. package/lib/public-data/quote.js +2 -2
  41. package/lib/public-data/quote.js.map +1 -1
  42. package/lib/services/accounts/profile.d.ts +1 -5
  43. package/lib/services/accounts/profile.d.ts.map +1 -1
  44. package/lib/services/accounts/profile.js +6 -17
  45. package/lib/services/accounts/profile.js.map +1 -1
  46. package/lib/services/accounts/spot.d.ts +2 -2
  47. package/lib/services/accounts/spot.d.ts.map +1 -1
  48. package/lib/services/accounts/spot.js.map +1 -1
  49. package/lib/services/accounts/unified.d.ts +2 -2
  50. package/lib/services/accounts/unified.d.ts.map +1 -1
  51. package/lib/services/accounts/unified.js +1 -11
  52. package/lib/services/accounts/unified.js.map +1 -1
  53. package/lib/services/exchange.d.ts +2 -0
  54. package/lib/services/exchange.d.ts.map +1 -0
  55. package/lib/services/exchange.js +58 -0
  56. package/lib/services/exchange.js.map +1 -0
  57. package/lib/services/orders/listOrders.d.ts +4 -2
  58. package/lib/services/orders/listOrders.d.ts.map +1 -1
  59. package/lib/services/orders/listOrders.js +47 -36
  60. package/lib/services/orders/listOrders.js.map +1 -1
  61. package/package.json +16 -16
  62. package/temp/package-deps.json +30 -30
  63. package/dist/services/account-actions-with-credential.js +0 -34
  64. package/dist/services/account-actions-with-credential.js.map +0 -1
  65. package/dist/services/order-actions-with-credential.js +0 -21
  66. package/dist/services/order-actions-with-credential.js.map +0 -1
  67. package/lib/services/account-actions-with-credential.d.ts +0 -2
  68. package/lib/services/account-actions-with-credential.d.ts.map +0 -1
  69. package/lib/services/account-actions-with-credential.js +0 -36
  70. package/lib/services/account-actions-with-credential.js.map +0 -1
  71. package/lib/services/order-actions-with-credential.d.ts +0 -2
  72. package/lib/services/order-actions-with-credential.d.ts.map +0 -1
  73. package/lib/services/order-actions-with-credential.js +0 -23
  74. package/lib/services/order-actions-with-credential.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listProducts = void 0;
3
4
  const data_product_1 = require("@yuants/data-product");
4
5
  const protocol_1 = require("@yuants/protocol");
5
6
  const utils_1 = require("@yuants/utils");
6
7
  const public_api_1 = require("../api/public-api");
7
8
  const terminal = protocol_1.Terminal.fromNodeEnv();
8
- // Provide QueryProducts service with the new design
9
- const cache = (0, data_product_1.provideQueryProductsService)(terminal, 'BINANCE', async (req) => {
9
+ const listProducts = async () => {
10
10
  // Directly call the external API to get exchange info
11
11
  const exchangeInfo = await (0, public_api_1.getFutureExchangeInfo)();
12
12
  // Convert symbols to IProduct format
@@ -32,6 +32,87 @@ const cache = (0, data_product_1.provideQueryProductsService)(terminal, 'BINANCE
32
32
  no_interest_rate: false,
33
33
  };
34
34
  });
35
+ };
36
+ exports.listProducts = listProducts;
37
+ // Provide QueryProducts service with the new design
38
+ const cache = (0, data_product_1.provideQueryProductsService)(terminal, 'BINANCE', async (req) => {
39
+ // Directly call the external API to get exchange info
40
+ const [futureExchangeInfo, spotExchangeInfo] = await Promise.all([
41
+ (0, public_api_1.getFutureExchangeInfo)(),
42
+ (0, public_api_1.getSpotExchangeInfo)(),
43
+ ]);
44
+ const products = [];
45
+ // Convert future symbols to IProduct format
46
+ for (const symbol of futureExchangeInfo.symbols) {
47
+ products.push({
48
+ datasource_id: 'BINANCE',
49
+ product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', symbol.symbol),
50
+ base_currency: symbol.baseAsset,
51
+ quote_currency: symbol.quoteAsset,
52
+ price_step: +`1e-${symbol.pricePrecision}`,
53
+ value_scale: 1,
54
+ volume_step: +`1e-${symbol.quantityPrecision}`,
55
+ name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,
56
+ value_scale_unit: '',
57
+ margin_rate: +symbol.requiredMarginPercent / 100,
58
+ value_based_cost: 0,
59
+ volume_based_cost: 0,
60
+ max_position: 0,
61
+ max_volume: 0,
62
+ allow_long: true,
63
+ allow_short: true,
64
+ market_id: 'BINANCE/USDT-FUTURE',
65
+ no_interest_rate: false,
66
+ });
67
+ }
68
+ // Convert spot symbols to IProduct format
69
+ for (const symbol of spotExchangeInfo.symbols) {
70
+ if (symbol.isSpotTradingAllowed) {
71
+ products.push({
72
+ datasource_id: 'BINANCE',
73
+ product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', symbol.symbol),
74
+ base_currency: symbol.baseAsset,
75
+ quote_currency: symbol.quoteAsset,
76
+ price_step: +`1e-${symbol.quotePrecision}`,
77
+ value_scale: 1,
78
+ volume_step: +`1e-${symbol.baseAssetPrecision}`,
79
+ name: `${symbol.baseAsset}/${symbol.quoteAsset} SPOT`,
80
+ value_scale_unit: '',
81
+ margin_rate: 1,
82
+ value_based_cost: 0,
83
+ volume_based_cost: 0,
84
+ max_position: 0,
85
+ max_volume: 0,
86
+ allow_long: true,
87
+ allow_short: false,
88
+ market_id: 'BINANCE/SPOT',
89
+ no_interest_rate: true,
90
+ });
91
+ }
92
+ if (symbol.isMarginTradingAllowed) {
93
+ products.push({
94
+ datasource_id: 'BINANCE',
95
+ product_id: (0, utils_1.encodePath)('BINANCE', 'MARGIN', symbol.symbol),
96
+ base_currency: symbol.baseAsset,
97
+ quote_currency: symbol.quoteAsset,
98
+ price_step: +`1e-${symbol.quotePrecision}`,
99
+ value_scale: 1,
100
+ volume_step: +`1e-${symbol.baseAssetPrecision}`,
101
+ name: `${symbol.baseAsset}/${symbol.quoteAsset} MARGIN`,
102
+ value_scale_unit: '',
103
+ margin_rate: 1,
104
+ value_based_cost: 0,
105
+ volume_based_cost: 0,
106
+ max_position: 0,
107
+ max_volume: 0,
108
+ allow_long: true,
109
+ allow_short: true,
110
+ market_id: 'BINANCE/MARGIN',
111
+ no_interest_rate: false,
112
+ });
113
+ }
114
+ }
115
+ return products;
35
116
  }, {
36
117
  auto_refresh_interval: 3600000,
37
118
  });
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/public-data/product.ts"],"names":[],"mappings":";;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,kDAA0D;AAE1D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,oDAAoD;AACpD,MAAM,KAAK,GAAG,IAAA,0CAA2B,EACvC,QAAQ,EACR,SAAS,EACT,KAAK,EAAE,GAA0B,EAAuB,EAAE;IACxD,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAAM,IAAA,kCAAqB,GAAE,CAAC;IAEnD,qCAAqC;IACrC,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAY,EAAE;QACnD,OAAO;YACL,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC;YAC/D,aAAa,EAAE,MAAM,CAAC,SAAS;YAC/B,cAAc,EAAE,MAAM,CAAC,UAAU;YACjC,UAAU,EAAE,CAAC,MAAM,MAAM,CAAC,cAAc,EAAE;YAC1C,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,CAAC,MAAM,MAAM,CAAC,iBAAiB,EAAE;YAC9C,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,OAAO;YACrD,gBAAgB,EAAE,EAAE;YACpB,WAAW,EAAE,CAAC,MAAM,CAAC,qBAAqB,GAAG,GAAG;YAChD,gBAAgB,EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;YACpB,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,qBAAqB;YAChC,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,EACD;IACE,qBAAqB,EAAE,OAAQ;CAChC,CACF,CAAC","sourcesContent":["import { IProduct, IQueryProductsRequest, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFutureExchangeInfo } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// Provide QueryProducts service with the new design\nconst cache = provideQueryProductsService(\n terminal,\n 'BINANCE',\n async (req: IQueryProductsRequest): Promise<IProduct[]> => {\n // Directly call the external API to get exchange info\n const exchangeInfo = await getFutureExchangeInfo();\n\n // Convert symbols to IProduct format\n return exchangeInfo.symbols.map((symbol): IProduct => {\n return {\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', symbol.symbol),\n base_currency: symbol.baseAsset,\n quote_currency: symbol.quoteAsset,\n price_step: +`1e-${symbol.pricePrecision}`,\n value_scale: 1,\n volume_step: +`1e-${symbol.quantityPrecision}`,\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n value_scale_unit: '',\n margin_rate: +symbol.requiredMarginPercent / 100,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'BINANCE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n },\n {\n auto_refresh_interval: 3600_000,\n },\n);\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/public-data/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,kDAA+E;AAE/E,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAEjC,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAAM,IAAA,kCAAqB,GAAE,CAAC;IAEnD,qCAAqC;IACrC,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAY,EAAE;QACnD,OAAO;YACL,aAAa,EAAE,SAAS;YACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC;YAC/D,aAAa,EAAE,MAAM,CAAC,SAAS;YAC/B,cAAc,EAAE,MAAM,CAAC,UAAU;YACjC,UAAU,EAA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,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;SACJ;QAED,IAAI,MAAM,CAAC,sBAAsB,EAAE;YACjC,QAAQ,CAAC,IAAI,CAAC;gBACZ,aAAa,EAAE,SAAS;gBACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;gBAC1D,aAAa,EAAE,MAAM,CAAC,SAAS;gBAC/B,cAAc,EAAE,MAAM,CAAC,UAAU;gBACjC,UAAU,EAAE,CAAC,MAAM,MAAM,CAAC,cAAc,EAAE;gBAC1C,WAAW,EAAE,CAAC;gBACd,WAAW,EAAE,CAAC,MAAM,MAAM,CAAC,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,SAAS;gBACvD,gBAAgB,EAAE,EAAE;gBACpB,WAAW,EAAE,CAAC;gBACd,gBAAgB,EAAE,CAAC;gBACnB,iBAAiB,EAAE,CAAC;gBACpB,YAAY,EAAE,CAAC;gBACf,UAAU,EAAE,CAAC;gBACb,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,IAAI;gBACjB,SAAS,EAAE,gBAAgB;gBAC3B,gBAAgB,EAAE,KAAK;aACxB,CAAC,CAAC;SACJ;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,EACD;IACE,qBAAqB,EAAE,OAAQ;CAChC,CACF,CAAC","sourcesContent":["import { IProduct, IQueryProductsRequest, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFutureExchangeInfo, getSpotExchangeInfo } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nexport const listProducts = async () => {\n // Directly call the external API to get exchange info\n const exchangeInfo = await getFutureExchangeInfo();\n\n // Convert symbols to IProduct format\n return exchangeInfo.symbols.map((symbol): IProduct => {\n return {\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', symbol.symbol),\n base_currency: symbol.baseAsset,\n quote_currency: symbol.quoteAsset,\n price_step: +`1e-${symbol.pricePrecision}`,\n value_scale: 1,\n volume_step: +`1e-${symbol.quantityPrecision}`,\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n value_scale_unit: '',\n margin_rate: +symbol.requiredMarginPercent / 100,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'BINANCE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n};\n\n// Provide QueryProducts service with the new design\nconst cache = provideQueryProductsService(\n terminal,\n 'BINANCE',\n async (req: IQueryProductsRequest): Promise<IProduct[]> => {\n // Directly call the external API to get exchange info\n const [futureExchangeInfo, spotExchangeInfo] = await Promise.all([\n getFutureExchangeInfo(),\n getSpotExchangeInfo(),\n ]);\n\n const products: IProduct[] = [];\n\n // Convert future symbols to IProduct format\n for (const symbol of futureExchangeInfo.symbols) {\n products.push({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', symbol.symbol),\n base_currency: symbol.baseAsset,\n quote_currency: symbol.quoteAsset,\n price_step: +`1e-${symbol.pricePrecision}`,\n value_scale: 1,\n volume_step: +`1e-${symbol.quantityPrecision}`,\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n value_scale_unit: '',\n margin_rate: +symbol.requiredMarginPercent / 100,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'BINANCE/USDT-FUTURE',\n no_interest_rate: false,\n });\n }\n\n // Convert spot symbols to IProduct format\n for (const symbol of spotExchangeInfo.symbols) {\n if (symbol.isSpotTradingAllowed) {\n products.push({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', symbol.symbol),\n base_currency: symbol.baseAsset,\n quote_currency: symbol.quoteAsset,\n price_step: +`1e-${symbol.quotePrecision}`,\n value_scale: 1,\n volume_step: +`1e-${symbol.baseAssetPrecision}`,\n name: `${symbol.baseAsset}/${symbol.quoteAsset} SPOT`,\n value_scale_unit: '',\n margin_rate: 1,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'BINANCE/SPOT',\n no_interest_rate: true,\n });\n }\n\n if (symbol.isMarginTradingAllowed) {\n products.push({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'MARGIN', symbol.symbol),\n base_currency: symbol.baseAsset,\n quote_currency: symbol.quoteAsset,\n price_step: +`1e-${symbol.quotePrecision}`,\n value_scale: 1,\n volume_step: +`1e-${symbol.baseAssetPrecision}`,\n name: `${symbol.baseAsset}/${symbol.quoteAsset} MARGIN`,\n value_scale_unit: '',\n margin_rate: 1,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'BINANCE/MARGIN',\n no_interest_rate: false,\n });\n }\n }\n\n return products;\n },\n {\n auto_refresh_interval: 3600_000,\n },\n);\n"]}
@@ -52,7 +52,7 @@ const quoteFromOpenInterest$ = futureBookTicker$.pipe((0, rxjs_1.mergeMap)((entr
52
52
  product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', entry.symbol),
53
53
  open_interest: `${openInterest !== null && openInterest !== void 0 ? openInterest : 0}`,
54
54
  }))), 5));
55
- const quoteFromSpotBookTicker$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSpotBookTicker)({})).pipe((0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 30000 }), (0, rxjs_1.shareReplay)({ bufferSize: 1, refCount: true }), (0, rxjs_1.mergeMap)((entries) => (0, rxjs_1.from)(entries || [])), (0, rxjs_1.map)((entry) => ({
55
+ const quoteFromSpotBookTicker$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSpotBookTicker)({})).pipe((0, rxjs_1.mergeMap)((entries) => (0, rxjs_1.from)(entries || [])), (0, rxjs_1.map)((entry) => ({
56
56
  datasource_id: 'BINANCE',
57
57
  product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', entry.symbol),
58
58
  bid_price: entry.bidPrice,
@@ -60,7 +60,7 @@ const quoteFromSpotBookTicker$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSpo
60
60
  bid_volume: entry.bidQty,
61
61
  ask_volume: entry.askQty,
62
62
  updated_at: (0, utils_1.formatTime)(Date.now()),
63
- })));
63
+ })), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 30000 }), (0, rxjs_1.shareReplay)({ bufferSize: 1, refCount: true }));
64
64
  const marginInterestRateCache = (0, cache_1.createCache)(async (asset) => {
65
65
  var _a;
66
66
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../src/public-data/quote.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAmE;AACnE,+BAac;AACd,oDAAqG;AACrG,kDAK2B;AAE3B,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAO,CAAC;AAE1G,MAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,KAAK,EAAE,MAAc,EAAE,EAAE;;IACvB,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAA,IAAI,CAAC,YAAY,mCAAI,CAAC,CAAC,CAAC;KACvC;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAA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UAAU,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n defer,\n filter,\n from,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getMarginAllPairs, getMarginNextHourlyInterestRate, IMarginPair } from '../api/private-api';\nimport {\n getFutureBookTicker,\n getFutureOpenInterest,\n getFuturePremiumIndex,\n getSpotBookTicker,\n} from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120_000;\n\nconst openInterestCache = createCache<number>(\n async (symbol: string) => {\n try {\n const data = await getFutureOpenInterest({ symbol });\n return Number(data.openInterest ?? 0);\n } catch (err) {\n console.warn('getFutureOpenInterest failed', symbol, err);\n return undefined;\n }\n },\n {\n expire: OPEN_INTEREST_TTL,\n },\n);\n\nconst futurePremiumIndex$ = defer(() => getFuturePremiumIndex({})).pipe(\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst futureBookTicker$ = defer(() => getFutureBookTicker({})).pipe(\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst quoteFromPremiumIndex$ = futurePremiumIndex$.pipe(\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n last_price: entry.markPrice,\n // Use the latest funding rate so that long pays when fundingRate > 0\n interest_rate_long: `${-Number(entry.lastFundingRate)}`,\n interest_rate_short: entry.lastFundingRate,\n interest_rate_next_settled_at: formatTime(entry.nextFundingTime),\n updated_at: formatTime(entry.time ?? Date.now()),\n }),\n ),\n);\n\nconst quoteFromBookTicker$ = futureBookTicker$.pipe(\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n bid_price: entry.bidPrice,\n ask_price: entry.askPrice,\n updated_at: formatTime(entry.time ?? Date.now()),\n }),\n ),\n);\n\nconst quoteFromOpenInterest$ = futureBookTicker$.pipe(\n mergeMap((entries) => from(entries || [])),\n mergeMap(\n (entry) =>\n from(openInterestCache.query(entry.symbol)).pipe(\n map(\n (openInterest): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n open_interest: `${openInterest ?? 0}`,\n }),\n ),\n ),\n 5,\n ),\n);\n\nconst quoteFromSpotBookTicker$ = defer(() => getSpotBookTicker({})).pipe(\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', entry.symbol),\n bid_price: entry.bidPrice,\n ask_price: entry.askPrice,\n bid_volume: entry.bidQty,\n ask_volume: entry.askQty,\n updated_at: formatTime(Date.now()),\n }),\n ),\n);\n\nconst marginInterestRateCache = createCache<string>(\n async (asset: string) => {\n try {\n const data = await getMarginNextHourlyInterestRate({\n assets: asset,\n isIsolated: false,\n });\n return data[0]?.nextHourlyInterestRate;\n } catch (err) {\n return undefined;\n }\n },\n {\n expire: 60_000,\n },\n);\n\nconst marginPairs$ = defer(() => getMarginAllPairs()).pipe(\n repeat({ delay: 3600_000 }), // Refresh pair list hourly\n retry({ delay: 60_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst quoteFromMarginRates$ = marginPairs$.pipe(\n mergeMap((pairs: IMarginPair[]) =>\n from(pairs).pipe(\n mergeMap(\n (pair) =>\n defer(async () => {\n const [baseRate, quoteRate] = await Promise.all([\n marginInterestRateCache.query(pair.base),\n marginInterestRateCache.query(pair.quote),\n ]);\n return {\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', pair.symbol),\n // User instruction: Long = Quote Rate, Short = Base Rate\n interest_rate_long: quoteRate,\n interest_rate_short: baseRate,\n updated_at: formatTime(Date.now()),\n } as Partial<IQuote>;\n }),\n 5, // Concurrency\n ),\n ),\n ),\n repeat({ delay: 60_000 }),\n);\n\nconst quote$ = merge(\n quoteFromPremiumIndex$,\n quoteFromBookTicker$,\n quoteFromOpenInterest$,\n quoteFromSpotBookTicker$,\n quoteFromMarginRates$,\n).pipe(\n groupBy((quote) => quote.product_id),\n mergeMap((group$) =>\n group$.pipe(\n scan(\n (acc, cur) =>\n Object.assign(acc, cur, {\n datasource_id: 'BINANCE',\n product_id: group$.key,\n }),\n {} as Partial<IQuote>,\n ),\n ),\n ),\n share(),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n quote$\n .pipe(\n writeToSQL({\n terminal,\n tableName: 'quote',\n writeInterval: 1_000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n\n terminal.channel.publishChannel('quote', { pattern: '^BINANCE/' }, (channel_id) => {\n const [datasourceId, productId] = decodePath(channel_id);\n if (!datasourceId || !productId) {\n throw new Error(`Invalid channel_id: ${channel_id}`);\n }\n return quote$.pipe(filter((quote) => quote.product_id === productId));\n });\n}\n"]}
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../src/public-data/quote.ts"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,EACP,IAAA,kBAAW,EAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAC/C,CAAC;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,MAAM;SACH,IAAI,CACH,IAAA,gBAAU,EAAC;QACT,QAAQ;QACR,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE,IAAK;QACpB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;IAEf,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAChF,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n defer,\n filter,\n from,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getMarginAllPairs, getMarginNextHourlyInterestRate, IMarginPair } from '../api/private-api';\nimport {\n getFutureBookTicker,\n getFutureOpenInterest,\n getFuturePremiumIndex,\n getSpotBookTicker,\n} from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120_000;\n\nconst openInterestCache = createCache<number>(\n async (symbol: string) => {\n try {\n const data = await getFutureOpenInterest({ symbol });\n return Number(data.openInterest ?? 0);\n } catch (err) {\n console.warn('getFutureOpenInterest failed', symbol, err);\n return undefined;\n }\n },\n {\n expire: OPEN_INTEREST_TTL,\n },\n);\n\nconst futurePremiumIndex$ = defer(() => getFuturePremiumIndex({})).pipe(\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst futureBookTicker$ = defer(() => getFutureBookTicker({})).pipe(\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst quoteFromPremiumIndex$ = futurePremiumIndex$.pipe(\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n last_price: entry.markPrice,\n // Use the latest funding rate so that long pays when fundingRate > 0\n interest_rate_long: `${-Number(entry.lastFundingRate)}`,\n interest_rate_short: entry.lastFundingRate,\n interest_rate_next_settled_at: formatTime(entry.nextFundingTime),\n updated_at: formatTime(entry.time ?? Date.now()),\n }),\n ),\n);\n\nconst quoteFromBookTicker$ = futureBookTicker$.pipe(\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n bid_price: entry.bidPrice,\n ask_price: entry.askPrice,\n updated_at: formatTime(entry.time ?? Date.now()),\n }),\n ),\n);\n\nconst quoteFromOpenInterest$ = futureBookTicker$.pipe(\n mergeMap((entries) => from(entries || [])),\n mergeMap(\n (entry) =>\n from(openInterestCache.query(entry.symbol)).pipe(\n map(\n (openInterest): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', entry.symbol),\n open_interest: `${openInterest ?? 0}`,\n }),\n ),\n ),\n 5,\n ),\n);\n\nconst quoteFromSpotBookTicker$ = defer(() => getSpotBookTicker({})).pipe(\n mergeMap((entries) => from(entries || [])),\n map(\n (entry): Partial<IQuote> => ({\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', entry.symbol),\n bid_price: entry.bidPrice,\n ask_price: entry.askPrice,\n bid_volume: entry.bidQty,\n ask_volume: entry.askQty,\n updated_at: formatTime(Date.now()),\n }),\n ),\n repeat({ delay: 1_000 }),\n retry({ delay: 30_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst marginInterestRateCache = createCache<string>(\n async (asset: string) => {\n try {\n const data = await getMarginNextHourlyInterestRate({\n assets: asset,\n isIsolated: false,\n });\n return data[0]?.nextHourlyInterestRate;\n } catch (err) {\n return undefined;\n }\n },\n {\n expire: 60_000,\n },\n);\n\nconst marginPairs$ = defer(() => getMarginAllPairs()).pipe(\n repeat({ delay: 3600_000 }), // Refresh pair list hourly\n retry({ delay: 60_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nconst quoteFromMarginRates$ = marginPairs$.pipe(\n mergeMap((pairs: IMarginPair[]) =>\n from(pairs).pipe(\n mergeMap(\n (pair) =>\n defer(async () => {\n const [baseRate, quoteRate] = await Promise.all([\n marginInterestRateCache.query(pair.base),\n marginInterestRateCache.query(pair.quote),\n ]);\n return {\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'SPOT', pair.symbol),\n // User instruction: Long = Quote Rate, Short = Base Rate\n interest_rate_long: quoteRate,\n interest_rate_short: baseRate,\n updated_at: formatTime(Date.now()),\n } as Partial<IQuote>;\n }),\n 5, // Concurrency\n ),\n ),\n ),\n repeat({ delay: 60_000 }),\n);\n\nconst quote$ = merge(\n quoteFromPremiumIndex$,\n quoteFromBookTicker$,\n quoteFromOpenInterest$,\n quoteFromSpotBookTicker$,\n quoteFromMarginRates$,\n).pipe(\n groupBy((quote) => quote.product_id),\n mergeMap((group$) =>\n group$.pipe(\n scan(\n (acc, cur) =>\n Object.assign(acc, cur, {\n datasource_id: 'BINANCE',\n product_id: group$.key,\n }),\n {} as Partial<IQuote>,\n ),\n ),\n ),\n share(),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n quote$\n .pipe(\n writeToSQL({\n terminal,\n tableName: 'quote',\n writeInterval: 1_000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n\n terminal.channel.publishChannel('quote', { pattern: '^BINANCE/' }, (channel_id) => {\n const [datasourceId, productId] = decodePath(channel_id);\n if (!datasourceId || !productId) {\n throw new Error(`Invalid channel_id: ${channel_id}`);\n }\n return quote$.pipe(filter((quote) => quote.product_id === productId));\n });\n}\n"]}
@@ -1,7 +1,3 @@
1
1
  import { ICredential } from '../../api/private-api';
2
- interface IAccountProfile {
3
- uid: string;
4
- }
5
- export declare const resolveAccountProfile: (credential: ICredential) => Promise<IAccountProfile>;
6
- export {};
2
+ export declare const getCredentialId: (credential: ICredential) => Promise<string>;
7
3
  //# sourceMappingURL=profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAiBD,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,eAAe,CAO5F,CAAC"}
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,eAAO,MAAM,eAAe,eAAsB,WAAW,KAAG,QAAQ,MAAM,CAM7E,CAAC"}
@@ -1,26 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveAccountProfile = void 0;
4
- const cache_1 = require("@yuants/cache");
3
+ exports.getCredentialId = void 0;
4
+ const utils_1 = require("@yuants/utils");
5
5
  const client_1 = require("../../api/client");
6
6
  const private_api_1 = require("../../api/private-api");
7
- const PROFILE_TTL = 60000;
8
- const serializeCredential = (credential) => JSON.stringify(credential);
9
- const deserializeCredential = (key) => JSON.parse(key);
10
- const accountProfileCache = (0, cache_1.createCache)(async (key) => {
11
- const spotAccountInfo = await (0, private_api_1.getSpotAccountInfo)(deserializeCredential(key));
7
+ const getCredentialId = async (credential) => {
8
+ const spotAccountInfo = await (0, private_api_1.getSpotAccountInfo)(credential);
12
9
  if ((0, client_1.isApiError)(spotAccountInfo)) {
13
10
  throw new Error(spotAccountInfo.msg);
14
11
  }
15
- return { uid: `${spotAccountInfo.uid}` };
16
- }, { expire: PROFILE_TTL });
17
- const resolveAccountProfile = async (credential) => {
18
- const key = serializeCredential(credential);
19
- const profile = await accountProfileCache.query(key);
20
- if (!profile) {
21
- throw new Error('Unable to resolve Binance account profile');
22
- }
23
- return profile;
12
+ return (0, utils_1.encodePath)('BINANCE', spotAccountInfo.uid);
24
13
  };
25
- exports.resolveAccountProfile = resolveAccountProfile;
14
+ exports.getCredentialId = getCredentialId;
26
15
  //# sourceMappingURL=profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,6CAA8C;AAC9C,uDAAwE;AAMxE,MAAM,WAAW,GAAG,KAAM,CAAC;AAC3B,MAAM,mBAAmB,GAAG,CAAC,UAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACpF,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAe,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAgB,CAAC;AAE3F,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,eAAe,GAAG,MAAM,IAAA,gCAAkB,EAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7E,IAAI,IAAA,mBAAU,EAAC,eAAe,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;KACtC;IACD,OAAO,EAAE,GAAG,EAAE,GAAG,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC;AAC3C,CAAC,EACD,EAAE,MAAM,EAAE,WAAW,EAAE,CACxB,CAAC;AAEK,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA4B,EAAE;IAC/F,MAAM,GAAG,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\ninterface IAccountProfile {\n uid: string;\n}\n\nconst PROFILE_TTL = 60_000;\nconst serializeCredential = (credential: ICredential) => JSON.stringify(credential);\nconst deserializeCredential = (key: string): ICredential => JSON.parse(key) as ICredential;\n\nconst accountProfileCache = createCache<IAccountProfile>(\n async (key) => {\n const spotAccountInfo = await getSpotAccountInfo(deserializeCredential(key));\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n return { uid: `${spotAccountInfo.uid}` };\n },\n { expire: PROFILE_TTL },\n);\n\nexport const resolveAccountProfile = async (credential: ICredential): Promise<IAccountProfile> => {\n const key = serializeCredential(credential);\n const profile = await accountProfileCache.query(key);\n if (!profile) {\n throw new Error('Unable to resolve Binance account profile');\n }\n return profile;\n};\n"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAwE;AAEjE,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,eAAe,GAAG,MAAM,IAAA,gCAAkB,EAAC,UAAU,CAAC,CAAC;IAC7D,IAAI,IAAA,mBAAU,EAAC,eAAe,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;KACtC;IACD,OAAO,IAAA,kBAAU,EAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC,CAAC;AANW,QAAA,eAAe,mBAM1B","sourcesContent":["import { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\nexport const getCredentialId = async (credential: ICredential): Promise<string> => {\n const spotAccountInfo = await getSpotAccountInfo(credential);\n if (isApiError(spotAccountInfo)) {\n throw new Error(spotAccountInfo.msg);\n }\n return encodePath('BINANCE', spotAccountInfo.uid);\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
+ import { IPosition } from '@yuants/data-account';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const getSpotAccountInfoSnapshot: IActionHandlerOfGetAccountInfo<ICredential>;
3
+ export declare const getSpotAccountInfoSnapshot: (credential: ICredential) => Promise<IPosition[]>;
4
4
  //# sourceMappingURL=spot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA+B,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,eAAO,MAAM,0BAA0B,EAAE,8BAA8B,CAAC,WAAW,CAqBlF,CAAC"}
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,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,eAAO,MAAM,0BAA0B,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAqB7F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmG;AACnG,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAwE;AAEjE,MAAM,0BAA0B,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAC1G,MAAM,GAAG,GAAG,MAAM,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ;SAC3B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,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,MAAM,CAAC;YACjE,MAAM;YACN,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI;YAC1B,cAAc,EAAE,CAAC,EAAE,0BAA0B;SAC9C,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;AArBW,QAAA,0BAA0B,8BAqBrC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfoSnapshot: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const res = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n const positions = res.balances\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}USDT`),\n volume,\n free_volume: +balance.free,\n closable_price: 0, // TODO: fetch price later\n });\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n};\n"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAwE;AAEjE,MAAM,0BAA0B,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAChG,MAAM,GAAG,GAAG,MAAM,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ;SAC3B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,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,MAAM,CAAC;YACjE,MAAM;YACN,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI;YAC1B,cAAc,EAAE,CAAC,EAAE,0BAA0B;SAC9C,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;AArBW,QAAA,0BAA0B,8BAqBrC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getSpotAccountInfo, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfoSnapshot = async (credential: ICredential): Promise<IPosition[]> => {\n const res = await getSpotAccountInfo(credential, { omitZeroBalances: true });\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n const positions = res.balances\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}USDT`),\n volume,\n free_volume: +balance.free,\n closable_price: 0, // TODO: fetch price later\n });\n return position;\n })\n .filter((position): position is IPosition => Boolean(position));\n return positions;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
+ import { IPosition } from '@yuants/data-account';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const getUnifiedAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
3
+ export declare const getUnifiedAccountInfo: (credential: ICredential) => Promise<IPosition[]>;
4
4
  //# sourceMappingURL=unified.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAGjF,OAAO,EAAiD,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEnG,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,CAoD7E,CAAC"}
1
+ {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAiD,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEnG,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAsCxF,CAAC"}
@@ -4,7 +4,7 @@ exports.getUnifiedAccountInfo = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const client_1 = require("../../api/client");
6
6
  const private_api_1 = require("../../api/private-api");
7
- const getUnifiedAccountInfo = async (credential, _accountId) => {
7
+ const getUnifiedAccountInfo = async (credential) => {
8
8
  const [balanceRes, umAccountRes] = await Promise.all([
9
9
  (0, private_api_1.getUnifiedAccountBalance)(credential),
10
10
  (0, private_api_1.getUnifiedUmAccount)(credential),
@@ -15,16 +15,6 @@ const getUnifiedAccountInfo = async (credential, _accountId) => {
15
15
  if ((0, client_1.isApiError)(umAccountRes)) {
16
16
  throw new Error(umAccountRes.msg);
17
17
  }
18
- const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');
19
- if (!usdtBalance) {
20
- throw new Error('USDT balance not found');
21
- }
22
- const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');
23
- if (!usdtAsset) {
24
- throw new Error('USDT asset not found in UM account');
25
- }
26
- const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;
27
- const free = equity - +usdtAsset.initialMargin;
28
18
  const positions = umAccountRes.positions
29
19
  .filter((position) => +position.positionAmt !== 0)
30
20
  .map((position) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AAE5F,MAAM,qBAAqB,GAAgD,KAAK,EACrF,UAAU,EACV,UAAU,EACV,EAAE;IACF,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IACD,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,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AAE,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW;QACzF,eAAe,EAAE,CAAC,QAAQ,CAAC,gBAAgB;QAC3C,SAAS,EACP,CAAC,QAAQ,CAAC,WAAW;YACrB,CAAC,CAAC,QAAQ,CAAC,UAAU;gBACnB,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAC5F,CAAC,CAAC,CAAC;IAEN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApDW,QAAA,qBAAqB,yBAoDhC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n _accountId,\n) => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n const usdtBalance = balanceRes.find((item) => item.asset === 'USDT');\n if (!usdtBalance) {\n throw new Error('USDT balance not found');\n }\n const usdtAsset = umAccountRes.assets.find((item) => item.asset === 'USDT');\n if (!usdtAsset) {\n throw new Error('USDT asset not found in UM account');\n }\n\n const equity = +usdtBalance.totalWalletBalance + +usdtBalance.umUnrealizedPNL;\n const free = equity - +usdtAsset.initialMargin;\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AAE5F,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED,MAAM,SAAS,GAAgB,YAAY,CAAC,SAAS;SAClD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,CAAC,CAAC;SACjD,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClB,WAAW,EAAE,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,YAAY,EAAE;QAC1D,aAAa,EAAE,SAAS;QACxB,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC;QACjE,SAAS,EACP,QAAQ,CAAC,YAAY,KAAK,MAAM;YAC9B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,QAAQ,CAAC,YAAY,KAAK,OAAO;gBACnC,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,QAAQ,CAAC,YAAY,KAAK,MAAM;oBAClC,CAAC,CAAC,MAAM;oBACR,CAAC,CAAC,SAAS;QACf,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW;QAC7B,WAAW,EAAE,CAAC,QAAQ,CAAC,WAAW;QAClC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU;QACpC,cAAc,EAAE,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW;QACzF,eAAe,EAAE,CAAC,QAAQ,CAAC,gBAAgB;QAC3C,SAAS,EACP,CAAC,QAAQ,CAAC,WAAW;YACrB,CAAC,CAAC,QAAQ,CAAC,UAAU;gBACnB,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAC5F,CAAC,CAAC,CAAC;IAEN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAtCW,QAAA,qBAAqB,yBAsChC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n return positions;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exchange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":""}
@@ -0,0 +1,58 @@
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 product_1 = require("../public-data/product");
7
+ const profile_1 = require("./accounts/profile");
8
+ const spot_1 = require("./accounts/spot");
9
+ const unified_1 = require("./accounts/unified");
10
+ const cancelOrder_1 = require("./orders/cancelOrder");
11
+ const listOrders_1 = require("./orders/listOrders");
12
+ const modifyOrder_1 = require("./orders/modifyOrder");
13
+ const submitOrder_1 = require("./orders/submitOrder");
14
+ const terminal = protocol_1.Terminal.fromNodeEnv();
15
+ (0, exchange_1.provideExchangeServices)(terminal, {
16
+ name: 'BINANCE',
17
+ credentialSchema: {
18
+ type: 'object',
19
+ required: ['access_key', 'secret_key'],
20
+ properties: {
21
+ access_key: { type: 'string' },
22
+ secret_key: { type: 'string' },
23
+ },
24
+ },
25
+ getCredentialId: profile_1.getCredentialId,
26
+ listProducts: product_1.listProducts,
27
+ getPositions: async function (credential) {
28
+ const [uFuturePositions, spotPositions] = await Promise.all([
29
+ (0, unified_1.getUnifiedAccountInfo)(credential),
30
+ (0, spot_1.getSpotAccountInfoSnapshot)(credential),
31
+ ]);
32
+ return [...uFuturePositions, ...spotPositions];
33
+ },
34
+ getOrders: async function (credential) {
35
+ const [umOrders, spotOrders] = await Promise.all([
36
+ (0, listOrders_1.listUnifiedUmOrders)(credential),
37
+ (0, listOrders_1.listSpotOrders)(credential),
38
+ ]);
39
+ return [...umOrders, ...spotOrders];
40
+ },
41
+ getPositionsByProductId: async function (credential, product_id) {
42
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // BINANCE/USDT-FUTURE/ADAUSDT
43
+ if (instType === 'SPOT') {
44
+ const positions = await (0, spot_1.getSpotAccountInfoSnapshot)(credential);
45
+ return positions.filter((position) => position.product_id === product_id);
46
+ }
47
+ if (instType === 'USDT-FUTURE') {
48
+ const positions = await (0, unified_1.getUnifiedAccountInfo)(credential);
49
+ return positions.filter((position) => position.product_id === product_id);
50
+ }
51
+ throw new Error(`Unsupported instType: ${instType}`);
52
+ },
53
+ getOrdersByProductId: listOrders_1.getOrdersByProductId,
54
+ submitOrder: submitOrder_1.submitOrder,
55
+ modifyOrder: modifyOrder_1.modifyOrder,
56
+ cancelOrder: cancelOrder_1.cancelOrder,
57
+ });
58
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +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;A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AK,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,4 +1,6 @@
1
- import { IActionHandlerOfListOrders } from '@yuants/data-order';
1
+ import { IOrder } from '@yuants/data-order';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const listOrders: IActionHandlerOfListOrders<ICredential>;
3
+ export declare const listUnifiedUmOrders: (credential: ICredential) => Promise<IOrder[]>;
4
+ export declare const listSpotOrders: (credential: ICredential) => Promise<IOrder[]>;
5
+ export declare const getOrdersByProductId: (credential: ICredential, product_id: string) => Promise<IOrder[]>;
4
6
  //# sourceMappingURL=listOrders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAU,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAA6C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQ/F,eAAO,MAAM,UAAU,EAAE,0BAA0B,CAAC,WAAW,CA8C9D,CAAC"}
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAA6C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQ/F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAsBnF,CAAC;AAEF,eAAO,MAAM,cAAc,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAoB9E,CAAC;AAEF,eAAO,MAAM,oBAAoB,eACnB,WAAW,cACX,MAAM,KACjB,QAAQ,MAAM,EAAE,CAWlB,CAAC"}
@@ -1,53 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listOrders = void 0;
3
+ exports.getOrdersByProductId = exports.listSpotOrders = exports.listUnifiedUmOrders = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const client_1 = require("../../api/client");
6
6
  const private_api_1 = require("../../api/private-api");
7
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)('BINANCE', '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
- });
8
+ const listUnifiedUmOrders = async (credential) => {
9
+ const res = await (0, private_api_1.getUnifiedUmOpenOrders)(credential);
10
+ if ((0, client_1.isApiError)(res)) {
11
+ throw new Error(res.msg);
30
12
  }
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) => ({
13
+ return res.map((order) => {
14
+ var _a;
15
+ return ({
37
16
  order_id: `${order.orderId}`,
38
- account_id,
39
- product_id: (0, utils_1.encodePath)('BINANCE', 'SPOT', order.symbol),
17
+ account_id: '',
18
+ product_id: (0, utils_1.encodePath)('BINANCE', 'USDT-FUTURE', order.symbol),
40
19
  order_type: (0, order_utils_1.mapBinanceOrderTypeToYuants)(order.type),
41
- order_direction: (0, order_utils_1.mapSpotSideToOrderDirection)(order.side),
20
+ order_direction: (_a = (0, order_utils_1.mapBinanceSideToYuantsDirection)(order.side, order.positionSide)) !== null && _a !== void 0 ? _a : (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),
42
21
  volume: +order.origQty,
43
22
  traded_volume: +order.executedQty,
44
- price: order.price ? +order.price : undefined,
23
+ price: order.price === undefined ? undefined : +order.price,
45
24
  submit_at: order.time,
46
25
  updated_at: (0, utils_1.formatTime)(order.updateTime),
47
26
  order_status: (0, order_utils_1.mapBinanceOrderStatus)(order.status),
48
- }));
27
+ });
28
+ });
29
+ };
30
+ exports.listUnifiedUmOrders = listUnifiedUmOrders;
31
+ const listSpotOrders = async (credential) => {
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)('BINANCE', '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 === undefined ? undefined : +order.price,
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
+ exports.listSpotOrders = listSpotOrders;
51
+ const getOrdersByProductId = async function (credential, product_id) {
52
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // BINANCE/USDT-FUTURE/ADAUSDT
53
+ if (instType === 'SPOT') {
54
+ const orders = await (0, exports.listSpotOrders)(credential);
55
+ return orders.filter((order) => order.product_id === product_id);
56
+ }
57
+ if (instType === 'USDT-FUTURE') {
58
+ const orders = await (0, exports.listUnifiedUmOrders)(credential);
59
+ return orders.filter((order) => order.product_id === product_id);
49
60
  }
50
- throw new Error(`Unsupported account_id for listOrders: ${account_id}`);
61
+ throw new Error(`Unsupported instType: ${instType}`);
51
62
  };
52
- exports.listOrders = listOrders;
63
+ exports.getOrdersByProductId = getOrdersByProductId;
53
64
  //# sourceMappingURL=listOrders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAuD;AACvD,6CAA8C;AAC9C,uDAA+F;AAC/F,+CAKuB;AAEhB,MAAM,UAAU,GAA4C,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;IAClG,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACpC,MAAM,GAAG,GAAG,MAAM,IAAA,oCAAsB,EAAC,UAAU,CAAC,CAAC;QACrD,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG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AQ,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;YAC5B,UAAU;YACV,UAAU,EAAE,IAAA,kBAAU,EAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;YACvD,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('BINANCE', 'USDT-FUTURE', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction:\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ??\n (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n }\n if (account_id.includes('/spot/')) {\n const res = await getSpotOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('BINANCE', 'SPOT', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction: mapSpotSideToOrderDirection(order.side),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price ? +order.price : undefined,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n }\n throw new Error(`Unsupported account_id for listOrders: ${account_id}`);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAmE;AACnE,6CAA8C;AAC9C,uDAA+F;AAC/F,+CAKuB;AAEhB,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAqB,EAAE;IACtF,MAAM,GAAG,GAAG,MAAM,IAAA,oCAAsB,EAAC,UAAU,CAAC,CAAC;IACrD,IAAI,IAAA,mBAAU,EAAC,GAAG,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,GAAG,CAAC,GAAG,CACZ,CAAC,KAAK,EAAU,EAAE;;QAAC,OAAA,CAAC;YAClB,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;YAC5B,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,IAAA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C;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport { decodePath, 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 listUnifiedUmOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const res = await getUnifiedUmOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id: '',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction:\n mapBinanceSideToYuantsDirection(order.side, order.positionSide) ??\n (order.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT'),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === undefined ? undefined : +order.price,\n submit_at: order.time,\n updated_at: formatTime(order.updateTime),\n order_status: mapBinanceOrderStatus(order.status),\n }),\n );\n};\n\nexport const listSpotOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const res = await getSpotOpenOrders(credential);\n if (isApiError(res)) {\n throw new Error(res.msg);\n }\n return res.map(\n (order): IOrder => ({\n order_id: `${order.orderId}`,\n account_id: '',\n product_id: encodePath('BINANCE', 'SPOT', order.symbol),\n order_type: mapBinanceOrderTypeToYuants(order.type),\n order_direction: mapSpotSideToOrderDirection(order.side),\n volume: +order.origQty,\n traded_volume: +order.executedQty,\n price: order.price === 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\nexport const getOrdersByProductId = async function (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n if (instType === 'SPOT') {\n const orders = await listSpotOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n if (instType === 'USDT-FUTURE') {\n const orders = await listUnifiedUmOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n};\n"]}