@yuants/vendor-binance 0.8.7 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/api/client.js +14 -5
  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 -400
  8. package/dist/legacy_index.js.map +1 -1
  9. package/dist/public-data/interest_rate.js +5 -3
  10. package/dist/public-data/interest_rate.js.map +1 -1
  11. package/dist/public-data/ohlc.js +1 -1
  12. package/dist/public-data/ohlc.js.map +1 -1
  13. package/dist/public-data/product.js +83 -4
  14. package/dist/public-data/product.js.map +1 -1
  15. package/dist/public-data/quote.js +7 -7
  16. package/dist/public-data/quote.js.map +1 -1
  17. package/dist/services/accounts/profile.js +4 -15
  18. package/dist/services/accounts/profile.js.map +1 -1
  19. package/dist/services/accounts/spot.js +1 -1
  20. package/dist/services/accounts/spot.js.map +1 -1
  21. package/dist/services/accounts/unified.js +2 -12
  22. package/dist/services/accounts/unified.js.map +1 -1
  23. package/dist/services/exchange.js +56 -0
  24. package/dist/services/exchange.js.map +1 -0
  25. package/dist/services/orders/cancelOrder.js +5 -3
  26. package/dist/services/orders/cancelOrder.js.map +1 -1
  27. package/dist/services/orders/listOrders.js +44 -35
  28. package/dist/services/orders/listOrders.js.map +1 -1
  29. package/dist/services/orders/modifyOrder.js +6 -3
  30. package/dist/services/orders/modifyOrder.js.map +1 -1
  31. package/dist/services/orders/order-utils.js +29 -7
  32. package/dist/services/orders/order-utils.js.map +1 -1
  33. package/dist/services/orders/submitOrder.js +5 -3
  34. package/dist/services/orders/submitOrder.js.map +1 -1
  35. package/lib/api/client.d.ts.map +1 -1
  36. package/lib/api/client.js +13 -7
  37. package/lib/api/client.js.map +1 -1
  38. package/lib/api/public-api.d.ts +41 -0
  39. package/lib/api/public-api.d.ts.map +1 -1
  40. package/lib/api/public-api.js +8 -1
  41. package/lib/api/public-api.js.map +1 -1
  42. package/lib/index.d.ts +1 -2
  43. package/lib/index.d.ts.map +1 -1
  44. package/lib/index.js +1 -2
  45. package/lib/index.js.map +1 -1
  46. package/lib/legacy_index.d.ts +0 -1
  47. package/lib/legacy_index.js +162 -401
  48. package/lib/legacy_index.js.map +1 -1
  49. package/lib/public-data/interest_rate.js +5 -3
  50. package/lib/public-data/interest_rate.js.map +1 -1
  51. package/lib/public-data/ohlc.js +1 -1
  52. package/lib/public-data/ohlc.js.map +1 -1
  53. package/lib/public-data/product.d.ts +2 -1
  54. package/lib/public-data/product.d.ts.map +1 -1
  55. package/lib/public-data/product.js +84 -3
  56. package/lib/public-data/product.js.map +1 -1
  57. package/lib/public-data/quote.js +7 -7
  58. package/lib/public-data/quote.js.map +1 -1
  59. package/lib/services/accounts/profile.d.ts +1 -5
  60. package/lib/services/accounts/profile.d.ts.map +1 -1
  61. package/lib/services/accounts/profile.js +6 -17
  62. package/lib/services/accounts/profile.js.map +1 -1
  63. package/lib/services/accounts/spot.d.ts +2 -2
  64. package/lib/services/accounts/spot.d.ts.map +1 -1
  65. package/lib/services/accounts/spot.js +1 -1
  66. package/lib/services/accounts/spot.js.map +1 -1
  67. package/lib/services/accounts/unified.d.ts +2 -2
  68. package/lib/services/accounts/unified.d.ts.map +1 -1
  69. package/lib/services/accounts/unified.js +2 -12
  70. package/lib/services/accounts/unified.js.map +1 -1
  71. package/lib/services/exchange.d.ts +2 -0
  72. package/lib/services/exchange.d.ts.map +1 -0
  73. package/lib/services/exchange.js +58 -0
  74. package/lib/services/exchange.js.map +1 -0
  75. package/lib/services/orders/cancelOrder.d.ts.map +1 -1
  76. package/lib/services/orders/cancelOrder.js +5 -3
  77. package/lib/services/orders/cancelOrder.js.map +1 -1
  78. package/lib/services/orders/listOrders.d.ts +4 -2
  79. package/lib/services/orders/listOrders.d.ts.map +1 -1
  80. package/lib/services/orders/listOrders.js +47 -36
  81. package/lib/services/orders/listOrders.js.map +1 -1
  82. package/lib/services/orders/modifyOrder.d.ts.map +1 -1
  83. package/lib/services/orders/modifyOrder.js +6 -3
  84. package/lib/services/orders/modifyOrder.js.map +1 -1
  85. package/lib/services/orders/order-utils.d.ts.map +1 -1
  86. package/lib/services/orders/order-utils.js +29 -7
  87. package/lib/services/orders/order-utils.js.map +1 -1
  88. package/lib/services/orders/submitOrder.d.ts.map +1 -1
  89. package/lib/services/orders/submitOrder.js +5 -3
  90. package/lib/services/orders/submitOrder.js.map +1 -1
  91. package/package.json +2 -1
  92. package/temp/package-deps.json +23 -24
  93. package/dist/cli.js +0 -3
  94. package/dist/cli.js.map +0 -1
  95. package/dist/services/account-actions-with-credential.js +0 -34
  96. package/dist/services/account-actions-with-credential.js.map +0 -1
  97. package/dist/services/order-actions-with-credential.js +0 -21
  98. package/dist/services/order-actions-with-credential.js.map +0 -1
  99. package/lib/cli.d.ts +0 -3
  100. package/lib/cli.d.ts.map +0 -1
  101. package/lib/cli.js +0 -5
  102. package/lib/cli.js.map +0 -1
  103. package/lib/services/account-actions-with-credential.d.ts +0 -2
  104. package/lib/services/account-actions-with-credential.d.ts.map +0 -1
  105. package/lib/services/account-actions-with-credential.js +0 -36
  106. package/lib/services/account-actions-with-credential.js.map +0 -1
  107. package/lib/services/order-actions-with-credential.d.ts +0 -2
  108. package/lib/services/order-actions-with-credential.d.ts.map +0 -1
  109. package/lib/services/order-actions-with-credential.js +0 -23
  110. package/lib/services/order-actions-with-credential.js.map +0 -1
@@ -1,403 +1,164 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_account_1 = require("@yuants/data-account");
4
- const data_order_1 = require("@yuants/data-order");
5
- const protocol_1 = require("@yuants/protocol");
6
- const transfer_1 = require("@yuants/transfer");
7
- const utils_1 = require("@yuants/utils");
8
- const crypto_1 = require("crypto");
9
- const client_1 = require("./api/client");
10
- const private_api_1 = require("./api/private-api");
11
- const public_api_1 = require("./api/public-api");
12
- const terminal = protocol_1.Terminal.fromNodeEnv();
13
- const _mapSymbolToOpenInterest = {};
14
- const getOpenInterest = async (symbol) => {
15
- const expired_at = Date.now() - 600000; // 10min expired
16
- const cache = _mapSymbolToOpenInterest[symbol];
17
- if (cache) {
18
- if (cache.updated_at > expired_at) {
19
- return cache.value;
20
- }
21
- }
22
- const data = await (0, public_api_1.getFutureOpenInterest)({ symbol });
23
- const value = +data.openInterest || 0;
24
- _mapSymbolToOpenInterest[symbol] = { value, updated_at: Date.now() };
25
- return value;
26
- };
27
- const mapOrderDirectionToSide = (direction) => {
28
- switch (direction) {
29
- case 'OPEN_LONG':
30
- case 'CLOSE_SHORT':
31
- return 'BUY';
32
- case 'OPEN_SHORT':
33
- case 'CLOSE_LONG':
34
- return 'SELL';
35
- }
36
- throw new Error(`Unknown direction: ${direction}`);
37
- };
38
- const mapOrderDirectionToPosSide = (direction) => {
39
- switch (direction) {
40
- case 'OPEN_LONG':
41
- case 'CLOSE_LONG':
42
- return 'LONG';
43
- case 'OPEN_SHORT':
44
- case 'CLOSE_SHORT':
45
- return 'SHORT';
46
- }
47
- throw new Error(`Unknown direction: ${direction}`);
48
- };
49
- const mapOrderTypeToOrdType = (order_type) => {
50
- switch (order_type) {
51
- case 'LIMIT':
52
- case 'MAKER':
53
- return 'LIMIT';
54
- case 'MARKET':
55
- return 'MARKET';
56
- }
57
- throw new Error(`Unknown order type: ${order_type}`);
58
- };
59
- const mapBinanceOrderTypeToYuants = (binanceType) => {
60
- switch (binanceType) {
61
- case 'LIMIT':
62
- return 'LIMIT';
63
- case 'MARKET':
64
- return 'MARKET';
65
- default:
66
- return 'LIMIT';
67
- }
68
- };
69
- const mapBinanceSideToYuantsDirection = (side, positionSide) => {
70
- if (!side || !positionSide) {
71
- return undefined;
72
- }
73
- if (positionSide === 'LONG') {
74
- return side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';
75
- }
76
- if (positionSide === 'SHORT') {
77
- return side === 'SELL' ? 'OPEN_SHORT' : 'CLOSE_SHORT';
78
- }
79
- return undefined;
80
- };
81
- const deriveClientOrderId = (order) => {
82
- if (order.order_id)
83
- return `${order.order_id}`;
84
- if (order.comment)
85
- return order.comment;
86
- const payload = JSON.stringify({
87
- account_id: order.account_id,
88
- product_id: order.product_id,
89
- order_direction: order.order_direction,
90
- order_type: order.order_type,
91
- price: order.price,
92
- volume: order.volume,
93
- });
94
- return `YUANTS${(0, crypto_1.createHash)('sha256').update(payload).digest('hex').slice(0, 24)}`;
95
- };
96
- const isPublicOnly = process.env.PUBLIC_ONLY === 'true';
97
- // provideTicks(terminal, 'binance', (product_id) => {
98
- // const [instType, symbol] = decodePath(product_id);
99
- // if (instType === 'usdt-future') {
100
- // return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(
101
- // combineLatestWith(defer(() => getOpenInterest(symbol))),
102
- // map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {
103
- // const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);
104
- // const bookTicker = mapSymbolToFutureBookTicker.get(symbol);
105
- // if (!premiumIndex) {
106
- // throw new Error(`Premium Index Not Found: ${symbol}`);
107
- // }
108
- // if (!bookTicker) {
109
- // throw new Error(`Book Ticker Not Found: ${symbol}`);
110
- // }
111
- // return {
112
- // datasource_id: 'binance',
113
- // product_id,
114
- // updated_at: Date.now(),
115
- // price: +premiumIndex.markPrice,
116
- // ask: +bookTicker.askPrice,
117
- // bid: +bookTicker.bidPrice,
118
- // interest_rate_for_long: -+premiumIndex.lastFundingRate,
119
- // interest_rate_for_short: +premiumIndex.lastFundingRate,
120
- // settlement_scheduled_at: premiumIndex.nextFundingTime,
121
- // open_interest: openInterestVolume,
122
- // };
123
- // }),
124
- // );
125
- // }
126
- // return EMPTY;
127
- // });
128
- if (isPublicOnly) {
129
- console.info('PUBLIC_ONLY=1, skip Binance legacy services');
130
- }
131
- else {
132
- const credential = (0, client_1.getDefaultCredential)();
133
- (async () => {
134
- const spotAccountInfo = await (0, private_api_1.getSpotAccountInfo)(credential);
135
- if ((0, client_1.isApiError)(spotAccountInfo)) {
136
- throw new Error(spotAccountInfo.msg);
137
- }
138
- const uid = spotAccountInfo.uid;
139
- const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;
140
- const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;
141
- {
142
- // unified accountInfo
143
- (0, data_account_1.provideAccountInfoService)(terminal, UNIFIED_ACCOUNT_ID, async () => {
144
- const [accountResult, umAccountResult] = await Promise.all([
145
- (0, private_api_1.getUnifiedAccountBalance)(credential),
146
- (0, private_api_1.getUnifiedUmAccount)(credential),
147
- ]);
148
- if ((0, client_1.isApiError)(accountResult)) {
149
- throw new Error(accountResult.msg);
150
- }
151
- const usdtAssets = accountResult.find((v) => v.asset === 'USDT');
152
- if (!usdtAssets) {
153
- throw new Error('USDT not found');
154
- }
155
- if ((0, client_1.isApiError)(umAccountResult)) {
156
- throw new Error(umAccountResult.msg);
157
- }
158
- const usdtUmAssets = umAccountResult.assets.find((v) => v.asset === 'USDT');
159
- if (!usdtUmAssets) {
160
- throw new Error('um USDT not found');
161
- }
162
- const equity = +usdtAssets.totalWalletBalance + +usdtAssets.umUnrealizedPNL;
163
- const free = equity - +usdtUmAssets.initialMargin;
164
- const positions = umAccountResult.positions
165
- .filter((v) => +v.positionAmt !== 0)
166
- .map((v) => {
167
- return {
168
- position_id: `${v.symbol}/${v.positionSide}`,
169
- datasource_id: 'BINANCE',
170
- product_id: (0, utils_1.encodePath)('usdt-future', v.symbol),
171
- direction: v.positionSide,
172
- volume: +v.positionAmt,
173
- free_volume: +v.positionAmt,
174
- position_price: +v.entryPrice,
175
- closable_price: +v.entryPrice + +v.unrealizedProfit / +v.positionAmt,
176
- floating_profit: +v.unrealizedProfit,
177
- valuation: +v.positionAmt * (+v.entryPrice + +v.unrealizedProfit / +v.positionAmt),
178
- };
179
- });
180
- return positions;
181
- }, { auto_refresh_interval: 1000 });
182
- (0, data_account_1.addAccountMarket)(terminal, { account_id: UNIFIED_ACCOUNT_ID, market_id: 'BINANCE/UNIFIED' });
183
- }
184
- {
185
- // spot account info
186
- (0, data_account_1.provideAccountInfoService)(terminal, SPOT_ACCOUNT_ID, async () => {
187
- const spotAccountResult = await (0, private_api_1.getSpotAccountInfo)(credential, { omitZeroBalances: true });
188
- if ((0, client_1.isApiError)(spotAccountResult)) {
189
- throw new Error(spotAccountResult.msg);
190
- }
191
- const usdtAssets = spotAccountResult.balances.find((v) => v.asset === 'USDT');
192
- const positions = spotAccountResult.balances
193
- .filter((balance) => balance.asset !== 'USDT')
194
- .map((balance) => {
195
- const volume = +balance.free + +balance.locked;
196
- if (!volume) {
197
- return undefined;
198
- }
199
- const position = {
200
- position_id: `spot/${balance.asset}`,
201
- datasource_id: 'BINANCE',
202
- product_id: (0, utils_1.encodePath)('spot', `${balance.asset}USDT`),
203
- direction: 'LONG',
204
- volume,
205
- free_volume: +balance.free,
206
- position_price: 0,
207
- closable_price: 0,
208
- floating_profit: 0,
209
- valuation: 0,
210
- };
211
- return position;
212
- })
213
- .filter((position) => Boolean(position));
214
- return positions;
215
- }, {
216
- auto_refresh_interval: 5000,
217
- });
218
- (0, data_account_1.addAccountMarket)(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'BINANCE/SPOT' });
219
- }
220
- // transfer
221
- {
222
- // spot -> unified
223
- const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;
224
- (0, transfer_1.addAccountTransferAddress)({
225
- terminal,
226
- account_id: SPOT_ACCOUNT_ID,
227
- network_id: SPOT_UNIFIED_NETWORK_ID,
228
- currency: 'USDT',
229
- address: `unified`,
230
- onApply: {
231
- INIT: async (order) => {
232
- const transferResult = await (0, private_api_1.postAssetTransfer)(credential, {
233
- type: 'MAIN_PORTFOLIO_MARGIN',
234
- asset: 'USDT',
235
- amount: order.current_amount,
236
- });
237
- if ((0, client_1.isApiError)(transferResult)) {
238
- return { state: 'INIT', message: transferResult.msg };
239
- }
240
- return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
241
- },
242
- },
243
- onEval: async (order) => {
244
- return { state: 'COMPLETE', received_amount: order.current_amount };
245
- },
246
- });
247
- // unified -> spot
248
- (0, transfer_1.addAccountTransferAddress)({
249
- terminal,
250
- account_id: UNIFIED_ACCOUNT_ID,
251
- network_id: SPOT_UNIFIED_NETWORK_ID,
252
- currency: 'USDT',
253
- address: `spot`,
254
- onApply: {
255
- INIT: async (order) => {
256
- const transferResult = await (0, private_api_1.postAssetTransfer)(credential, {
257
- type: 'PORTFOLIO_MARGIN_MAIN',
258
- asset: 'USDT',
259
- amount: order.current_amount,
260
- });
261
- if ((0, client_1.isApiError)(transferResult)) {
262
- return { state: 'INIT', message: transferResult.msg };
263
- }
264
- return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
265
- },
266
- },
267
- onEval: async (order) => {
268
- return { state: 'COMPLETE', received_amount: order.current_amount };
269
- },
270
- });
271
- const subAccountsResult = await (0, private_api_1.getSubAccountList)(credential);
272
- const isMain = !(0, client_1.isApiError)(subAccountsResult);
273
- // main -> sub
274
- // TODO...
275
- // blockchain
276
- if (isMain) {
277
- const depositAddressResult = await (0, private_api_1.getDepositAddress)(credential, { coin: 'USDT', network: 'TRX' });
278
- (0, transfer_1.addAccountTransferAddress)({
279
- terminal,
280
- account_id: SPOT_ACCOUNT_ID,
281
- network_id: 'TRC20',
282
- currency: 'USDT',
283
- address: depositAddressResult.address,
284
- onApply: {
285
- INIT: async (order) => {
286
- const transferResult = await (0, private_api_1.postWithdraw)(credential, {
287
- coin: 'USDT',
288
- network: 'TRX',
289
- address: order.current_rx_address,
290
- amount: order.current_amount,
291
- });
292
- if ((0, client_1.isApiError)(transferResult)) {
293
- return { state: 'ERROR', message: transferResult.msg };
294
- }
295
- const wdId = transferResult.id;
296
- return { state: 'PENDING', context: wdId };
297
- },
298
- PENDING: async (order) => {
299
- const wdId = order.current_tx_context;
300
- const withdrawResult = await (0, private_api_1.getWithdrawHistory)(credential, { coin: 'USDT' });
301
- const record = withdrawResult === null || withdrawResult === void 0 ? void 0 : withdrawResult.find((v) => v.id === wdId);
302
- const txId = record === null || record === void 0 ? void 0 : record.txId;
303
- if (!txId) {
304
- return { state: 'PENDING', context: wdId };
305
- }
306
- return { state: 'COMPLETE', transaction_id: txId };
307
- },
308
- },
309
- onEval: async (order) => {
310
- var _a;
311
- const checkResult = await (0, private_api_1.getDepositHistory)(credential, {
312
- coin: 'USDT',
313
- txId: order.current_transaction_id,
314
- });
315
- if (((_a = checkResult === null || checkResult === void 0 ? void 0 : checkResult[0]) === null || _a === void 0 ? void 0 : _a.status) !== 1) {
316
- return { state: 'PENDING' };
317
- }
318
- const received_amount = +checkResult[0].amount;
319
- return { state: 'COMPLETE', received_amount };
320
- },
321
- });
322
- }
323
- }
324
- // order related
325
- {
326
- (0, data_order_1.providePendingOrdersService)(terminal, UNIFIED_ACCOUNT_ID, async () => {
327
- const openOrders = await (0, private_api_1.getUnifiedUmOpenOrders)(credential);
328
- return openOrders.map((order) => {
329
- var _a;
330
- const order_direction = (_a = mapBinanceSideToYuantsDirection(order.side, order.positionSide)) !== null && _a !== void 0 ? _a : 'OPEN_LONG';
331
- return {
332
- order_id: `${order.orderId}`,
333
- account_id: UNIFIED_ACCOUNT_ID,
334
- product_id: (0, utils_1.encodePath)('usdt-future', order.symbol),
335
- order_type: mapBinanceOrderTypeToYuants(order.type),
336
- order_direction,
337
- volume: +order.origQty,
338
- traded_volume: +order.executedQty,
339
- price: order.price === undefined ? undefined : +order.price,
340
- submit_at: order.time,
341
- updated_at: new Date(order.updateTime).toISOString(),
342
- order_status: order.status,
343
- };
344
- });
345
- }, { auto_refresh_interval: 1000 });
346
- terminal.server.provideService('SubmitOrder', {
347
- required: ['account_id'],
348
- properties: {
349
- account_id: { const: UNIFIED_ACCOUNT_ID },
350
- },
351
- }, async (msg) => {
352
- console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', msg.req);
353
- const order = msg.req;
354
- const [instType, symbol] = (0, utils_1.decodePath)(order.product_id);
355
- if (instType === 'usdt-future') {
356
- const params = {
357
- symbol,
358
- side: mapOrderDirectionToSide(order.order_direction),
359
- positionSide: mapOrderDirectionToPosSide(order.order_direction),
360
- type: mapOrderTypeToOrdType(order.order_type),
361
- timeInForce: order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined,
362
- quantity: order.volume,
363
- price: order.price,
364
- newClientOrderId: deriveClientOrderId(order),
365
- };
366
- console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));
367
- const orderResult = await (0, private_api_1.postUmOrder)(credential, params);
368
- if ((0, client_1.isApiError)(orderResult)) {
369
- return { res: { code: orderResult.code, message: orderResult.msg } };
370
- }
371
- return { res: { code: 0, message: 'OK', order_id: orderResult.orderId } };
372
- }
373
- return { res: { code: 400, message: `unsupported type: ${instType}` } };
374
- });
375
- }
376
- {
377
- terminal.server.provideService('CancelOrder', {
378
- required: ['account_id', 'order_id', 'product_id'],
379
- properties: {
380
- account_id: { const: UNIFIED_ACCOUNT_ID },
381
- },
382
- }, async (msg) => {
383
- const order = msg.req;
384
- if (!order.order_id) {
385
- return { res: { code: 400, message: 'order_id is required' } };
386
- }
387
- const [instType, symbol] = (0, utils_1.decodePath)(order.product_id);
388
- if (instType !== 'usdt-future') {
389
- return { res: { code: 400, message: `unsupported type: ${instType}` } };
390
- }
391
- const cancelResult = await (0, private_api_1.deleteUmOrder)(credential, {
392
- symbol,
393
- orderId: order.order_id,
394
- });
395
- if ((0, client_1.isApiError)(cancelResult)) {
396
- return { res: { code: cancelResult.code, message: cancelResult.msg } };
397
- }
398
- return { res: { code: 0, message: 'OK' } };
399
- });
400
- }
401
- })();
402
- }
2
+ // import { Terminal } from '@yuants/protocol';
3
+ // import { addAccountTransferAddress } from '@yuants/transfer';
4
+ // import { getDefaultCredential, isApiError } from './api/client';
5
+ // import {
6
+ // getDepositAddress,
7
+ // getDepositHistory,
8
+ // getSpotAccountInfo,
9
+ // getSubAccountList,
10
+ // getWithdrawHistory,
11
+ // postAssetTransfer,
12
+ // postWithdraw,
13
+ // } from './api/private-api';
14
+ // const terminal = Terminal.fromNodeEnv();
15
+ // const isPublicOnly = process.env.PUBLIC_ONLY === 'true';
16
+ // // provideTicks(terminal, 'binance', (product_id) => {
17
+ // // const [instType, symbol] = decodePath(product_id);
18
+ // // if (instType === 'usdt-future') {
19
+ // // return combineLatest([mapSymbolToFuturePremiumIndex$, mapSymbolToFutureBookTicker$]).pipe(
20
+ // // combineLatestWith(defer(() => getOpenInterest(symbol))),
21
+ // // map(([[mapSymbolToFuturePremiumIndex, mapSymbolToFutureBookTicker], openInterestVolume]): ITick => {
22
+ // // const premiumIndex = mapSymbolToFuturePremiumIndex.get(symbol);
23
+ // // const bookTicker = mapSymbolToFutureBookTicker.get(symbol);
24
+ // // if (!premiumIndex) {
25
+ // // throw new Error(`Premium Index Not Found: ${symbol}`);
26
+ // // }
27
+ // // if (!bookTicker) {
28
+ // // throw new Error(`Book Ticker Not Found: ${symbol}`);
29
+ // // }
30
+ // // return {
31
+ // // datasource_id: 'binance',
32
+ // // product_id,
33
+ // // updated_at: Date.now(),
34
+ // // price: +premiumIndex.markPrice,
35
+ // // ask: +bookTicker.askPrice,
36
+ // // bid: +bookTicker.bidPrice,
37
+ // // interest_rate_for_long: -+premiumIndex.lastFundingRate,
38
+ // // interest_rate_for_short: +premiumIndex.lastFundingRate,
39
+ // // settlement_scheduled_at: premiumIndex.nextFundingTime,
40
+ // // open_interest: openInterestVolume,
41
+ // // };
42
+ // // }),
43
+ // // );
44
+ // // }
45
+ // // return EMPTY;
46
+ // // });
47
+ // if (isPublicOnly) {
48
+ // console.info('PUBLIC_ONLY=1, skip Binance legacy services');
49
+ // } else {
50
+ // const credential = getDefaultCredential();
51
+ // (async () => {
52
+ // const spotAccountInfo = await getSpotAccountInfo(credential);
53
+ // if (isApiError(spotAccountInfo)) {
54
+ // throw new Error(spotAccountInfo.msg);
55
+ // }
56
+ // const uid = spotAccountInfo.uid;
57
+ // const SPOT_ACCOUNT_ID = `binance/${uid}/spot/usdt`;
58
+ // const UNIFIED_ACCOUNT_ID = `binance/${uid}/unified/usdt`;
59
+ // // transfer
60
+ // {
61
+ // // spot -> unified
62
+ // const SPOT_UNIFIED_NETWORK_ID = `binance/${uid}/spot/unified`;
63
+ // addAccountTransferAddress({
64
+ // terminal,
65
+ // account_id: SPOT_ACCOUNT_ID,
66
+ // network_id: SPOT_UNIFIED_NETWORK_ID,
67
+ // currency: 'USDT',
68
+ // address: `unified`,
69
+ // onApply: {
70
+ // INIT: async (order) => {
71
+ // const transferResult = await postAssetTransfer(credential, {
72
+ // type: 'MAIN_PORTFOLIO_MARGIN',
73
+ // asset: 'USDT',
74
+ // amount: order.current_amount!,
75
+ // });
76
+ // if (isApiError(transferResult)) {
77
+ // return { state: 'INIT', message: transferResult.msg };
78
+ // }
79
+ // return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
80
+ // },
81
+ // },
82
+ // onEval: async (order) => {
83
+ // return { state: 'COMPLETE', received_amount: order.current_amount };
84
+ // },
85
+ // });
86
+ // // unified -> spot
87
+ // addAccountTransferAddress({
88
+ // terminal,
89
+ // account_id: UNIFIED_ACCOUNT_ID,
90
+ // network_id: SPOT_UNIFIED_NETWORK_ID,
91
+ // currency: 'USDT',
92
+ // address: `spot`,
93
+ // onApply: {
94
+ // INIT: async (order) => {
95
+ // const transferResult = await postAssetTransfer(credential, {
96
+ // type: 'PORTFOLIO_MARGIN_MAIN',
97
+ // asset: 'USDT',
98
+ // amount: order.current_amount!,
99
+ // });
100
+ // if (isApiError(transferResult)) {
101
+ // return { state: 'INIT', message: transferResult.msg };
102
+ // }
103
+ // return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
104
+ // },
105
+ // },
106
+ // onEval: async (order) => {
107
+ // return { state: 'COMPLETE', received_amount: order.current_amount };
108
+ // },
109
+ // });
110
+ // const subAccountsResult = await getSubAccountList(credential);
111
+ // const isMain = !isApiError(subAccountsResult);
112
+ // // main -> sub
113
+ // // TODO...
114
+ // // blockchain
115
+ // if (isMain) {
116
+ // const depositAddressResult = await getDepositAddress(credential, { coin: 'USDT', network: 'TRX' });
117
+ // addAccountTransferAddress({
118
+ // terminal,
119
+ // account_id: SPOT_ACCOUNT_ID,
120
+ // network_id: 'TRC20',
121
+ // currency: 'USDT',
122
+ // address: depositAddressResult.address,
123
+ // onApply: {
124
+ // INIT: async (order) => {
125
+ // const transferResult = await postWithdraw(credential, {
126
+ // coin: 'USDT',
127
+ // network: 'TRX',
128
+ // address: order.current_rx_address!,
129
+ // amount: order.current_amount!,
130
+ // });
131
+ // if (isApiError(transferResult)) {
132
+ // return { state: 'ERROR', message: transferResult.msg };
133
+ // }
134
+ // const wdId = transferResult.id;
135
+ // return { state: 'PENDING', context: wdId };
136
+ // },
137
+ // PENDING: async (order) => {
138
+ // const wdId = order.current_tx_context;
139
+ // const withdrawResult = await getWithdrawHistory(credential, { coin: 'USDT' });
140
+ // const record = withdrawResult?.find((v) => v.id === wdId);
141
+ // const txId = record?.txId;
142
+ // if (!txId) {
143
+ // return { state: 'PENDING', context: wdId };
144
+ // }
145
+ // return { state: 'COMPLETE', transaction_id: txId };
146
+ // },
147
+ // },
148
+ // onEval: async (order) => {
149
+ // const checkResult = await getDepositHistory(credential, {
150
+ // coin: 'USDT',
151
+ // txId: order.current_transaction_id,
152
+ // });
153
+ // if (checkResult?.[0]?.status !== 1) {
154
+ // return { state: 'PENDING' };
155
+ // }
156
+ // const received_amount = +checkResult[0].amount;
157
+ // return { state: 'COMPLETE', received_amount };
158
+ // },
159
+ // });
160
+ // }
161
+ // }
162
+ // })();
163
+ // }
403
164
  //# sourceMappingURL=legacy_index.js.map