@yuants/vendor-binance 0.7.7 → 0.8.0

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