@yuants/vendor-huobi 0.11.41 → 0.13.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/account-info.js +235 -0
- package/dist/account-info.js.map +1 -0
- package/dist/api/private-api.js +251 -0
- package/dist/api/private-api.js.map +1 -0
- package/dist/api/public-api.js +145 -0
- package/dist/api/public-api.js.map +1 -0
- package/dist/api.js +0 -279
- package/dist/api.js.map +1 -1
- package/dist/index.js +28 -524
- package/dist/index.js.map +1 -1
- package/dist/interest_rate.js +2 -2
- package/dist/interest_rate.js.map +1 -1
- package/dist/order-actions-with-credentials.js +15 -0
- package/dist/order-actions-with-credentials.js.map +1 -0
- package/dist/order-actions.js +17 -0
- package/dist/order-actions.js.map +1 -0
- package/dist/orders/submitOrder.js +93 -0
- package/dist/orders/submitOrder.js.map +1 -0
- package/dist/product.js +4 -4
- package/dist/product.js.map +1 -1
- package/dist/quote.js +5 -5
- package/dist/quote.js.map +1 -1
- package/dist/transfer.js +248 -0
- package/dist/transfer.js.map +1 -0
- package/dist/uid.js +22 -0
- package/dist/uid.js.map +1 -0
- package/lib/account-info.d.ts +35 -0
- package/lib/account-info.d.ts.map +1 -0
- package/lib/account-info.js +243 -0
- package/lib/account-info.js.map +1 -0
- package/lib/api/private-api.d.ts +474 -0
- package/lib/api/private-api.d.ts.map +1 -0
- package/lib/api/private-api.js +280 -0
- package/lib/api/private-api.js.map +1 -0
- package/lib/api/public-api.d.ts +308 -0
- package/lib/api/public-api.d.ts.map +1 -0
- package/lib/api/public-api.js +158 -0
- package/lib/api/public-api.js.map +1 -0
- package/lib/api.d.ts +2 -621
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +0 -279
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +26 -522
- package/lib/index.js.map +1 -1
- package/lib/interest_rate.js +2 -2
- package/lib/interest_rate.js.map +1 -1
- package/lib/order-actions-with-credentials.d.ts +2 -0
- package/lib/order-actions-with-credentials.d.ts.map +1 -0
- package/lib/order-actions-with-credentials.js +17 -0
- package/lib/order-actions-with-credentials.js.map +1 -0
- package/lib/order-actions.d.ts +7 -0
- package/lib/order-actions.d.ts.map +1 -0
- package/lib/order-actions.js +21 -0
- package/lib/order-actions.js.map +1 -0
- package/lib/orders/submitOrder.d.ts +6 -0
- package/lib/orders/submitOrder.d.ts.map +1 -0
- package/lib/orders/submitOrder.js +97 -0
- package/lib/orders/submitOrder.js.map +1 -0
- package/lib/product.js +4 -4
- package/lib/product.js.map +1 -1
- package/lib/quote.js +5 -5
- package/lib/quote.js.map +1 -1
- package/lib/transfer.d.ts +19 -0
- package/lib/transfer.d.ts.map +1 -0
- package/lib/transfer.js +255 -0
- package/lib/transfer.js.map +1 -0
- package/lib/uid.d.ts +13 -0
- package/lib/uid.d.ts.map +1 -0
- package/lib/uid.js +26 -0
- package/lib/uid.js.map +1 -0
- package/package.json +3 -3
- package/temp/package-deps.json +18 -11
- package/dist/logger.js +0 -91
- package/dist/logger.js.map +0 -1
- package/lib/logger.d.ts +0 -21
- package/lib/logger.d.ts.map +0 -1
- package/lib/logger.js +0 -98
- package/lib/logger.js.map +0 -1
package/lib/transfer.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSubAccountTransfers = exports.setupSpotSwapTransfer = exports.setupSpotSuperMarginTransfer = exports.setupTrc20WithdrawalAddresses = void 0;
|
|
4
|
+
const transfer_1 = require("@yuants/transfer");
|
|
5
|
+
const private_api_1 = require("./api/private-api");
|
|
6
|
+
/**
|
|
7
|
+
* 设置 TRC20 USDT 提现地址
|
|
8
|
+
*/
|
|
9
|
+
const setupTrc20WithdrawalAddresses = async (terminal, spotAccountId, credential, isMainAccount) => {
|
|
10
|
+
if (!isMainAccount) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const res = await (0, private_api_1.getSpotAccountDepositAddresses)(credential, { currency: 'usdt' });
|
|
14
|
+
const addresses = res.data.filter((v) => v.chain === 'trc20usdt').map((v) => v.address);
|
|
15
|
+
for (const address of addresses) {
|
|
16
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
17
|
+
terminal,
|
|
18
|
+
account_id: spotAccountId,
|
|
19
|
+
currency: 'USDT',
|
|
20
|
+
address: address,
|
|
21
|
+
network_id: 'TRC20',
|
|
22
|
+
onApply: {
|
|
23
|
+
INIT: async (order) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const res0 = await (0, private_api_1.getV2ReferenceCurrencies)(credential, { currency: 'usdt' });
|
|
26
|
+
const fee = (_b = (_a = res0.data
|
|
27
|
+
.find((v) => v.currency === 'usdt')) === null || _a === void 0 ? void 0 : _a.chains.find((v) => v.chain === 'trc20usdt')) === null || _b === void 0 ? void 0 : _b.transactFeeWithdraw;
|
|
28
|
+
if (!fee) {
|
|
29
|
+
return { state: 'ERROR', message: 'MISSING FEE' };
|
|
30
|
+
}
|
|
31
|
+
const res = await (0, private_api_1.postWithdraw)(credential, {
|
|
32
|
+
address: order.current_rx_address,
|
|
33
|
+
amount: '' + (order.expected_amount - +fee),
|
|
34
|
+
currency: 'usdt',
|
|
35
|
+
fee: fee,
|
|
36
|
+
chain: 'trc20usdt',
|
|
37
|
+
});
|
|
38
|
+
if (res.status != 'ok') {
|
|
39
|
+
return { state: 'INIT', message: `${res.status}` };
|
|
40
|
+
}
|
|
41
|
+
return { state: 'PENDING', context: `${res.data}` };
|
|
42
|
+
},
|
|
43
|
+
PENDING: async (order) => {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!order.current_tx_context) {
|
|
46
|
+
return { state: 'ERROR', message: 'MISSING CONTEXT' };
|
|
47
|
+
}
|
|
48
|
+
const wdId = +order.current_tx_context;
|
|
49
|
+
const res = await (0, private_api_1.getDepositWithdrawHistory)(credential, {
|
|
50
|
+
currency: 'usdt',
|
|
51
|
+
type: 'withdraw',
|
|
52
|
+
from: `${wdId}`,
|
|
53
|
+
});
|
|
54
|
+
const txId = (_a = res.data.find((v) => v.id === wdId)) === null || _a === void 0 ? void 0 : _a['tx-hash'];
|
|
55
|
+
if (!txId) {
|
|
56
|
+
return { state: 'PENDING', context: `${wdId}` };
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
state: 'COMPLETE',
|
|
60
|
+
transaction_id: txId,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
onEval: async (order) => {
|
|
65
|
+
const res = await (0, private_api_1.getDepositWithdrawHistory)(credential, {
|
|
66
|
+
currency: 'usdt',
|
|
67
|
+
type: 'deposit',
|
|
68
|
+
direct: 'next',
|
|
69
|
+
});
|
|
70
|
+
const theItem = res.data.find((v) => v['tx-hash'] === order.current_transaction_id && v.state === 'safe');
|
|
71
|
+
if (!theItem) {
|
|
72
|
+
return { state: 'PENDING' };
|
|
73
|
+
}
|
|
74
|
+
return { received_amount: +theItem.amount, state: 'COMPLETE' };
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.setupTrc20WithdrawalAddresses = setupTrc20WithdrawalAddresses;
|
|
80
|
+
/**
|
|
81
|
+
* 设置 SPOT 和 SUPER_MARGIN 账户之间的内部转账
|
|
82
|
+
*/
|
|
83
|
+
const setupSpotSuperMarginTransfer = (terminal, spotAccountId, superMarginAccountId, credential, huobiUid) => {
|
|
84
|
+
const networkId = `Huobi/${huobiUid}/SPOT-SUPER_MARGIN`;
|
|
85
|
+
// SPOT -> SUPER_MARGIN
|
|
86
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
87
|
+
terminal,
|
|
88
|
+
account_id: spotAccountId,
|
|
89
|
+
currency: 'USDT',
|
|
90
|
+
network_id: networkId,
|
|
91
|
+
address: 'SPOT',
|
|
92
|
+
onApply: {
|
|
93
|
+
INIT: async (order) => {
|
|
94
|
+
const transferInResult = await (0, private_api_1.postSuperMarginAccountTransferIn)(credential, {
|
|
95
|
+
currency: 'usdt',
|
|
96
|
+
amount: '' + (order.current_amount || order.expected_amount),
|
|
97
|
+
});
|
|
98
|
+
if (transferInResult.status !== 'ok') {
|
|
99
|
+
return { state: 'INIT' };
|
|
100
|
+
}
|
|
101
|
+
return { state: 'COMPLETE' };
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
onEval: async (order) => {
|
|
105
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
// SUPER_MARGIN -> SPOT
|
|
109
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
110
|
+
terminal,
|
|
111
|
+
account_id: superMarginAccountId,
|
|
112
|
+
currency: 'USDT',
|
|
113
|
+
network_id: networkId,
|
|
114
|
+
address: 'SUPER_MARGIN',
|
|
115
|
+
onApply: {
|
|
116
|
+
INIT: async (order) => {
|
|
117
|
+
const transferOutResult = await (0, private_api_1.postSuperMarginAccountTransferOut)(credential, {
|
|
118
|
+
currency: 'usdt',
|
|
119
|
+
amount: '' + (order.current_amount || order.expected_amount),
|
|
120
|
+
});
|
|
121
|
+
if (transferOutResult.status !== 'ok') {
|
|
122
|
+
return { state: 'INIT' };
|
|
123
|
+
}
|
|
124
|
+
return { state: 'COMPLETE' };
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
onEval: async (order) => {
|
|
128
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
exports.setupSpotSuperMarginTransfer = setupSpotSuperMarginTransfer;
|
|
133
|
+
/**
|
|
134
|
+
* 设置 SPOT 和 SWAP 账户之间的内部转账
|
|
135
|
+
*/
|
|
136
|
+
const setupSpotSwapTransfer = (terminal, spotAccountId, swapAccountId, credential, huobiUid) => {
|
|
137
|
+
const networkId = `Huobi/${huobiUid}/SPOT-SWAP`;
|
|
138
|
+
// SPOT -> SWAP
|
|
139
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
140
|
+
terminal,
|
|
141
|
+
account_id: spotAccountId,
|
|
142
|
+
currency: 'USDT',
|
|
143
|
+
network_id: networkId,
|
|
144
|
+
address: 'SPOT',
|
|
145
|
+
onApply: {
|
|
146
|
+
INIT: async (order) => {
|
|
147
|
+
const transferResult = await (0, private_api_1.postSpotAccountTransfer)(credential, {
|
|
148
|
+
from: 'spot',
|
|
149
|
+
to: 'linear-swap',
|
|
150
|
+
currency: 'usdt',
|
|
151
|
+
amount: order.current_amount || order.expected_amount,
|
|
152
|
+
'margin-account': 'USDT',
|
|
153
|
+
});
|
|
154
|
+
if (!transferResult.success) {
|
|
155
|
+
return { state: 'INIT' };
|
|
156
|
+
}
|
|
157
|
+
return { state: 'COMPLETE' };
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
onEval: async (order) => {
|
|
161
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
// SWAP -> SPOT
|
|
165
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
166
|
+
terminal,
|
|
167
|
+
account_id: swapAccountId,
|
|
168
|
+
currency: 'USDT',
|
|
169
|
+
network_id: networkId,
|
|
170
|
+
address: 'SWAP',
|
|
171
|
+
onApply: {
|
|
172
|
+
INIT: async (order) => {
|
|
173
|
+
const transferResult = await (0, private_api_1.postSpotAccountTransfer)(credential, {
|
|
174
|
+
from: 'linear-swap',
|
|
175
|
+
to: 'spot',
|
|
176
|
+
currency: 'usdt',
|
|
177
|
+
amount: order.current_amount || order.expected_amount,
|
|
178
|
+
'margin-account': 'USDT',
|
|
179
|
+
});
|
|
180
|
+
if (!transferResult.success) {
|
|
181
|
+
return { state: 'INIT' };
|
|
182
|
+
}
|
|
183
|
+
return { state: 'COMPLETE' };
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
onEval: async (order) => {
|
|
187
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
exports.setupSpotSwapTransfer = setupSpotSwapTransfer;
|
|
192
|
+
/**
|
|
193
|
+
* 设置子账户转账
|
|
194
|
+
*/
|
|
195
|
+
const setupSubAccountTransfers = (terminal, spotAccountId, credential, huobiUid, subAccounts, isMainAccount) => {
|
|
196
|
+
if (!isMainAccount) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
for (const subAccount of subAccounts) {
|
|
200
|
+
const spotSubAccountId = `huobi/${subAccount.uid}/spot/usdt`;
|
|
201
|
+
const subAccountNetworkId = `Huobi/${huobiUid}/SubAccount/${subAccount.uid}`;
|
|
202
|
+
// 主账户 -> 子账户
|
|
203
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
204
|
+
terminal,
|
|
205
|
+
account_id: spotAccountId,
|
|
206
|
+
currency: 'USDT',
|
|
207
|
+
network_id: subAccountNetworkId,
|
|
208
|
+
address: '#main',
|
|
209
|
+
onApply: {
|
|
210
|
+
INIT: async (order) => {
|
|
211
|
+
const transferResult = await (0, private_api_1.postSubUserTransfer)(credential, {
|
|
212
|
+
'sub-uid': +order.current_rx_address,
|
|
213
|
+
currency: 'usdt',
|
|
214
|
+
amount: order.current_amount || order.expected_amount,
|
|
215
|
+
type: 'master-transfer-out',
|
|
216
|
+
});
|
|
217
|
+
if (transferResult.status !== 'ok') {
|
|
218
|
+
return { state: 'INIT' };
|
|
219
|
+
}
|
|
220
|
+
return { state: 'COMPLETE' };
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
onEval: async (order) => {
|
|
224
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
// 子账户 -> 主账户
|
|
228
|
+
(0, transfer_1.addAccountTransferAddress)({
|
|
229
|
+
terminal,
|
|
230
|
+
account_id: spotSubAccountId,
|
|
231
|
+
currency: 'USDT',
|
|
232
|
+
network_id: subAccountNetworkId,
|
|
233
|
+
address: `${subAccount.uid}`,
|
|
234
|
+
onApply: {
|
|
235
|
+
INIT: async (order) => {
|
|
236
|
+
const transferResult = await (0, private_api_1.postSubUserTransfer)(credential, {
|
|
237
|
+
'sub-uid': +order.current_tx_address,
|
|
238
|
+
currency: 'usdt',
|
|
239
|
+
amount: order.current_amount || order.expected_amount,
|
|
240
|
+
type: 'master-transfer-in',
|
|
241
|
+
});
|
|
242
|
+
if (transferResult.status !== 'ok') {
|
|
243
|
+
return { state: 'INIT' };
|
|
244
|
+
}
|
|
245
|
+
return { state: 'COMPLETE' };
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
onEval: async (order) => {
|
|
249
|
+
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
exports.setupSubAccountTransfers = setupSubAccountTransfers;
|
|
255
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":";;;AACA,+CAA6D;AAC7D,mDAU2B;AAE3B;;GAEG;AACI,MAAM,6BAA6B,GAAG,KAAK,EAChD,QAAkB,EAClB,aAAqB,EACrB,UAAuB,EACvB,aAAsB,EACtB,EAAE;IACF,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO;KACR;IAED,MAAM,GAAG,GAAG,MAAM,IAAA,4CAA8B,EAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACnF,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC,GAAG,CAAC,C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AAE,KAAK,EAAE,EAAE;gBACtB,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;YAC/F,CAAC;SACF,CAAC,CAAC;QAEH,aAAa;QACb,IAAA,oCAAyB,EAAC;YACxB,QAAQ;YACR,UAAU,EAAE,gBAAgB;YAC5B,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,mBAAmB;YAC/B,OAAO,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,OAAO,EAAE;gBACP,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACpB,MAAM,cAAc,GAAG,MAAM,IAAA,iCAAmB,EAAC,UAAU,EAAE;wBAC3D,SAAS,EAAE,CAAC,KAAK,CAAC,kBAAmB;wBACrC,QAAQ,EAAE,MAAM;wBAChB,MAAM,EAAE,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,eAAe;wBACrD,IAAI,EAAE,oBAAoB;qBAC3B,CAAC,CAAC;oBACH,IAAI,cAAc,CAAC,MAAM,KAAK,IAAI,EAAE;wBAClC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;qBAC1B;oBACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;gBAC/B,CAAC;aACF;YACD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACtB,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;YAC/F,CAAC;SACF,CAAC,CAAC;KACJ;AACH,CAAC,CAAC;AApEW,QAAA,wBAAwB,4BAoEnC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport {\n getDepositWithdrawHistory,\n getSpotAccountDepositAddresses,\n getV2ReferenceCurrencies,\n ICredential,\n postSpotAccountTransfer,\n postSubUserTransfer,\n postSuperMarginAccountTransferIn,\n postSuperMarginAccountTransferOut,\n postWithdraw,\n} from './api/private-api';\n\n/**\n * 设置 TRC20 USDT 提现地址\n */\nexport const setupTrc20WithdrawalAddresses = async (\n terminal: Terminal,\n spotAccountId: string,\n credential: ICredential,\n isMainAccount: boolean,\n) => {\n if (!isMainAccount) {\n return;\n }\n\n const res = await getSpotAccountDepositAddresses(credential, { currency: 'usdt' });\n const addresses = res.data.filter((v) => v.chain === 'trc20usdt').map((v) => v.address);\n\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: spotAccountId,\n currency: 'USDT',\n address: address,\n network_id: 'TRC20',\n onApply: {\n INIT: async (order) => {\n const res0 = await getV2ReferenceCurrencies(credential, { currency: 'usdt' });\n const fee = res0.data\n .find((v) => v.currency === 'usdt')\n ?.chains.find((v) => v.chain === 'trc20usdt')?.transactFeeWithdraw;\n if (!fee) {\n return { state: 'ERROR', message: 'MISSING FEE' };\n }\n const res = await postWithdraw(credential, {\n address: order.current_rx_address!,\n amount: '' + (order.expected_amount - +fee),\n currency: 'usdt',\n fee: fee,\n chain: 'trc20usdt',\n });\n if (res.status != 'ok') {\n return { state: 'INIT', message: `${res.status}` };\n }\n return { state: 'PENDING', context: `${res.data}` };\n },\n PENDING: async (order) => {\n if (!order.current_tx_context) {\n return { state: 'ERROR', message: 'MISSING CONTEXT' };\n }\n const wdId = +order.current_tx_context;\n const res = await getDepositWithdrawHistory(credential, {\n currency: 'usdt',\n type: 'withdraw',\n from: `${wdId}`,\n });\n const txId = res.data.find((v) => v.id === wdId)?.['tx-hash'];\n if (!txId) {\n return { state: 'PENDING', context: `${wdId}` };\n }\n return {\n state: 'COMPLETE',\n transaction_id: txId,\n };\n },\n },\n onEval: async (order) => {\n const res = await getDepositWithdrawHistory(credential, {\n currency: 'usdt',\n type: 'deposit',\n direct: 'next',\n });\n\n const theItem = res.data.find(\n (v) => v['tx-hash'] === order.current_transaction_id && v.state === 'safe',\n );\n if (!theItem) {\n return { state: 'PENDING' };\n }\n return { received_amount: +theItem.amount, state: 'COMPLETE' };\n },\n });\n }\n};\n\n/**\n * 设置 SPOT 和 SUPER_MARGIN 账户之间的内部转账\n */\nexport const setupSpotSuperMarginTransfer = (\n terminal: Terminal,\n spotAccountId: string,\n superMarginAccountId: string,\n credential: ICredential,\n huobiUid: number,\n) => {\n const networkId = `Huobi/${huobiUid}/SPOT-SUPER_MARGIN`;\n\n // SPOT -> SUPER_MARGIN\n addAccountTransferAddress({\n terminal,\n account_id: spotAccountId,\n currency: 'USDT',\n network_id: networkId,\n address: 'SPOT',\n onApply: {\n INIT: async (order) => {\n const transferInResult = await postSuperMarginAccountTransferIn(credential, {\n currency: 'usdt',\n amount: '' + (order.current_amount || order.expected_amount),\n });\n if (transferInResult.status !== 'ok') {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n\n // SUPER_MARGIN -> SPOT\n addAccountTransferAddress({\n terminal,\n account_id: superMarginAccountId,\n currency: 'USDT',\n network_id: networkId,\n address: 'SUPER_MARGIN',\n onApply: {\n INIT: async (order) => {\n const transferOutResult = await postSuperMarginAccountTransferOut(credential, {\n currency: 'usdt',\n amount: '' + (order.current_amount || order.expected_amount),\n });\n if (transferOutResult.status !== 'ok') {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n};\n\n/**\n * 设置 SPOT 和 SWAP 账户之间的内部转账\n */\nexport const setupSpotSwapTransfer = (\n terminal: Terminal,\n spotAccountId: string,\n swapAccountId: string,\n credential: ICredential,\n huobiUid: number,\n) => {\n const networkId = `Huobi/${huobiUid}/SPOT-SWAP`;\n\n // SPOT -> SWAP\n addAccountTransferAddress({\n terminal,\n account_id: spotAccountId,\n currency: 'USDT',\n network_id: networkId,\n address: 'SPOT',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postSpotAccountTransfer(credential, {\n from: 'spot',\n to: 'linear-swap',\n currency: 'usdt',\n amount: order.current_amount || order.expected_amount,\n 'margin-account': 'USDT',\n });\n if (!transferResult.success) {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n\n // SWAP -> SPOT\n addAccountTransferAddress({\n terminal,\n account_id: swapAccountId,\n currency: 'USDT',\n network_id: networkId,\n address: 'SWAP',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postSpotAccountTransfer(credential, {\n from: 'linear-swap',\n to: 'spot',\n currency: 'usdt',\n amount: order.current_amount || order.expected_amount,\n 'margin-account': 'USDT',\n });\n if (!transferResult.success) {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n};\n\n/**\n * 设置子账户转账\n */\nexport const setupSubAccountTransfers = (\n terminal: Terminal,\n spotAccountId: string,\n credential: ICredential,\n huobiUid: number,\n subAccounts: any[],\n isMainAccount: boolean,\n) => {\n if (!isMainAccount) {\n return;\n }\n\n for (const subAccount of subAccounts) {\n const spotSubAccountId = `huobi/${subAccount.uid}/spot/usdt`;\n const subAccountNetworkId = `Huobi/${huobiUid}/SubAccount/${subAccount.uid}`;\n\n // 主账户 -> 子账户\n addAccountTransferAddress({\n terminal,\n account_id: spotAccountId,\n currency: 'USDT',\n network_id: subAccountNetworkId,\n address: '#main',\n onApply: {\n INIT: async (order) => {\n const transferResult = await postSubUserTransfer(credential, {\n 'sub-uid': +order.current_rx_address!,\n currency: 'usdt',\n amount: order.current_amount || order.expected_amount,\n type: 'master-transfer-out',\n });\n if (transferResult.status !== 'ok') {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n\n // 子账户 -> 主账户\n addAccountTransferAddress({\n terminal,\n account_id: spotSubAccountId,\n currency: 'USDT',\n network_id: subAccountNetworkId,\n address: `${subAccount.uid}`,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postSubUserTransfer(credential, {\n 'sub-uid': +order.current_tx_address!,\n currency: 'usdt',\n amount: order.current_amount || order.expected_amount,\n type: 'master-transfer-in',\n });\n if (transferResult.status !== 'ok') {\n return { state: 'INIT' };\n }\n return { state: 'COMPLETE' };\n },\n },\n onEval: async (order) => {\n return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };\n },\n });\n }\n};\n"]}
|
package/lib/uid.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const uidCache: import("@yuants/cache").ICache<{
|
|
2
|
+
data: number;
|
|
3
|
+
code: number;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const superMarginAccountUidCache: import("@yuants/cache").ICache<number>;
|
|
6
|
+
export declare const spotAccountUidCache: import("@yuants/cache").ICache<number>;
|
|
7
|
+
export declare const getAccountIds: (key: string) => Promise<{
|
|
8
|
+
main: string;
|
|
9
|
+
spot: string;
|
|
10
|
+
superMargin: string;
|
|
11
|
+
swap: string;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=uid.d.ts.map
|
package/lib/uid.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../src/uid.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ;;;EAAgD,CAAC;AAItE,eAAO,MAAM,0BAA0B,wCAEtC,CAAC;AAEF,eAAO,MAAM,mBAAmB,wCAE/B,CAAC;AAEF,eAAO,MAAM,aAAa,QAAe,MAAM;;;;;EAe9C,CAAC"}
|
package/lib/uid.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAccountIds = exports.spotAccountUidCache = exports.superMarginAccountUidCache = exports.uidCache = void 0;
|
|
4
|
+
const cache_1 = require("@yuants/cache");
|
|
5
|
+
const private_api_1 = require("./api/private-api");
|
|
6
|
+
exports.uidCache = (0, cache_1.createCache)((key) => (0, private_api_1.getUid)(JSON.parse(key)));
|
|
7
|
+
const huobiAccounts = (0, cache_1.createCache)((key) => (0, private_api_1.getAccount)(JSON.parse(key)));
|
|
8
|
+
exports.superMarginAccountUidCache = (0, cache_1.createCache)((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'super-margin')) === null || _a === void 0 ? void 0 : _a.id; }));
|
|
9
|
+
exports.spotAccountUidCache = (0, cache_1.createCache)((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'spot')) === null || _a === void 0 ? void 0 : _a.id; }));
|
|
10
|
+
const getAccountIds = async (key) => {
|
|
11
|
+
const uid = await exports.uidCache.query(key);
|
|
12
|
+
if (!uid)
|
|
13
|
+
throw new Error('Failed to get UID');
|
|
14
|
+
const account_id = `huobi/${uid}`;
|
|
15
|
+
const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;
|
|
16
|
+
const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;
|
|
17
|
+
const SWAP_ACCOUNT_ID = `${account_id}/swap`;
|
|
18
|
+
return {
|
|
19
|
+
main: account_id,
|
|
20
|
+
spot: SPOT_ACCOUNT_ID,
|
|
21
|
+
superMargin: SUPER_MARGIN_ACCOUNT_ID,
|
|
22
|
+
swap: SWAP_ACCOUNT_ID,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.getAccountIds = getAccountIds;
|
|
26
|
+
//# sourceMappingURL=uid.js.map
|
package/lib/uid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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AAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,SAAS,GAAG,EAAE,CAAC;IAClC,MAAM,eAAe,GAAG,GAAG,UAAU,YAAY,CAAC;IAClD,MAAM,uBAAuB,GAAG,GAAG,UAAU,eAAe,CAAC;IAC7D,MAAM,eAAe,GAAG,GAAG,UAAU,OAAO,CAAC;IAE7C,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE,eAAe;KACtB,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,aAAa,iBAexB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccount, getUid } from './api/private-api';\n\nexport const uidCache = createCache((key) => getUid(JSON.parse(key)));\n\nconst huobiAccounts = createCache((key) => getAccount(JSON.parse(key)));\n\nexport const superMarginAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'super-margin')?.id),\n);\n\nexport const spotAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'spot')?.id),\n);\n\nexport const getAccountIds = async (key: string) => {\n const uid = await uidCache.query(key);\n if (!uid) throw new Error('Failed to get UID');\n\n const account_id = `huobi/${uid}`;\n const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;\n const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;\n const SWAP_ACCOUNT_ID = `${account_id}/swap`;\n\n return {\n main: account_id,\n spot: SPOT_ACCOUNT_ID,\n superMargin: SUPER_MARGIN_ACCOUNT_ID,\n swap: SWAP_ACCOUNT_ID,\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-huobi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"bin": "lib/cli.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@yuants/protocol": "0.50.4",
|
|
13
|
-
"@yuants/data-account": "0.6.
|
|
14
|
-
"@yuants/data-order": "0.
|
|
13
|
+
"@yuants/data-account": "0.6.15",
|
|
14
|
+
"@yuants/data-order": "0.4.0",
|
|
15
15
|
"@yuants/transfer": "0.2.33",
|
|
16
16
|
"@yuants/utils": "0.11.0",
|
|
17
17
|
"@yuants/cache": "0.3.0",
|
package/temp/package-deps.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/vendor-huobi/CHANGELOG.json": "
|
|
3
|
-
"apps/vendor-huobi/CHANGELOG.md": "
|
|
2
|
+
"apps/vendor-huobi/CHANGELOG.json": "f10455469861b5ffb8b4550dde8638ce54abf1ac",
|
|
3
|
+
"apps/vendor-huobi/CHANGELOG.md": "2b0bf5539ec413f4c7095ad855fcfb68f703b8db",
|
|
4
4
|
"apps/vendor-huobi/README.md": "d7bf0149513114eab5500a6b5c9e7cba10565572",
|
|
5
5
|
"apps/vendor-huobi/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
6
6
|
"apps/vendor-huobi/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-huobi/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-huobi/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
9
|
"apps/vendor-huobi/etc/vendor-huobi.api.md": "dc8cbf2a044a227b30a4ee9701b0c97328244724",
|
|
10
|
-
"apps/vendor-huobi/package.json": "
|
|
11
|
-
"apps/vendor-huobi/src/
|
|
10
|
+
"apps/vendor-huobi/package.json": "206b61d2980a11a3e5dca9ea84b57e62e446476a",
|
|
11
|
+
"apps/vendor-huobi/src/account-info.ts": "78d866fab248c78f6aaf5623f21e9013debab25c",
|
|
12
|
+
"apps/vendor-huobi/src/api.ts": "061c8644a01c6e0b4964e4be6f4588e16abd8869",
|
|
13
|
+
"apps/vendor-huobi/src/api/private-api.ts": "e093cd61bb5e69eaf2ba42a7393fddf10d221552",
|
|
14
|
+
"apps/vendor-huobi/src/api/public-api.ts": "03a1468bea318d5fcb8c0c9d45666ffbee4346f0",
|
|
12
15
|
"apps/vendor-huobi/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
|
|
13
|
-
"apps/vendor-huobi/src/index.ts": "
|
|
14
|
-
"apps/vendor-huobi/src/interest_rate.ts": "
|
|
15
|
-
"apps/vendor-huobi/src/
|
|
16
|
-
"apps/vendor-huobi/src/
|
|
17
|
-
"apps/vendor-huobi/src/
|
|
16
|
+
"apps/vendor-huobi/src/index.ts": "9733795740b8df5e1d9fe96a25257d080c35b983",
|
|
17
|
+
"apps/vendor-huobi/src/interest_rate.ts": "2ba38d2c97b91f1b2f9979647dab5d516f6bfa4f",
|
|
18
|
+
"apps/vendor-huobi/src/order-actions-with-credentials.ts": "32322c28a4c52b936c98ee51d09905178815cb5e",
|
|
19
|
+
"apps/vendor-huobi/src/order-actions.ts": "93a5d294f6674ba433d892d6be2ae6aa5d059420",
|
|
20
|
+
"apps/vendor-huobi/src/orders/submitOrder.ts": "37d6886dc81bde92b20f31031a9df2a1ef9963c4",
|
|
21
|
+
"apps/vendor-huobi/src/product.ts": "973c81048708f265ce86fad37d06e4a4044a11b9",
|
|
22
|
+
"apps/vendor-huobi/src/quote.ts": "52922569315ce9f72aef8ed5d65157c8800e943d",
|
|
23
|
+
"apps/vendor-huobi/src/transfer.ts": "0da0957b0acf820bbc26bfd74776305167f28d35",
|
|
24
|
+
"apps/vendor-huobi/src/uid.ts": "9f9a4fd99dcfa47eda14fbcf5fe5b03aecc19c9c",
|
|
18
25
|
"apps/vendor-huobi/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
19
26
|
"apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "9cfeff02d2b4838478ed6afd825f89806d4c2b57",
|
|
20
27
|
"libraries/protocol/temp/package-deps.json": "35bc77333a1c85db1cd130579963e8cefa00f56c",
|
|
21
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
22
|
-
"libraries/data-order/temp/package-deps.json": "
|
|
28
|
+
"libraries/data-account/temp/package-deps.json": "bc6176ac72e51f5deb7f123807852a4305935bcd",
|
|
29
|
+
"libraries/data-order/temp/package-deps.json": "afb45e88841011b7abd71901cda1bda450f36dc5",
|
|
23
30
|
"libraries/transfer/temp/package-deps.json": "708a4caf79d042cad56a39f0b00d399bca04af40",
|
|
24
31
|
"libraries/utils/temp/package-deps.json": "c58f1ca8f498315d9a0219ca8c498299a41d297b",
|
|
25
32
|
"libraries/cache/temp/package-deps.json": "49789a92426969daa31f0c956bb56bd783929765",
|
package/dist/logger.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import cluster from 'cluster';
|
|
2
|
-
/**
|
|
3
|
-
* 集群模式下的日志管理器
|
|
4
|
-
* 在worker进程中将日志发送到主进程,在主进程中直接使用console
|
|
5
|
-
*/
|
|
6
|
-
class ClusterLogger {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.isWorker = !cluster.isPrimary;
|
|
9
|
-
}
|
|
10
|
-
sendToMaster(level, message, ...args) {
|
|
11
|
-
if (this.isWorker && process.send) {
|
|
12
|
-
const formattedMessage = args.length > 0
|
|
13
|
-
? `${message} ${args
|
|
14
|
-
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
15
|
-
.join(' ')}`
|
|
16
|
-
: message;
|
|
17
|
-
process.send({
|
|
18
|
-
type: 'log',
|
|
19
|
-
level,
|
|
20
|
-
message: `[PID:${process.pid}] ${formattedMessage}`,
|
|
21
|
-
pid: process.pid,
|
|
22
|
-
label: process.env.WORKER_LABEL || 'unknown',
|
|
23
|
-
timestamp: Date.now(),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// 在主进程中直接输出
|
|
28
|
-
const formattedMessage = args.length > 0
|
|
29
|
-
? `${message} ${args
|
|
30
|
-
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
31
|
-
.join(' ')}`
|
|
32
|
-
: message;
|
|
33
|
-
const logMessage = `[PID:${process.pid}] ${formattedMessage}`;
|
|
34
|
-
// 控制台输出
|
|
35
|
-
switch (level) {
|
|
36
|
-
case 'error':
|
|
37
|
-
console.error(logMessage);
|
|
38
|
-
break;
|
|
39
|
-
case 'warn':
|
|
40
|
-
console.warn(logMessage);
|
|
41
|
-
break;
|
|
42
|
-
case 'debug':
|
|
43
|
-
console.debug(logMessage);
|
|
44
|
-
break;
|
|
45
|
-
default:
|
|
46
|
-
console.log(logMessage);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
info(message, ...args) {
|
|
51
|
-
this.sendToMaster('info', message, ...args);
|
|
52
|
-
}
|
|
53
|
-
warn(message, ...args) {
|
|
54
|
-
this.sendToMaster('warn', message, ...args);
|
|
55
|
-
}
|
|
56
|
-
error(message, ...args) {
|
|
57
|
-
this.sendToMaster('error', message, ...args);
|
|
58
|
-
}
|
|
59
|
-
debug(message, ...args) {
|
|
60
|
-
this.sendToMaster('debug', message, ...args);
|
|
61
|
-
}
|
|
62
|
-
log(message, ...args) {
|
|
63
|
-
this.info(message, ...args);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// 默认配置的logger实例
|
|
67
|
-
export const logger = new ClusterLogger();
|
|
68
|
-
// 猛踩油门
|
|
69
|
-
export const overrideConsole = () => {
|
|
70
|
-
if (!cluster.isPrimary) {
|
|
71
|
-
const originalConsole = {
|
|
72
|
-
log: console.log,
|
|
73
|
-
info: console.info,
|
|
74
|
-
warn: console.warn,
|
|
75
|
-
error: console.error,
|
|
76
|
-
};
|
|
77
|
-
console.log = (...args) => logger.info(args.join(' '));
|
|
78
|
-
console.info = (...args) => logger.info(args.join(' '));
|
|
79
|
-
console.warn = (...args) => logger.warn(args.join(' '));
|
|
80
|
-
console.error = (...args) => logger.error(args.join(' '));
|
|
81
|
-
// 提供恢复方法
|
|
82
|
-
return () => {
|
|
83
|
-
console.log = originalConsole.log;
|
|
84
|
-
console.info = originalConsole.info;
|
|
85
|
-
console.warn = originalConsole.warn;
|
|
86
|
-
console.error = originalConsole.error;
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return () => { }; // 主进程中返回空函数
|
|
90
|
-
};
|
|
91
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B;;;GAGG;AACH,MAAM,aAAa;IAAnB;QACU,aAAQ,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;IAkExC,CAAC;IAhES,YAAY,CAAC,KAAe,EAAE,OAAe,EAAE,GAAG,IAAW;QACnE,IAAI,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE;YACjC,MAAM,gBAAgB,GACpB,IAAI,CAAC,MAAM,GAAG,CAAC;gBACb,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI;qBACf,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBAC3E,IAAI,CAAC,GAAG,CAAC,EAAE;gBAChB,CAAC,CAAC,OAAO,CAAC;YAEd,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,KAAK;gBACX,KAAK;gBACL,OAAO,EAAE,QAAQ,OAAO,CAAC,G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AAG,IAAW,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAEjE,SAAS;QACT,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC;YAClC,OAAO,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;YACpC,OAAO,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;YACpC,OAAO,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC;QACxC,CAAC,CAAC;KACH;IACD,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,YAAY;AAC/B,CAAC,CAAC","sourcesContent":["import cluster from 'cluster';\nimport { formatTime } from '@yuants/utils';\n\n/**\n * 日志级别\n */\nexport type LogLevel = 'info' | 'warn' | 'error' | 'debug';\n\n/**\n * 集群模式下的日志管理器\n * 在worker进程中将日志发送到主进程,在主进程中直接使用console\n */\nclass ClusterLogger {\n private isWorker = !cluster.isPrimary;\n\n private sendToMaster(level: LogLevel, message: string, ...args: any[]) {\n if (this.isWorker && process.send) {\n const formattedMessage =\n args.length > 0\n ? `${message} ${args\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))\n .join(' ')}`\n : message;\n\n process.send({\n type: 'log',\n level,\n message: `[PID:${process.pid}] ${formattedMessage}`,\n pid: process.pid,\n label: process.env.WORKER_LABEL || 'unknown',\n timestamp: Date.now(),\n });\n } else {\n // 在主进程中直接输出\n const formattedMessage =\n args.length > 0\n ? `${message} ${args\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))\n .join(' ')}`\n : message;\n\n const logMessage = `[PID:${process.pid}] ${formattedMessage}`;\n\n // 控制台输出\n switch (level) {\n case 'error':\n console.error(logMessage);\n break;\n case 'warn':\n console.warn(logMessage);\n break;\n case 'debug':\n console.debug(logMessage);\n break;\n default:\n console.log(logMessage);\n }\n }\n }\n\n info(message: string, ...args: any[]) {\n this.sendToMaster('info', message, ...args);\n }\n\n warn(message: string, ...args: any[]) {\n this.sendToMaster('warn', message, ...args);\n }\n\n error(message: string, ...args: any[]) {\n this.sendToMaster('error', message, ...args);\n }\n\n debug(message: string, ...args: any[]) {\n this.sendToMaster('debug', message, ...args);\n }\n\n log(message: string, ...args: any[]) {\n this.info(message, ...args);\n }\n}\n\n// 默认配置的logger实例\nexport const logger = new ClusterLogger();\n\n// 猛踩油门\nexport const overrideConsole = () => {\n if (!cluster.isPrimary) {\n const originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n };\n\n console.log = (...args: any[]) => logger.info(args.join(' '));\n console.info = (...args: any[]) => logger.info(args.join(' '));\n console.warn = (...args: any[]) => logger.warn(args.join(' '));\n console.error = (...args: any[]) => logger.error(args.join(' '));\n\n // 提供恢复方法\n return () => {\n console.log = originalConsole.log;\n console.info = originalConsole.info;\n console.warn = originalConsole.warn;\n console.error = originalConsole.error;\n };\n }\n return () => {}; // 主进程中返回空函数\n};\n"]}
|
package/lib/logger.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 日志级别
|
|
3
|
-
*/
|
|
4
|
-
export declare type LogLevel = 'info' | 'warn' | 'error' | 'debug';
|
|
5
|
-
/**
|
|
6
|
-
* 集群模式下的日志管理器
|
|
7
|
-
* 在worker进程中将日志发送到主进程,在主进程中直接使用console
|
|
8
|
-
*/
|
|
9
|
-
declare class ClusterLogger {
|
|
10
|
-
private isWorker;
|
|
11
|
-
private sendToMaster;
|
|
12
|
-
info(message: string, ...args: any[]): void;
|
|
13
|
-
warn(message: string, ...args: any[]): void;
|
|
14
|
-
error(message: string, ...args: any[]): void;
|
|
15
|
-
debug(message: string, ...args: any[]): void;
|
|
16
|
-
log(message: string, ...args: any[]): void;
|
|
17
|
-
}
|
|
18
|
-
export declare const logger: ClusterLogger;
|
|
19
|
-
export declare const overrideConsole: () => () => void;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/lib/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,oBAAY,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D;;;GAGG;AACH,cAAM,aAAa;IACjB,OAAO,CAAC,QAAQ,CAAsB;IAEtC,OAAO,CAAC,YAAY;IA6CpB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAIpC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAIpC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAIrC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAIrC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;CAGpC;AAGD,eAAO,MAAM,MAAM,eAAsB,CAAC;AAG1C,eAAO,MAAM,eAAe,kBAuB3B,CAAC"}
|
package/lib/logger.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.overrideConsole = exports.logger = void 0;
|
|
7
|
-
const cluster_1 = __importDefault(require("cluster"));
|
|
8
|
-
/**
|
|
9
|
-
* 集群模式下的日志管理器
|
|
10
|
-
* 在worker进程中将日志发送到主进程,在主进程中直接使用console
|
|
11
|
-
*/
|
|
12
|
-
class ClusterLogger {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.isWorker = !cluster_1.default.isPrimary;
|
|
15
|
-
}
|
|
16
|
-
sendToMaster(level, message, ...args) {
|
|
17
|
-
if (this.isWorker && process.send) {
|
|
18
|
-
const formattedMessage = args.length > 0
|
|
19
|
-
? `${message} ${args
|
|
20
|
-
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
21
|
-
.join(' ')}`
|
|
22
|
-
: message;
|
|
23
|
-
process.send({
|
|
24
|
-
type: 'log',
|
|
25
|
-
level,
|
|
26
|
-
message: `[PID:${process.pid}] ${formattedMessage}`,
|
|
27
|
-
pid: process.pid,
|
|
28
|
-
label: process.env.WORKER_LABEL || 'unknown',
|
|
29
|
-
timestamp: Date.now(),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// 在主进程中直接输出
|
|
34
|
-
const formattedMessage = args.length > 0
|
|
35
|
-
? `${message} ${args
|
|
36
|
-
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
37
|
-
.join(' ')}`
|
|
38
|
-
: message;
|
|
39
|
-
const logMessage = `[PID:${process.pid}] ${formattedMessage}`;
|
|
40
|
-
// 控制台输出
|
|
41
|
-
switch (level) {
|
|
42
|
-
case 'error':
|
|
43
|
-
console.error(logMessage);
|
|
44
|
-
break;
|
|
45
|
-
case 'warn':
|
|
46
|
-
console.warn(logMessage);
|
|
47
|
-
break;
|
|
48
|
-
case 'debug':
|
|
49
|
-
console.debug(logMessage);
|
|
50
|
-
break;
|
|
51
|
-
default:
|
|
52
|
-
console.log(logMessage);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
info(message, ...args) {
|
|
57
|
-
this.sendToMaster('info', message, ...args);
|
|
58
|
-
}
|
|
59
|
-
warn(message, ...args) {
|
|
60
|
-
this.sendToMaster('warn', message, ...args);
|
|
61
|
-
}
|
|
62
|
-
error(message, ...args) {
|
|
63
|
-
this.sendToMaster('error', message, ...args);
|
|
64
|
-
}
|
|
65
|
-
debug(message, ...args) {
|
|
66
|
-
this.sendToMaster('debug', message, ...args);
|
|
67
|
-
}
|
|
68
|
-
log(message, ...args) {
|
|
69
|
-
this.info(message, ...args);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// 默认配置的logger实例
|
|
73
|
-
exports.logger = new ClusterLogger();
|
|
74
|
-
// 猛踩油门
|
|
75
|
-
const overrideConsole = () => {
|
|
76
|
-
if (!cluster_1.default.isPrimary) {
|
|
77
|
-
const originalConsole = {
|
|
78
|
-
log: console.log,
|
|
79
|
-
info: console.info,
|
|
80
|
-
warn: console.warn,
|
|
81
|
-
error: console.error,
|
|
82
|
-
};
|
|
83
|
-
console.log = (...args) => exports.logger.info(args.join(' '));
|
|
84
|
-
console.info = (...args) => exports.logger.info(args.join(' '));
|
|
85
|
-
console.warn = (...args) => exports.logger.warn(args.join(' '));
|
|
86
|
-
console.error = (...args) => exports.logger.error(args.join(' '));
|
|
87
|
-
// 提供恢复方法
|
|
88
|
-
return () => {
|
|
89
|
-
console.log = originalConsole.log;
|
|
90
|
-
console.info = originalConsole.info;
|
|
91
|
-
console.warn = originalConsole.warn;
|
|
92
|
-
console.error = originalConsole.error;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return () => { }; // 主进程中返回空函数
|
|
96
|
-
};
|
|
97
|
-
exports.overrideConsole = overrideConsole;
|
|
98
|
-
//# sourceMappingURL=logger.js.map
|