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