@yuants/vendor-binance 0.7.8 → 0.8.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.
- package/dist/api/client.js +70 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/private-api.js +162 -0
- package/dist/api/private-api.js.map +1 -0
- package/dist/api/public-api.js +52 -0
- package/dist/api/public-api.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interest_rate.js +2 -2
- package/dist/interest_rate.js.map +1 -1
- package/dist/legacy_index.js +270 -237
- package/dist/legacy_index.js.map +1 -1
- package/dist/product.js +2 -2
- package/dist/product.js.map +1 -1
- package/dist/quote.js +4 -4
- package/dist/quote.js.map +1 -1
- package/dist/services/account-actions-with-credential.js +34 -0
- package/dist/services/account-actions-with-credential.js.map +1 -0
- package/dist/services/accounts/profile.js +22 -0
- package/dist/services/accounts/profile.js.map +1 -0
- package/dist/services/accounts/spot.js +44 -0
- package/dist/services/accounts/spot.js.map +1 -0
- package/dist/services/accounts/unified.js +56 -0
- package/dist/services/accounts/unified.js.map +1 -0
- package/dist/services/order-actions-with-credential.js +19 -0
- package/dist/services/order-actions-with-credential.js.map +1 -0
- package/dist/services/orders/cancelOrder.js +39 -0
- package/dist/services/orders/cancelOrder.js.map +1 -0
- package/dist/services/orders/listOrders.js +49 -0
- package/dist/services/orders/listOrders.js.map +1 -0
- package/dist/services/orders/order-utils.js +118 -0
- package/dist/services/orders/order-utils.js.map +1 -0
- package/dist/services/orders/submitOrder.js +70 -0
- package/dist/services/orders/submitOrder.js.map +1 -0
- package/lib/api/client.d.ts +16 -0
- package/lib/api/client.d.ts.map +1 -0
- package/lib/api/client.js +80 -0
- package/lib/api/client.js.map +1 -0
- package/lib/api/private-api.d.ts +477 -0
- package/lib/api/private-api.d.ts.map +1 -0
- package/lib/api/private-api.js +183 -0
- package/lib/api/private-api.js.map +1 -0
- package/lib/api/public-api.d.ts +150 -0
- package/lib/api/public-api.d.ts.map +1 -0
- package/lib/api/public-api.js +61 -0
- package/lib/api/public-api.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/interest_rate.js +2 -2
- package/lib/interest_rate.js.map +1 -1
- package/lib/legacy_index.js +270 -237
- package/lib/legacy_index.js.map +1 -1
- package/lib/product.js +2 -2
- package/lib/product.js.map +1 -1
- package/lib/quote.js +4 -4
- package/lib/quote.js.map +1 -1
- package/lib/services/account-actions-with-credential.d.ts +2 -0
- package/lib/services/account-actions-with-credential.d.ts.map +1 -0
- package/lib/services/account-actions-with-credential.js +36 -0
- package/lib/services/account-actions-with-credential.js.map +1 -0
- package/lib/services/accounts/profile.d.ts +7 -0
- package/lib/services/accounts/profile.d.ts.map +1 -0
- package/lib/services/accounts/profile.js +26 -0
- package/lib/services/accounts/profile.js.map +1 -0
- package/lib/services/accounts/spot.d.ts +4 -0
- package/lib/services/accounts/spot.d.ts.map +1 -0
- package/lib/services/accounts/spot.js +48 -0
- package/lib/services/accounts/spot.js.map +1 -0
- package/lib/services/accounts/unified.d.ts +4 -0
- package/lib/services/accounts/unified.d.ts.map +1 -0
- package/lib/services/accounts/unified.js +60 -0
- package/lib/services/accounts/unified.js.map +1 -0
- package/lib/services/order-actions-with-credential.d.ts +2 -0
- package/lib/services/order-actions-with-credential.d.ts.map +1 -0
- package/lib/services/order-actions-with-credential.js +21 -0
- package/lib/services/order-actions-with-credential.js.map +1 -0
- package/lib/services/orders/cancelOrder.d.ts +4 -0
- package/lib/services/orders/cancelOrder.d.ts.map +1 -0
- package/lib/services/orders/cancelOrder.js +43 -0
- package/lib/services/orders/cancelOrder.js.map +1 -0
- package/lib/services/orders/listOrders.d.ts +4 -0
- package/lib/services/orders/listOrders.d.ts.map +1 -0
- package/lib/services/orders/listOrders.js +53 -0
- package/lib/services/orders/listOrders.js.map +1 -0
- package/lib/services/orders/order-utils.d.ts +12 -0
- package/lib/services/orders/order-utils.d.ts.map +1 -0
- package/lib/services/orders/order-utils.js +131 -0
- package/lib/services/orders/order-utils.js.map +1 -0
- package/lib/services/orders/submitOrder.d.ts +4 -0
- package/lib/services/orders/submitOrder.d.ts.map +1 -0
- package/lib/services/orders/submitOrder.js +74 -0
- package/lib/services/orders/submitOrder.js.map +1 -0
- package/package.json +11 -19
- package/temp/package-deps.json +32 -19
- package/dist/api.js +0 -248
- package/dist/api.js.map +0 -1
- package/lib/api.d.ts +0 -576
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -256
- package/lib/api.js.map +0 -1
package/lib/legacy_index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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:
|
|
241
|
+
network_id: SPOT_UNIFIED_NETWORK_ID,
|
|
264
242
|
currency: 'USDT',
|
|
265
|
-
address:
|
|
243
|
+
address: `unified`,
|
|
266
244
|
onApply: {
|
|
267
245
|
INIT: async (order) => {
|
|
268
|
-
const transferResult = await
|
|
269
|
-
|
|
270
|
-
|
|
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,
|
|
275
|
-
return { state: '
|
|
251
|
+
if ((0, client_1.isApiError)(transferResult)) {
|
|
252
|
+
return { state: 'INIT', message: transferResult.msg };
|
|
276
253
|
}
|
|
277
|
-
|
|
278
|
-
return { state: 'PENDING', context: wdId };
|
|
254
|
+
return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
|
|
279
255
|
},
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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:
|
|
278
|
+
return { state: 'COMPLETE', transaction_id: '' + transferResult.tranId };
|
|
289
279
|
},
|
|
290
280
|
},
|
|
291
281
|
onEval: async (order) => {
|
|
292
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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'
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return { res: { code: 0, message: 'OK' } };
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
})();
|
|
414
|
+
}
|
|
415
|
+
})();
|
|
416
|
+
}
|
|
384
417
|
//# sourceMappingURL=legacy_index.js.map
|