@yuants/vendor-huobi 0.14.6 → 0.15.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/__archived/account-info.js +45 -0
- package/dist/__archived/account-info.js.map +1 -0
- package/dist/__archived/api.js +51 -0
- package/dist/__archived/api.js.map +1 -0
- package/dist/__archived/transfer.js +285 -0
- package/dist/__archived/transfer.js.map +1 -0
- package/dist/index.js +3 -51
- package/dist/index.js.map +1 -1
- package/dist/{accounts → services/accounts}/spot.js +7 -4
- package/dist/services/accounts/spot.js.map +1 -0
- package/dist/{accounts → services/accounts}/super-margin.js +2 -2
- package/dist/services/accounts/super-margin.js.map +1 -0
- package/dist/services/accounts/swap.js +37 -0
- package/dist/services/accounts/swap.js.map +1 -0
- package/dist/services/exchange.js +75 -0
- package/dist/services/exchange.js.map +1 -0
- package/dist/services/market-data/interest_rate.js +63 -0
- package/dist/services/market-data/interest_rate.js.map +1 -0
- package/dist/{quote.js → services/market-data/quote.js} +9 -9
- package/dist/services/market-data/quote.js.map +1 -0
- package/dist/services/orders/listOrders.js +44 -0
- package/dist/services/orders/listOrders.js.map +1 -0
- package/dist/{orders → services/orders}/submitOrder.js +9 -8
- package/dist/services/orders/submitOrder.js.map +1 -0
- package/dist/{product.js → services/product.js} +16 -12
- package/dist/services/product.js.map +1 -0
- package/dist/{uid.js → services/uid.js} +1 -15
- package/dist/services/uid.js.map +1 -0
- package/lib/__archived/account-info.d.ts +1 -0
- package/lib/__archived/account-info.d.ts.map +1 -0
- package/lib/__archived/account-info.js +45 -0
- package/lib/__archived/account-info.js.map +1 -0
- package/lib/__archived/api.d.ts +1 -0
- package/lib/__archived/api.d.ts.map +1 -0
- package/lib/__archived/api.js +51 -0
- package/lib/__archived/api.js.map +1 -0
- package/lib/__archived/transfer.d.ts +1 -0
- package/lib/__archived/transfer.d.ts.map +1 -0
- package/lib/__archived/transfer.js +285 -0
- package/lib/__archived/transfer.js.map +1 -0
- package/lib/index.d.ts +3 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -51
- package/lib/index.js.map +1 -1
- package/lib/{accounts → services/accounts}/spot.d.ts +1 -1
- package/lib/services/accounts/spot.d.ts.map +1 -0
- package/lib/{accounts → services/accounts}/spot.js +7 -4
- package/lib/services/accounts/spot.js.map +1 -0
- package/lib/{accounts → services/accounts}/super-margin.d.ts +1 -1
- package/lib/services/accounts/super-margin.d.ts.map +1 -0
- package/lib/{accounts → services/accounts}/super-margin.js +2 -2
- package/lib/services/accounts/super-margin.js.map +1 -0
- package/lib/services/accounts/swap.d.ts +4 -0
- package/lib/services/accounts/swap.d.ts.map +1 -0
- package/lib/services/accounts/swap.js +41 -0
- package/lib/services/accounts/swap.js.map +1 -0
- package/lib/services/exchange.d.ts +2 -0
- package/lib/services/exchange.d.ts.map +1 -0
- package/lib/services/exchange.js +77 -0
- package/lib/services/exchange.js.map +1 -0
- package/lib/services/market-data/interest_rate.d.ts.map +1 -0
- package/lib/{interest_rate.js → services/market-data/interest_rate.js} +34 -30
- package/lib/services/market-data/interest_rate.js.map +1 -0
- package/lib/services/market-data/quote.d.ts.map +1 -0
- package/lib/{quote.js → services/market-data/quote.js} +9 -9
- package/lib/services/market-data/quote.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 +48 -0
- package/lib/services/orders/listOrders.js.map +1 -0
- package/lib/{orders → services/orders}/submitOrder.d.ts +1 -1
- package/lib/services/orders/submitOrder.d.ts.map +1 -0
- package/lib/{orders → services/orders}/submitOrder.js +7 -6
- package/lib/services/orders/submitOrder.js.map +1 -0
- package/lib/services/product.d.ts +4 -0
- package/lib/services/product.d.ts.map +1 -0
- package/lib/{product.js → services/product.js} +18 -13
- package/lib/services/product.js.map +1 -0
- package/lib/{uid.d.ts → services/uid.d.ts} +0 -5
- package/lib/services/uid.d.ts.map +1 -0
- package/lib/{uid.js → services/uid.js} +2 -17
- package/lib/services/uid.js.map +1 -0
- package/package.json +2 -1
- package/temp/package-deps.json +19 -21
- package/dist/account-actions-with-credentials.js +0 -30
- package/dist/account-actions-with-credentials.js.map +0 -1
- package/dist/account-info.js +0 -75
- package/dist/account-info.js.map +0 -1
- package/dist/accounts/list.js +0 -8
- package/dist/accounts/list.js.map +0 -1
- package/dist/accounts/spot.js.map +0 -1
- package/dist/accounts/super-margin.js.map +0 -1
- package/dist/accounts/swap.js +0 -80
- package/dist/accounts/swap.js.map +0 -1
- package/dist/api.js +0 -34
- package/dist/api.js.map +0 -1
- package/dist/cli.js +0 -3
- package/dist/cli.js.map +0 -1
- package/dist/interest_rate.js +0 -59
- package/dist/interest_rate.js.map +0 -1
- package/dist/order-actions-with-credentials.js +0 -15
- package/dist/order-actions-with-credentials.js.map +0 -1
- package/dist/order-actions.js +0 -17
- package/dist/order-actions.js.map +0 -1
- package/dist/orders/submitOrder.js.map +0 -1
- package/dist/product.js.map +0 -1
- package/dist/quote.js.map +0 -1
- package/dist/transfer.js +0 -248
- package/dist/transfer.js.map +0 -1
- package/dist/uid.js.map +0 -1
- package/lib/account-actions-with-credentials.d.ts +0 -2
- package/lib/account-actions-with-credentials.d.ts.map +0 -1
- package/lib/account-actions-with-credentials.js +0 -32
- package/lib/account-actions-with-credentials.js.map +0 -1
- package/lib/account-info.d.ts +0 -35
- package/lib/account-info.d.ts.map +0 -1
- package/lib/account-info.js +0 -83
- package/lib/account-info.js.map +0 -1
- package/lib/accounts/list.d.ts +0 -4
- package/lib/accounts/list.d.ts.map +0 -1
- package/lib/accounts/list.js +0 -12
- package/lib/accounts/list.js.map +0 -1
- package/lib/accounts/spot.d.ts.map +0 -1
- package/lib/accounts/spot.js.map +0 -1
- package/lib/accounts/super-margin.d.ts.map +0 -1
- package/lib/accounts/super-margin.js.map +0 -1
- package/lib/accounts/swap.d.ts +0 -4
- package/lib/accounts/swap.d.ts.map +0 -1
- package/lib/accounts/swap.js +0 -84
- package/lib/accounts/swap.js.map +0 -1
- package/lib/api.d.ts +0 -15
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -41
- package/lib/api.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/interest_rate.d.ts.map +0 -1
- package/lib/interest_rate.js.map +0 -1
- package/lib/order-actions-with-credentials.d.ts +0 -2
- package/lib/order-actions-with-credentials.d.ts.map +0 -1
- package/lib/order-actions-with-credentials.js +0 -17
- package/lib/order-actions-with-credentials.js.map +0 -1
- package/lib/order-actions.d.ts +0 -7
- package/lib/order-actions.d.ts.map +0 -1
- package/lib/order-actions.js +0 -21
- package/lib/order-actions.js.map +0 -1
- package/lib/orders/submitOrder.d.ts.map +0 -1
- package/lib/orders/submitOrder.js.map +0 -1
- package/lib/product.d.ts +0 -3
- package/lib/product.d.ts.map +0 -1
- package/lib/product.js.map +0 -1
- package/lib/quote.d.ts.map +0 -1
- package/lib/quote.js.map +0 -1
- package/lib/transfer.d.ts +0 -19
- package/lib/transfer.d.ts.map +0 -1
- package/lib/transfer.js +0 -255
- package/lib/transfer.js.map +0 -1
- package/lib/uid.d.ts.map +0 -1
- package/lib/uid.js.map +0 -1
- /package/lib/{interest_rate.d.ts → services/market-data/interest_rate.d.ts} +0 -0
- /package/lib/{quote.d.ts → services/market-data/quote.d.ts} +0 -0
package/dist/transfer.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { addAccountTransferAddress } from '@yuants/transfer';
|
|
2
|
-
import { getDepositWithdrawHistory, getSpotAccountDepositAddresses, getV2ReferenceCurrencies, postSpotAccountTransfer, postSubUserTransfer, postSuperMarginAccountTransferIn, postSuperMarginAccountTransferOut, postWithdraw, } from './api/private-api';
|
|
3
|
-
/**
|
|
4
|
-
* 设置 TRC20 USDT 提现地址
|
|
5
|
-
*/
|
|
6
|
-
export const setupTrc20WithdrawalAddresses = async (terminal, spotAccountId, credential, isMainAccount) => {
|
|
7
|
-
if (!isMainAccount) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const res = await getSpotAccountDepositAddresses(credential, { currency: 'usdt' });
|
|
11
|
-
const addresses = res.data.filter((v) => v.chain === 'trc20usdt').map((v) => v.address);
|
|
12
|
-
for (const address of addresses) {
|
|
13
|
-
addAccountTransferAddress({
|
|
14
|
-
terminal,
|
|
15
|
-
account_id: spotAccountId,
|
|
16
|
-
currency: 'USDT',
|
|
17
|
-
address: address,
|
|
18
|
-
network_id: 'TRC20',
|
|
19
|
-
onApply: {
|
|
20
|
-
INIT: async (order) => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const res0 = await getV2ReferenceCurrencies(credential, { currency: 'usdt' });
|
|
23
|
-
const fee = (_b = (_a = res0.data
|
|
24
|
-
.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;
|
|
25
|
-
if (!fee) {
|
|
26
|
-
return { state: 'ERROR', message: 'MISSING FEE' };
|
|
27
|
-
}
|
|
28
|
-
const res = await postWithdraw(credential, {
|
|
29
|
-
address: order.current_rx_address,
|
|
30
|
-
amount: '' + (order.expected_amount - +fee),
|
|
31
|
-
currency: 'usdt',
|
|
32
|
-
fee: fee,
|
|
33
|
-
chain: 'trc20usdt',
|
|
34
|
-
});
|
|
35
|
-
if (res.status != 'ok') {
|
|
36
|
-
return { state: 'INIT', message: `${res.status}` };
|
|
37
|
-
}
|
|
38
|
-
return { state: 'PENDING', context: `${res.data}` };
|
|
39
|
-
},
|
|
40
|
-
PENDING: async (order) => {
|
|
41
|
-
var _a;
|
|
42
|
-
if (!order.current_tx_context) {
|
|
43
|
-
return { state: 'ERROR', message: 'MISSING CONTEXT' };
|
|
44
|
-
}
|
|
45
|
-
const wdId = +order.current_tx_context;
|
|
46
|
-
const res = await getDepositWithdrawHistory(credential, {
|
|
47
|
-
currency: 'usdt',
|
|
48
|
-
type: 'withdraw',
|
|
49
|
-
from: `${wdId}`,
|
|
50
|
-
});
|
|
51
|
-
const txId = (_a = res.data.find((v) => v.id === wdId)) === null || _a === void 0 ? void 0 : _a['tx-hash'];
|
|
52
|
-
if (!txId) {
|
|
53
|
-
return { state: 'PENDING', context: `${wdId}` };
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
state: 'COMPLETE',
|
|
57
|
-
transaction_id: txId,
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
onEval: async (order) => {
|
|
62
|
-
const res = await getDepositWithdrawHistory(credential, {
|
|
63
|
-
currency: 'usdt',
|
|
64
|
-
type: 'deposit',
|
|
65
|
-
direct: 'next',
|
|
66
|
-
});
|
|
67
|
-
const theItem = res.data.find((v) => v['tx-hash'] === order.current_transaction_id && v.state === 'safe');
|
|
68
|
-
if (!theItem) {
|
|
69
|
-
return { state: 'PENDING' };
|
|
70
|
-
}
|
|
71
|
-
return { received_amount: +theItem.amount, state: 'COMPLETE' };
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* 设置 SPOT 和 SUPER_MARGIN 账户之间的内部转账
|
|
78
|
-
*/
|
|
79
|
-
export const setupSpotSuperMarginTransfer = (terminal, spotAccountId, superMarginAccountId, credential, huobiUid) => {
|
|
80
|
-
const networkId = `Huobi/${huobiUid}/SPOT-SUPER_MARGIN`;
|
|
81
|
-
// SPOT -> SUPER_MARGIN
|
|
82
|
-
addAccountTransferAddress({
|
|
83
|
-
terminal,
|
|
84
|
-
account_id: spotAccountId,
|
|
85
|
-
currency: 'USDT',
|
|
86
|
-
network_id: networkId,
|
|
87
|
-
address: 'SPOT',
|
|
88
|
-
onApply: {
|
|
89
|
-
INIT: async (order) => {
|
|
90
|
-
const transferInResult = await postSuperMarginAccountTransferIn(credential, {
|
|
91
|
-
currency: 'usdt',
|
|
92
|
-
amount: '' + (order.current_amount || order.expected_amount),
|
|
93
|
-
});
|
|
94
|
-
if (transferInResult.status !== 'ok') {
|
|
95
|
-
return { state: 'INIT' };
|
|
96
|
-
}
|
|
97
|
-
return { state: 'COMPLETE' };
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
onEval: async (order) => {
|
|
101
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
// SUPER_MARGIN -> SPOT
|
|
105
|
-
addAccountTransferAddress({
|
|
106
|
-
terminal,
|
|
107
|
-
account_id: superMarginAccountId,
|
|
108
|
-
currency: 'USDT',
|
|
109
|
-
network_id: networkId,
|
|
110
|
-
address: 'SUPER_MARGIN',
|
|
111
|
-
onApply: {
|
|
112
|
-
INIT: async (order) => {
|
|
113
|
-
const transferOutResult = await postSuperMarginAccountTransferOut(credential, {
|
|
114
|
-
currency: 'usdt',
|
|
115
|
-
amount: '' + (order.current_amount || order.expected_amount),
|
|
116
|
-
});
|
|
117
|
-
if (transferOutResult.status !== 'ok') {
|
|
118
|
-
return { state: 'INIT' };
|
|
119
|
-
}
|
|
120
|
-
return { state: 'COMPLETE' };
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
onEval: async (order) => {
|
|
124
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* 设置 SPOT 和 SWAP 账户之间的内部转账
|
|
130
|
-
*/
|
|
131
|
-
export const setupSpotSwapTransfer = (terminal, spotAccountId, swapAccountId, credential, huobiUid) => {
|
|
132
|
-
const networkId = `Huobi/${huobiUid}/SPOT-SWAP`;
|
|
133
|
-
// SPOT -> SWAP
|
|
134
|
-
addAccountTransferAddress({
|
|
135
|
-
terminal,
|
|
136
|
-
account_id: spotAccountId,
|
|
137
|
-
currency: 'USDT',
|
|
138
|
-
network_id: networkId,
|
|
139
|
-
address: 'SPOT',
|
|
140
|
-
onApply: {
|
|
141
|
-
INIT: async (order) => {
|
|
142
|
-
const transferResult = await postSpotAccountTransfer(credential, {
|
|
143
|
-
from: 'spot',
|
|
144
|
-
to: 'linear-swap',
|
|
145
|
-
currency: 'usdt',
|
|
146
|
-
amount: order.current_amount || order.expected_amount,
|
|
147
|
-
'margin-account': 'USDT',
|
|
148
|
-
});
|
|
149
|
-
if (!transferResult.success) {
|
|
150
|
-
return { state: 'INIT' };
|
|
151
|
-
}
|
|
152
|
-
return { state: 'COMPLETE' };
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
onEval: async (order) => {
|
|
156
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
// SWAP -> SPOT
|
|
160
|
-
addAccountTransferAddress({
|
|
161
|
-
terminal,
|
|
162
|
-
account_id: swapAccountId,
|
|
163
|
-
currency: 'USDT',
|
|
164
|
-
network_id: networkId,
|
|
165
|
-
address: 'SWAP',
|
|
166
|
-
onApply: {
|
|
167
|
-
INIT: async (order) => {
|
|
168
|
-
const transferResult = await postSpotAccountTransfer(credential, {
|
|
169
|
-
from: 'linear-swap',
|
|
170
|
-
to: 'spot',
|
|
171
|
-
currency: 'usdt',
|
|
172
|
-
amount: order.current_amount || order.expected_amount,
|
|
173
|
-
'margin-account': 'USDT',
|
|
174
|
-
});
|
|
175
|
-
if (!transferResult.success) {
|
|
176
|
-
return { state: 'INIT' };
|
|
177
|
-
}
|
|
178
|
-
return { state: 'COMPLETE' };
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
onEval: async (order) => {
|
|
182
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* 设置子账户转账
|
|
188
|
-
*/
|
|
189
|
-
export const setupSubAccountTransfers = (terminal, spotAccountId, credential, huobiUid, subAccounts, isMainAccount) => {
|
|
190
|
-
if (!isMainAccount) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
for (const subAccount of subAccounts) {
|
|
194
|
-
const spotSubAccountId = `huobi/${subAccount.uid}/spot/usdt`;
|
|
195
|
-
const subAccountNetworkId = `Huobi/${huobiUid}/SubAccount/${subAccount.uid}`;
|
|
196
|
-
// 主账户 -> 子账户
|
|
197
|
-
addAccountTransferAddress({
|
|
198
|
-
terminal,
|
|
199
|
-
account_id: spotAccountId,
|
|
200
|
-
currency: 'USDT',
|
|
201
|
-
network_id: subAccountNetworkId,
|
|
202
|
-
address: '#main',
|
|
203
|
-
onApply: {
|
|
204
|
-
INIT: async (order) => {
|
|
205
|
-
const transferResult = await postSubUserTransfer(credential, {
|
|
206
|
-
'sub-uid': +order.current_rx_address,
|
|
207
|
-
currency: 'usdt',
|
|
208
|
-
amount: order.current_amount || order.expected_amount,
|
|
209
|
-
type: 'master-transfer-out',
|
|
210
|
-
});
|
|
211
|
-
if (transferResult.status !== 'ok') {
|
|
212
|
-
return { state: 'INIT' };
|
|
213
|
-
}
|
|
214
|
-
return { state: 'COMPLETE' };
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
onEval: async (order) => {
|
|
218
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
// 子账户 -> 主账户
|
|
222
|
-
addAccountTransferAddress({
|
|
223
|
-
terminal,
|
|
224
|
-
account_id: spotSubAccountId,
|
|
225
|
-
currency: 'USDT',
|
|
226
|
-
network_id: subAccountNetworkId,
|
|
227
|
-
address: `${subAccount.uid}`,
|
|
228
|
-
onApply: {
|
|
229
|
-
INIT: async (order) => {
|
|
230
|
-
const transferResult = await postSubUserTransfer(credential, {
|
|
231
|
-
'sub-uid': +order.current_tx_address,
|
|
232
|
-
currency: 'usdt',
|
|
233
|
-
amount: order.current_amount || order.expected_amount,
|
|
234
|
-
type: 'master-transfer-in',
|
|
235
|
-
});
|
|
236
|
-
if (transferResult.status !== 'ok') {
|
|
237
|
-
return { state: 'INIT' };
|
|
238
|
-
}
|
|
239
|
-
return { state: 'COMPLETE' };
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
onEval: async (order) => {
|
|
243
|
-
return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
//# sourceMappingURL=transfer.js.map
|
package/dist/transfer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EAExB,uBAAuB,EACvB,mBAAmB,EACnB,gCAAgC,EAChC,iCAAiC,EACjC,YAAY,GACb,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,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,8BAA8B,CAAC,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,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAExF,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE;QAC/B,yBAAyB,CAAC;YACxB,QAAQ;YACR,UAAU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AO,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,OAAO,EAAE;gBACP,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACpB,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,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","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/dist/uid.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uid.js","sourceRoot":"","sources":["../src/uid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtE,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAC5D,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACzF,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CACrD,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACjF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;IACjD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,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,eAAe;QACrB,WAAW,EAAE,uBAAuB;QACpC,IAAI,EAAE,eAAe;KACtB,CAAC;AACJ,CAAC,CAAC","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 spot: SPOT_ACCOUNT_ID,\n superMargin: SUPER_MARGIN_ACCOUNT_ID,\n swap: SWAP_ACCOUNT_ID,\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-actions-with-credentials.d.ts","sourceRoot":"","sources":["../src/account-actions-with-credentials.ts"],"names":[],"mappings":""}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const data_account_1 = require("@yuants/data-account");
|
|
4
|
-
const protocol_1 = require("@yuants/protocol");
|
|
5
|
-
const list_1 = require("./accounts/list");
|
|
6
|
-
const spot_1 = require("./accounts/spot");
|
|
7
|
-
const super_margin_1 = require("./accounts/super-margin");
|
|
8
|
-
const swap_1 = require("./accounts/swap");
|
|
9
|
-
const uid_1 = require("./uid");
|
|
10
|
-
(0, data_account_1.provideAccountActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'HTX', {
|
|
11
|
-
type: 'object',
|
|
12
|
-
required: ['access_key', 'secret_key'],
|
|
13
|
-
properties: {
|
|
14
|
-
access_key: { type: 'string' },
|
|
15
|
-
secret_key: { type: 'string' },
|
|
16
|
-
},
|
|
17
|
-
}, {
|
|
18
|
-
listAccounts: list_1.listAccounts,
|
|
19
|
-
getAccountInfo: async (credential, account_id) => {
|
|
20
|
-
const accounts = await (0, uid_1.getAccountIds)(JSON.stringify(credential));
|
|
21
|
-
switch (account_id) {
|
|
22
|
-
case accounts.spot:
|
|
23
|
-
return (0, spot_1.getSpotAccountInfo)(credential, account_id);
|
|
24
|
-
case accounts.superMargin:
|
|
25
|
-
return (0, super_margin_1.getSuperMarginAccountInfo)(credential, account_id);
|
|
26
|
-
case accounts.swap:
|
|
27
|
-
return (0, swap_1.getSwapAccountInfo)(credential, account_id);
|
|
28
|
-
}
|
|
29
|
-
throw new Error(`Unsupported account_id: ${account_id}`);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
//# sourceMappingURL=account-actions-with-credentials.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-actions-with-credentials.js","sourceRoot":"","sources":["../src/account-actions-with-credentials.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAC5C,0CAA+C;AAC/C,0CAAqD;AACrD,0DAAoE;AACpE,0CAAqD;AACrD,+BAAsC;AAEtC,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,KAAK,EACL;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACtC,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,YAAY,EAAE,mBAAY;IAC1B,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAa,EAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QACjE,QAAQ,UAAU,EAAE;YAClB,KAAK,QAAQ,CAAC,IAAI;gBAChB,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACpD,KAAK,QAAQ,CAAC,WAAW;gBACvB,OAAO,IAAA,wCAAyB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAC3D,KAAK,QAAQ,CAAC,IAAI;gBAChB,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACrD;QACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { listAccounts } from './accounts/list';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getSuperMarginAccountInfo } from './accounts/super-margin';\nimport { getSwapAccountInfo } from './accounts/swap';\nimport { getAccountIds } from './uid';\n\nprovideAccountActionsWithCredential(\n Terminal.fromNodeEnv(),\n 'HTX',\n {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n {\n listAccounts: listAccounts,\n getAccountInfo: async (credential, account_id) => {\n const accounts = await getAccountIds(JSON.stringify(credential));\n switch (account_id) {\n case accounts.spot:\n return getSpotAccountInfo(credential, account_id);\n case accounts.superMargin:\n return getSuperMarginAccountInfo(credential, account_id);\n case accounts.swap:\n return getSwapAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
|
package/lib/account-info.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Terminal } from '@yuants/protocol';
|
|
2
|
-
import { ICredential } from './api/private-api';
|
|
3
|
-
/**
|
|
4
|
-
* 提供 SWAP 账户信息服务
|
|
5
|
-
*/
|
|
6
|
-
export declare const provideSwapAccountInfoService: (terminal: Terminal, accountId: string, credential: ICredential) => void;
|
|
7
|
-
/**
|
|
8
|
-
* 获取超级保证金账户余额流
|
|
9
|
-
*/
|
|
10
|
-
export declare const getSuperMarginAccountBalance$: (credential: ICredential, superMarginAccountUid: number) => import("rxjs").Observable<{
|
|
11
|
-
list: {
|
|
12
|
-
currency: string;
|
|
13
|
-
balance: string;
|
|
14
|
-
type: string;
|
|
15
|
-
}[];
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* 设置超级保证金账户的 WebSocket 订阅
|
|
19
|
-
*/
|
|
20
|
-
export declare const setupSuperMarginWebSocketSubscriptions: (superMarginAccountBalance$: ReturnType<typeof getSuperMarginAccountBalance$>, subscriptions: Set<string>) => void;
|
|
21
|
-
/**
|
|
22
|
-
* 提供超级保证金账户信息服务
|
|
23
|
-
*/
|
|
24
|
-
export declare const provideSuperMarginAccountInfoService: (terminal: Terminal, accountId: string, credential: ICredential, superMarginAccountUid: number, subscriptions: Set<string>) => import("rxjs").Observable<{
|
|
25
|
-
list: {
|
|
26
|
-
currency: string;
|
|
27
|
-
balance: string;
|
|
28
|
-
type: string;
|
|
29
|
-
}[];
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* 提供 SPOT 账户信息服务
|
|
33
|
-
*/
|
|
34
|
-
export declare const provideSpotAccountInfoService: (terminal: Terminal, accountId: string, credential: ICredential) => void;
|
|
35
|
-
//# sourceMappingURL=account-info.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-info.d.ts","sourceRoot":"","sources":["../src/account-info.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAO5C,OAAO,EAAyB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,6BAA6B,aAC9B,QAAQ,aACP,MAAM,cACL,WAAW,SAKxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,eAAgB,WAAW,yBAAyB,MAAM;;;;;;EAanG,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC,+BACrB,WAAW,oCAAoC,CAAC,iBAC7D,IAAI,MAAM,CAAC,SAoC3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oCAAoC,aACrC,QAAQ,aACP,MAAM,cACL,WAAW,yBACA,MAAM,iBACd,IAAI,MAAM,CAAC;;;;;;EAa3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,aAC9B,QAAQ,aACP,MAAM,cACL,WAAW,SAKxB,CAAC"}
|
package/lib/account-info.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.provideSpotAccountInfoService = exports.provideSuperMarginAccountInfoService = exports.setupSuperMarginWebSocketSubscriptions = exports.getSuperMarginAccountBalance$ = exports.provideSwapAccountInfoService = void 0;
|
|
4
|
-
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const utils_1 = require("@yuants/utils");
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
const spot_1 = require("./accounts/spot");
|
|
8
|
-
const super_margin_1 = require("./accounts/super-margin");
|
|
9
|
-
const swap_1 = require("./accounts/swap");
|
|
10
|
-
const api_1 = require("./api");
|
|
11
|
-
const private_api_1 = require("./api/private-api");
|
|
12
|
-
/**
|
|
13
|
-
* 提供 SWAP 账户信息服务
|
|
14
|
-
*/
|
|
15
|
-
const provideSwapAccountInfoService = (terminal, accountId, credential) => {
|
|
16
|
-
(0, data_account_1.provideAccountInfoService)(terminal, accountId, async () => (0, swap_1.getSwapAccountInfo)(credential, accountId), {
|
|
17
|
-
auto_refresh_interval: 1000,
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
exports.provideSwapAccountInfoService = provideSwapAccountInfoService;
|
|
21
|
-
/**
|
|
22
|
-
* 获取超级保证金账户余额流
|
|
23
|
-
*/
|
|
24
|
-
const getSuperMarginAccountBalance$ = (credential, superMarginAccountUid) => {
|
|
25
|
-
return (0, rxjs_1.defer)(() => (0, private_api_1.getSpotAccountBalance)(credential, superMarginAccountUid)).pipe(
|
|
26
|
-
//
|
|
27
|
-
(0, rxjs_1.map)((res) => res.data), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.tap)({
|
|
28
|
-
error: (e) => {
|
|
29
|
-
console.error((0, utils_1.formatTime)(Date.now()), 'unifiedRaw', e);
|
|
30
|
-
},
|
|
31
|
-
}), (0, rxjs_1.retry)({ delay: 5000 }), (0, rxjs_1.shareReplay)(1));
|
|
32
|
-
};
|
|
33
|
-
exports.getSuperMarginAccountBalance$ = getSuperMarginAccountBalance$;
|
|
34
|
-
/**
|
|
35
|
-
* 设置超级保证金账户的 WebSocket 订阅
|
|
36
|
-
*/
|
|
37
|
-
const setupSuperMarginWebSocketSubscriptions = (superMarginAccountBalance$, subscriptions) => {
|
|
38
|
-
(0, rxjs_1.from)(api_1.client.spot_ws.connection$).subscribe(() => {
|
|
39
|
-
subscriptions.clear();
|
|
40
|
-
});
|
|
41
|
-
// subscribe the symbols of positions we held
|
|
42
|
-
superMarginAccountBalance$
|
|
43
|
-
.pipe(
|
|
44
|
-
//
|
|
45
|
-
(0, rxjs_1.mergeMap)((res) => (0, rxjs_1.from)((res === null || res === void 0 ? void 0 : res.list) || []).pipe((0, rxjs_1.filter)((v) => v.currency !== 'usdt'), (0, rxjs_1.map)((v) => v.currency), (0, rxjs_1.distinct)(), (0, rxjs_1.toArray)(), (0, rxjs_1.map)((v) => new Set(v)))))
|
|
46
|
-
.subscribe((v) => {
|
|
47
|
-
const toUnsubscribe = [...subscriptions].filter((x) => !v.has(x));
|
|
48
|
-
const toSubscribe = [...v].filter((x) => !subscriptions.has(x));
|
|
49
|
-
for (const symbol of toUnsubscribe) {
|
|
50
|
-
api_1.client.spot_ws.output$.next({
|
|
51
|
-
unsub: `market.${symbol}usdt.ticker`,
|
|
52
|
-
});
|
|
53
|
-
subscriptions.delete(symbol);
|
|
54
|
-
}
|
|
55
|
-
for (const symbol of toSubscribe) {
|
|
56
|
-
api_1.client.spot_ws.output$.next({
|
|
57
|
-
sub: `market.${symbol}usdt.ticker`,
|
|
58
|
-
});
|
|
59
|
-
subscriptions.add(symbol);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
exports.setupSuperMarginWebSocketSubscriptions = setupSuperMarginWebSocketSubscriptions;
|
|
64
|
-
/**
|
|
65
|
-
* 提供超级保证金账户信息服务
|
|
66
|
-
*/
|
|
67
|
-
const provideSuperMarginAccountInfoService = (terminal, accountId, credential, superMarginAccountUid, subscriptions) => {
|
|
68
|
-
const superMarginAccountBalance$ = (0, exports.getSuperMarginAccountBalance$)(credential, superMarginAccountUid);
|
|
69
|
-
(0, exports.setupSuperMarginWebSocketSubscriptions)(superMarginAccountBalance$, subscriptions);
|
|
70
|
-
(0, data_account_1.provideAccountInfoService)(terminal, accountId, async () => (0, super_margin_1.getSuperMarginAccountInfo)(credential, accountId), { auto_refresh_interval: 1000 });
|
|
71
|
-
return superMarginAccountBalance$;
|
|
72
|
-
};
|
|
73
|
-
exports.provideSuperMarginAccountInfoService = provideSuperMarginAccountInfoService;
|
|
74
|
-
/**
|
|
75
|
-
* 提供 SPOT 账户信息服务
|
|
76
|
-
*/
|
|
77
|
-
const provideSpotAccountInfoService = (terminal, accountId, credential) => {
|
|
78
|
-
(0, data_account_1.provideAccountInfoService)(terminal, accountId, async () => (0, spot_1.getSpotAccountInfo)(credential, accountId), {
|
|
79
|
-
auto_refresh_interval: 1000,
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
exports.provideSpotAccountInfoService = provideSpotAccountInfoService;
|
|
83
|
-
//# sourceMappingURL=account-info.js.map
|
package/lib/account-info.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-info.js","sourceRoot":"","sources":["../src/account-info.ts"],"names":[],"mappings":";;;AAAA,uDAAiE;AAEjE,yCAA2C;AAC3C,+BAA8G;AAC9G,0CAAqD;AACrD,0DAAoE;AACpE,0CAAqD;AACrD,+BAA+B;AAC/B,mDAAuE;AAEvE;;GAEG;AACI,MAAM,6BAA6B,GAAG,CAC3C,QAAkB,EAClB,SAAiB,EACjB,UAAuB,EACvB,EAAE;IACF,IAAA,wCAAyB,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,IAAA,yBAAkB,EAAC,UAAU,EAAE,SAAS,CAAC,EAAE;QACpG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC;AARW,QAAA,6BAA6B,iCAQxC;AAEF;;GAEG;AACI,MAAM,6BAA6B,GAAG,CAAC,UAAuB,EAAE,qBAA6B,EAAE,EAAE;IACtG,OAAO,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,mCAAqB,EAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC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AE,SAAS,CAAC,EAC5D,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAChC,CAAC;IAEF,OAAO,0BAA0B,CAAC;AACpC,CAAC,CAAC;AAlBW,QAAA,oCAAoC,wCAkB/C;AAEF;;GAEG;AACI,MAAM,6BAA6B,GAAG,CAC3C,QAAkB,EAClB,SAAiB,EACjB,UAAuB,EACvB,EAAE;IACF,IAAA,wCAAyB,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,IAAA,yBAAkB,EAAC,UAAU,EAAE,SAAS,CAAC,EAAE;QACpG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC;AARW,QAAA,6BAA6B,iCAQxC","sourcesContent":["import { provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { formatTime } from '@yuants/utils';\nimport { defer, distinct, filter, from, map, mergeMap, repeat, retry, shareReplay, tap, toArray } from 'rxjs';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getSuperMarginAccountInfo } from './accounts/super-margin';\nimport { getSwapAccountInfo } from './accounts/swap';\nimport { client } from './api';\nimport { getSpotAccountBalance, ICredential } from './api/private-api';\n\n/**\n * 提供 SWAP 账户信息服务\n */\nexport const provideSwapAccountInfoService = (\n terminal: Terminal,\n accountId: string,\n credential: ICredential,\n) => {\n provideAccountInfoService(terminal, accountId, async () => getSwapAccountInfo(credential, accountId), {\n auto_refresh_interval: 1000,\n });\n};\n\n/**\n * 获取超级保证金账户余额流\n */\nexport const getSuperMarginAccountBalance$ = (credential: ICredential, superMarginAccountUid: number) => {\n return defer(() => getSpotAccountBalance(credential, superMarginAccountUid)).pipe(\n //\n map((res) => res.data),\n repeat({ delay: 1000 }),\n tap({\n error: (e) => {\n console.error(formatTime(Date.now()), 'unifiedRaw', e);\n },\n }),\n retry({ delay: 5000 }),\n shareReplay(1),\n );\n};\n\n/**\n * 设置超级保证金账户的 WebSocket 订阅\n */\nexport const setupSuperMarginWebSocketSubscriptions = (\n superMarginAccountBalance$: ReturnType<typeof getSuperMarginAccountBalance$>,\n subscriptions: Set<string>,\n) => {\n from(client.spot_ws.connection$).subscribe(() => {\n subscriptions.clear();\n });\n // subscribe the symbols of positions we held\n superMarginAccountBalance$\n .pipe(\n //\n mergeMap((res) =>\n from(res?.list || []).pipe(\n filter((v) => v.currency !== 'usdt'),\n map((v) => v.currency),\n distinct(),\n toArray(),\n map((v) => new Set(v)),\n ),\n ),\n )\n .subscribe((v: Set<string>) => {\n const toUnsubscribe = [...subscriptions].filter((x) => !v.has(x));\n const toSubscribe = [...v].filter((x) => !subscriptions.has(x));\n\n for (const symbol of toUnsubscribe) {\n client.spot_ws.output$.next({\n unsub: `market.${symbol}usdt.ticker`,\n });\n subscriptions.delete(symbol);\n }\n for (const symbol of toSubscribe) {\n client.spot_ws.output$.next({\n sub: `market.${symbol}usdt.ticker`,\n });\n subscriptions.add(symbol);\n }\n });\n};\n\n/**\n * 提供超级保证金账户信息服务\n */\nexport const provideSuperMarginAccountInfoService = (\n terminal: Terminal,\n accountId: string,\n credential: ICredential,\n superMarginAccountUid: number,\n subscriptions: Set<string>,\n) => {\n const superMarginAccountBalance$ = getSuperMarginAccountBalance$(credential, superMarginAccountUid);\n setupSuperMarginWebSocketSubscriptions(superMarginAccountBalance$, subscriptions);\n\n provideAccountInfoService(\n terminal,\n accountId,\n async () => getSuperMarginAccountInfo(credential, accountId),\n { auto_refresh_interval: 1000 },\n );\n\n return superMarginAccountBalance$;\n};\n\n/**\n * 提供 SPOT 账户信息服务\n */\nexport const provideSpotAccountInfoService = (\n terminal: Terminal,\n accountId: string,\n credential: ICredential,\n) => {\n provideAccountInfoService(terminal, accountId, async () => getSpotAccountInfo(credential, accountId), {\n auto_refresh_interval: 1000,\n });\n};\n"]}
|
package/lib/accounts/list.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/accounts/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,eAAO,MAAM,YAAY,EAAE,4BAA4B,CAAC,WAAW,CAKlE,CAAC"}
|
package/lib/accounts/list.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listAccounts = void 0;
|
|
4
|
-
const uid_1 = require("../uid");
|
|
5
|
-
const listAccounts = async (credential) => {
|
|
6
|
-
const accounts = await (0, uid_1.getAccountIds)(JSON.stringify(credential));
|
|
7
|
-
if (!accounts)
|
|
8
|
-
throw new Error('Failed to get Account IDs');
|
|
9
|
-
return [{ account_id: accounts.spot }, { account_id: accounts.superMargin }, { account_id: accounts.swap }];
|
|
10
|
-
};
|
|
11
|
-
exports.listAccounts = listAccounts;
|
|
12
|
-
//# sourceMappingURL=list.js.map
|
package/lib/accounts/list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/accounts/list.ts"],"names":[],"mappings":";;;AAEA,gCAAuC;AAEhC,MAAM,YAAY,GAA8C,KAAK,EAAE,UAAU,EAAE,EAAE;IAC1F,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAa,EAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACjE,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAE5D,OAAO,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9G,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB","sourcesContent":["import { IActionHandlerOfListAccounts } from '@yuants/data-account';\nimport { ICredential } from '../api/private-api';\nimport { getAccountIds } from '../uid';\n\nexport const listAccounts: IActionHandlerOfListAccounts<ICredential> = async (credential) => {\n const accounts = await getAccountIds(JSON.stringify(credential));\n if (!accounts) throw new Error('Failed to get Account IDs');\n\n return [{ account_id: accounts.spot }, { account_id: accounts.superMargin }, { account_id: accounts.swap }];\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAoB,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGxE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAe1E,CAAC"}
|
package/lib/accounts/spot.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AACxF,oDAAwE;AACxE,gCAA6C;AAEtC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,cAAc,GAAG,MAAM,yBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACrC,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE;YAC5B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,OAAO;YACrC,MAAM,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YACzB,WAAW,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YAC9B,cAAc,EAAE,CAAC,EAAE,iBAAiB;SACrC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { spotAccountUidCache } from '../uid';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n return spotBalance.data.list.map((v) => {\n return makeSpotPosition({\n position_id: `${v.currency}`,\n datasource_id: 'HTX',\n product_id: `SPOT/${v.currency}-USDT`,\n volume: +(v.balance ?? 0),\n free_volume: +(v.balance ?? 0),\n closable_price: 1, // TODO: 获取现货币对价格\n });\n });\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"super-margin.d.ts","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AASxE;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,8BAA8B,CAAC,WAAW,CA+CjF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,y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,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7D;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAA6C,CAAC,CAAC;IAEpD,kCAAkC;IAClC,KAAK,MAAM,YAAY,IAAI,iBAAiB,EAAE;QAC5C,IAAI,YAAY,CAAC,OAAO,GAAG,CAAC,EAAE;YAC5B,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YACnE,MAAM,KAAK,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,CAAC,KAAK,KAAI,CAAC,CAAC;YACzC,IAAI;gBACF,2DAA2D;gBAE3D,SAAS,CAAC,IAAI,CAAC;oBACb,WAAW,EAAE,GAAG,YAAY,CAAC,QAAQ,YAAY;oBACjD,UAAU,EAAE,GAAG,YAAY,CAAC,QAAQ,MAAM;oBAC1C,SAAS,EAAE,MAAM;oBACjB,MAAM,EAAE,YAAY,CAAC,OAAO;oBAC5B,WAAW,EAAE,YAAY,CAAC,OAAO;oBACjC,cAAc,EAAE,KAAK;oBACrB,cAAc,EAAE,KAAK;oBACrB,eAAe,EAAE,CAAC;oBAClB,SAAS,EAAE,YAAY,CAAC,OAAO,GAAG,KAAK;iBACxC,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,2BAA2B,YAAY,CAAC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;aAClG;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AA/CW,QAAA,yBAAyB,6BA+CpC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { formatTime } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { getSpotTick } from '../api/public-api';\nimport { superMarginAccountUidCache } from '../uid';\n\nconst spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {\n expire: 300_000, // 5 minutes\n swrAfter: 10_000, // 10 seconds\n});\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Failed to get Super Margin Account UID');\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // get positions (non-usdt currencies)\n const positions: IPosition[] = [];\n const nonUsdtCurrencies = balanceList\n .filter((v) => v.currency !== 'usdt')\n .reduce((acc, cur) => {\n const existing = acc.find((item) => item.currency === cur.currency);\n if (existing) {\n existing.balance += +cur.balance;\n } else {\n acc.push({ currency: cur.currency, balance: +cur.balance });\n }\n return acc;\n }, [] as { currency: string; balance: number }[]);\n\n // get prices and create positions\n for (const currencyData of nonUsdtCurrencies) {\n if (currencyData.balance > 0) {\n const tickerRes = await spotTickCache.query(currencyData.currency);\n const price = tickerRes?.tick.close || 0;\n try {\n // get current price from websocket or fallback to REST API\n\n positions.push({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: `${currencyData.currency}usdt`,\n direction: 'LONG',\n volume: currencyData.balance,\n free_volume: currencyData.balance,\n position_price: price,\n closable_price: price,\n floating_profit: 0,\n valuation: currencyData.balance * price,\n });\n } catch (error) {\n console.warn(formatTime(Date.now()), `Failed to get price for ${currencyData.currency}:`, error);\n }\n }\n }\n\n return positions;\n};\n"]}
|
package/lib/accounts/swap.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAmD,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGlG,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAiF1E,CAAC"}
|
package/lib/accounts/swap.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSwapAccountInfo = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const private_api_1 = require("../api/private-api");
|
|
6
|
-
const product_1 = require("../product");
|
|
7
|
-
const getSwapAccountInfo = async (credential) => {
|
|
8
|
-
// balance
|
|
9
|
-
const balance = await (0, private_api_1.getUnifiedAccountInfo)(credential);
|
|
10
|
-
if (!balance.data) {
|
|
11
|
-
throw new Error('Failed to get unified account info');
|
|
12
|
-
}
|
|
13
|
-
const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');
|
|
14
|
-
if (!balanceData) {
|
|
15
|
-
throw new Error('No USDT balance found in unified account');
|
|
16
|
-
}
|
|
17
|
-
const equity = balanceData.margin_balance;
|
|
18
|
-
const free = balanceData.withdraw_available;
|
|
19
|
-
// positions
|
|
20
|
-
const positionsRes = await (0, private_api_1.getSwapCrossPositionInfo)(credential);
|
|
21
|
-
const mapProductIdToPerpetualProduct = await (0, rxjs_1.firstValueFrom)(product_1.swapProductService.mapProductIdToProduct$);
|
|
22
|
-
const positions = (positionsRes.data || []).map((v) => {
|
|
23
|
-
const product_id = v.contract_code;
|
|
24
|
-
const theProduct = mapProductIdToPerpetualProduct === null || mapProductIdToPerpetualProduct === void 0 ? void 0 : mapProductIdToPerpetualProduct.get(product_id);
|
|
25
|
-
const valuation = v.volume * v.last_price * ((theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) || 1);
|
|
26
|
-
return {
|
|
27
|
-
position_id: `${v.contract_code}/${v.contract_type}/${v.direction}/${v.margin_mode}`,
|
|
28
|
-
datasource_id: 'HUOBI-SWAP',
|
|
29
|
-
product_id,
|
|
30
|
-
direction: v.direction === 'buy' ? 'LONG' : 'SHORT',
|
|
31
|
-
volume: v.volume,
|
|
32
|
-
free_volume: v.available,
|
|
33
|
-
position_price: v.cost_hold,
|
|
34
|
-
closable_price: v.last_price,
|
|
35
|
-
floating_profit: v.profit_unreal,
|
|
36
|
-
valuation,
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
// orders
|
|
40
|
-
// const orders: IOrder[] = [];
|
|
41
|
-
// let page_index = 1;
|
|
42
|
-
// const page_size = 50;
|
|
43
|
-
// while (true) {
|
|
44
|
-
// const ordersRes = await client.getSwapOpenOrders({ page_index, page_size });
|
|
45
|
-
// if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {
|
|
46
|
-
// break;
|
|
47
|
-
// }
|
|
48
|
-
// const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {
|
|
49
|
-
// return {
|
|
50
|
-
// order_id: v.order_id_str,
|
|
51
|
-
// account_id: SWAP_ACCOUNT_ID,
|
|
52
|
-
// product_id: v.contract_code,
|
|
53
|
-
// order_type: ['lightning'].includes(v.order_price_type)
|
|
54
|
-
// ? 'MARKET'
|
|
55
|
-
// : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(
|
|
56
|
-
// v.order_price_type,
|
|
57
|
-
// )
|
|
58
|
-
// ? 'LIMIT'
|
|
59
|
-
// : ['fok'].includes(v.order_price_type)
|
|
60
|
-
// ? 'FOK'
|
|
61
|
-
// : v.order_price_type.includes('ioc')
|
|
62
|
-
// ? 'IOC'
|
|
63
|
-
// : 'STOP', // unreachable code
|
|
64
|
-
// order_direction:
|
|
65
|
-
// v.direction === 'open'
|
|
66
|
-
// ? v.offset === 'buy'
|
|
67
|
-
// ? 'OPEN_LONG'
|
|
68
|
-
// : 'OPEN_SHORT'
|
|
69
|
-
// : v.offset === 'buy'
|
|
70
|
-
// ? 'CLOSE_SHORT'
|
|
71
|
-
// : 'CLOSE_LONG',
|
|
72
|
-
// volume: v.volume,
|
|
73
|
-
// submit_at: v.created_at,
|
|
74
|
-
// price: v.price,
|
|
75
|
-
// traded_volume: v.trade_volume,
|
|
76
|
-
// };
|
|
77
|
-
// });
|
|
78
|
-
// orders.push(...pageOrders);
|
|
79
|
-
// page_index++;
|
|
80
|
-
// }
|
|
81
|
-
return positions;
|
|
82
|
-
};
|
|
83
|
-
exports.getSwapAccountInfo = getSwapAccountInfo;
|
|
84
|
-
//# sourceMappingURL=swap.js.map
|