@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
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { Terminal } from '@yuants/protocol';
|
|
3
|
+
// import { addAccountTransferAddress } from '@yuants/transfer';
|
|
4
|
+
// import {
|
|
5
|
+
// getDepositWithdrawHistory,
|
|
6
|
+
// getSpotAccountDepositAddresses,
|
|
7
|
+
// getV2ReferenceCurrencies,
|
|
8
|
+
// ICredential,
|
|
9
|
+
// postSpotAccountTransfer,
|
|
10
|
+
// postSubUserTransfer,
|
|
11
|
+
// postSuperMarginAccountTransferIn,
|
|
12
|
+
// postSuperMarginAccountTransferOut,
|
|
13
|
+
// postWithdraw,
|
|
14
|
+
// } from './api/private-api';
|
|
15
|
+
// /**
|
|
16
|
+
// * 设置 TRC20 USDT 提现地址
|
|
17
|
+
// */
|
|
18
|
+
// export const setupTrc20WithdrawalAddresses = async (
|
|
19
|
+
// terminal: Terminal,
|
|
20
|
+
// spotAccountId: string,
|
|
21
|
+
// credential: ICredential,
|
|
22
|
+
// isMainAccount: boolean,
|
|
23
|
+
// ) => {
|
|
24
|
+
// if (!isMainAccount) {
|
|
25
|
+
// return;
|
|
26
|
+
// }
|
|
27
|
+
// const res = await getSpotAccountDepositAddresses(credential, { currency: 'usdt' });
|
|
28
|
+
// const addresses = res.data.filter((v) => v.chain === 'trc20usdt').map((v) => v.address);
|
|
29
|
+
// for (const address of addresses) {
|
|
30
|
+
// addAccountTransferAddress({
|
|
31
|
+
// terminal,
|
|
32
|
+
// account_id: spotAccountId,
|
|
33
|
+
// currency: 'USDT',
|
|
34
|
+
// address: address,
|
|
35
|
+
// network_id: 'TRC20',
|
|
36
|
+
// onApply: {
|
|
37
|
+
// INIT: async (order) => {
|
|
38
|
+
// const res0 = await getV2ReferenceCurrencies(credential, { currency: 'usdt' });
|
|
39
|
+
// const fee = res0.data
|
|
40
|
+
// .find((v) => v.currency === 'usdt')
|
|
41
|
+
// ?.chains.find((v) => v.chain === 'trc20usdt')?.transactFeeWithdraw;
|
|
42
|
+
// if (!fee) {
|
|
43
|
+
// return { state: 'ERROR', message: 'MISSING FEE' };
|
|
44
|
+
// }
|
|
45
|
+
// const res = await postWithdraw(credential, {
|
|
46
|
+
// address: order.current_rx_address!,
|
|
47
|
+
// amount: '' + (order.expected_amount - +fee),
|
|
48
|
+
// currency: 'usdt',
|
|
49
|
+
// fee: fee,
|
|
50
|
+
// chain: 'trc20usdt',
|
|
51
|
+
// });
|
|
52
|
+
// if (res.status != 'ok') {
|
|
53
|
+
// return { state: 'INIT', message: `${res.status}` };
|
|
54
|
+
// }
|
|
55
|
+
// return { state: 'PENDING', context: `${res.data}` };
|
|
56
|
+
// },
|
|
57
|
+
// PENDING: async (order) => {
|
|
58
|
+
// if (!order.current_tx_context) {
|
|
59
|
+
// return { state: 'ERROR', message: 'MISSING CONTEXT' };
|
|
60
|
+
// }
|
|
61
|
+
// const wdId = +order.current_tx_context;
|
|
62
|
+
// const res = await getDepositWithdrawHistory(credential, {
|
|
63
|
+
// currency: 'usdt',
|
|
64
|
+
// type: 'withdraw',
|
|
65
|
+
// from: `${wdId}`,
|
|
66
|
+
// });
|
|
67
|
+
// const txId = res.data.find((v) => v.id === wdId)?.['tx-hash'];
|
|
68
|
+
// if (!txId) {
|
|
69
|
+
// return { state: 'PENDING', context: `${wdId}` };
|
|
70
|
+
// }
|
|
71
|
+
// return {
|
|
72
|
+
// state: 'COMPLETE',
|
|
73
|
+
// transaction_id: txId,
|
|
74
|
+
// };
|
|
75
|
+
// },
|
|
76
|
+
// },
|
|
77
|
+
// onEval: async (order) => {
|
|
78
|
+
// const res = await getDepositWithdrawHistory(credential, {
|
|
79
|
+
// currency: 'usdt',
|
|
80
|
+
// type: 'deposit',
|
|
81
|
+
// direct: 'next',
|
|
82
|
+
// });
|
|
83
|
+
// const theItem = res.data.find(
|
|
84
|
+
// (v) => v['tx-hash'] === order.current_transaction_id && v.state === 'safe',
|
|
85
|
+
// );
|
|
86
|
+
// if (!theItem) {
|
|
87
|
+
// return { state: 'PENDING' };
|
|
88
|
+
// }
|
|
89
|
+
// return { received_amount: +theItem.amount, state: 'COMPLETE' };
|
|
90
|
+
// },
|
|
91
|
+
// });
|
|
92
|
+
// }
|
|
93
|
+
// };
|
|
94
|
+
// /**
|
|
95
|
+
// * 设置 SPOT 和 SUPER_MARGIN 账户之间的内部转账
|
|
96
|
+
// */
|
|
97
|
+
// export const setupSpotSuperMarginTransfer = (
|
|
98
|
+
// terminal: Terminal,
|
|
99
|
+
// spotAccountId: string,
|
|
100
|
+
// superMarginAccountId: string,
|
|
101
|
+
// credential: ICredential,
|
|
102
|
+
// huobiUid: number,
|
|
103
|
+
// ) => {
|
|
104
|
+
// const networkId = `Huobi/${huobiUid}/SPOT-SUPER_MARGIN`;
|
|
105
|
+
// // SPOT -> SUPER_MARGIN
|
|
106
|
+
// addAccountTransferAddress({
|
|
107
|
+
// terminal,
|
|
108
|
+
// account_id: spotAccountId,
|
|
109
|
+
// currency: 'USDT',
|
|
110
|
+
// network_id: networkId,
|
|
111
|
+
// address: 'SPOT',
|
|
112
|
+
// onApply: {
|
|
113
|
+
// INIT: async (order) => {
|
|
114
|
+
// const transferInResult = await postSuperMarginAccountTransferIn(credential, {
|
|
115
|
+
// currency: 'usdt',
|
|
116
|
+
// amount: '' + (order.current_amount || order.expected_amount),
|
|
117
|
+
// });
|
|
118
|
+
// if (transferInResult.status !== 'ok') {
|
|
119
|
+
// return { state: 'INIT' };
|
|
120
|
+
// }
|
|
121
|
+
// return { state: 'COMPLETE' };
|
|
122
|
+
// },
|
|
123
|
+
// },
|
|
124
|
+
// onEval: async (order) => {
|
|
125
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
126
|
+
// },
|
|
127
|
+
// });
|
|
128
|
+
// // SUPER_MARGIN -> SPOT
|
|
129
|
+
// addAccountTransferAddress({
|
|
130
|
+
// terminal,
|
|
131
|
+
// account_id: superMarginAccountId,
|
|
132
|
+
// currency: 'USDT',
|
|
133
|
+
// network_id: networkId,
|
|
134
|
+
// address: 'SUPER_MARGIN',
|
|
135
|
+
// onApply: {
|
|
136
|
+
// INIT: async (order) => {
|
|
137
|
+
// const transferOutResult = await postSuperMarginAccountTransferOut(credential, {
|
|
138
|
+
// currency: 'usdt',
|
|
139
|
+
// amount: '' + (order.current_amount || order.expected_amount),
|
|
140
|
+
// });
|
|
141
|
+
// if (transferOutResult.status !== 'ok') {
|
|
142
|
+
// return { state: 'INIT' };
|
|
143
|
+
// }
|
|
144
|
+
// return { state: 'COMPLETE' };
|
|
145
|
+
// },
|
|
146
|
+
// },
|
|
147
|
+
// onEval: async (order) => {
|
|
148
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
149
|
+
// },
|
|
150
|
+
// });
|
|
151
|
+
// };
|
|
152
|
+
// /**
|
|
153
|
+
// * 设置 SPOT 和 SWAP 账户之间的内部转账
|
|
154
|
+
// */
|
|
155
|
+
// export const setupSpotSwapTransfer = (
|
|
156
|
+
// terminal: Terminal,
|
|
157
|
+
// spotAccountId: string,
|
|
158
|
+
// swapAccountId: string,
|
|
159
|
+
// credential: ICredential,
|
|
160
|
+
// huobiUid: number,
|
|
161
|
+
// ) => {
|
|
162
|
+
// const networkId = `Huobi/${huobiUid}/SPOT-SWAP`;
|
|
163
|
+
// // SPOT -> SWAP
|
|
164
|
+
// addAccountTransferAddress({
|
|
165
|
+
// terminal,
|
|
166
|
+
// account_id: spotAccountId,
|
|
167
|
+
// currency: 'USDT',
|
|
168
|
+
// network_id: networkId,
|
|
169
|
+
// address: 'SPOT',
|
|
170
|
+
// onApply: {
|
|
171
|
+
// INIT: async (order) => {
|
|
172
|
+
// const transferResult = await postSpotAccountTransfer(credential, {
|
|
173
|
+
// from: 'spot',
|
|
174
|
+
// to: 'linear-swap',
|
|
175
|
+
// currency: 'usdt',
|
|
176
|
+
// amount: order.current_amount || order.expected_amount,
|
|
177
|
+
// 'margin-account': 'USDT',
|
|
178
|
+
// });
|
|
179
|
+
// if (!transferResult.success) {
|
|
180
|
+
// return { state: 'INIT' };
|
|
181
|
+
// }
|
|
182
|
+
// return { state: 'COMPLETE' };
|
|
183
|
+
// },
|
|
184
|
+
// },
|
|
185
|
+
// onEval: async (order) => {
|
|
186
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
187
|
+
// },
|
|
188
|
+
// });
|
|
189
|
+
// // SWAP -> SPOT
|
|
190
|
+
// addAccountTransferAddress({
|
|
191
|
+
// terminal,
|
|
192
|
+
// account_id: swapAccountId,
|
|
193
|
+
// currency: 'USDT',
|
|
194
|
+
// network_id: networkId,
|
|
195
|
+
// address: 'SWAP',
|
|
196
|
+
// onApply: {
|
|
197
|
+
// INIT: async (order) => {
|
|
198
|
+
// const transferResult = await postSpotAccountTransfer(credential, {
|
|
199
|
+
// from: 'linear-swap',
|
|
200
|
+
// to: 'spot',
|
|
201
|
+
// currency: 'usdt',
|
|
202
|
+
// amount: order.current_amount || order.expected_amount,
|
|
203
|
+
// 'margin-account': 'USDT',
|
|
204
|
+
// });
|
|
205
|
+
// if (!transferResult.success) {
|
|
206
|
+
// return { state: 'INIT' };
|
|
207
|
+
// }
|
|
208
|
+
// return { state: 'COMPLETE' };
|
|
209
|
+
// },
|
|
210
|
+
// },
|
|
211
|
+
// onEval: async (order) => {
|
|
212
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
213
|
+
// },
|
|
214
|
+
// });
|
|
215
|
+
// };
|
|
216
|
+
// /**
|
|
217
|
+
// * 设置子账户转账
|
|
218
|
+
// */
|
|
219
|
+
// export const setupSubAccountTransfers = (
|
|
220
|
+
// terminal: Terminal,
|
|
221
|
+
// spotAccountId: string,
|
|
222
|
+
// credential: ICredential,
|
|
223
|
+
// huobiUid: number,
|
|
224
|
+
// subAccounts: any[],
|
|
225
|
+
// isMainAccount: boolean,
|
|
226
|
+
// ) => {
|
|
227
|
+
// if (!isMainAccount) {
|
|
228
|
+
// return;
|
|
229
|
+
// }
|
|
230
|
+
// for (const subAccount of subAccounts) {
|
|
231
|
+
// const spotSubAccountId = `huobi/${subAccount.uid}/spot/usdt`;
|
|
232
|
+
// const subAccountNetworkId = `Huobi/${huobiUid}/SubAccount/${subAccount.uid}`;
|
|
233
|
+
// // 主账户 -> 子账户
|
|
234
|
+
// addAccountTransferAddress({
|
|
235
|
+
// terminal,
|
|
236
|
+
// account_id: spotAccountId,
|
|
237
|
+
// currency: 'USDT',
|
|
238
|
+
// network_id: subAccountNetworkId,
|
|
239
|
+
// address: '#main',
|
|
240
|
+
// onApply: {
|
|
241
|
+
// INIT: async (order) => {
|
|
242
|
+
// const transferResult = await postSubUserTransfer(credential, {
|
|
243
|
+
// 'sub-uid': +order.current_rx_address!,
|
|
244
|
+
// currency: 'usdt',
|
|
245
|
+
// amount: order.current_amount || order.expected_amount,
|
|
246
|
+
// type: 'master-transfer-out',
|
|
247
|
+
// });
|
|
248
|
+
// if (transferResult.status !== 'ok') {
|
|
249
|
+
// return { state: 'INIT' };
|
|
250
|
+
// }
|
|
251
|
+
// return { state: 'COMPLETE' };
|
|
252
|
+
// },
|
|
253
|
+
// },
|
|
254
|
+
// onEval: async (order) => {
|
|
255
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
256
|
+
// },
|
|
257
|
+
// });
|
|
258
|
+
// // 子账户 -> 主账户
|
|
259
|
+
// addAccountTransferAddress({
|
|
260
|
+
// terminal,
|
|
261
|
+
// account_id: spotSubAccountId,
|
|
262
|
+
// currency: 'USDT',
|
|
263
|
+
// network_id: subAccountNetworkId,
|
|
264
|
+
// address: `${subAccount.uid}`,
|
|
265
|
+
// onApply: {
|
|
266
|
+
// INIT: async (order) => {
|
|
267
|
+
// const transferResult = await postSubUserTransfer(credential, {
|
|
268
|
+
// 'sub-uid': +order.current_tx_address!,
|
|
269
|
+
// currency: 'usdt',
|
|
270
|
+
// amount: order.current_amount || order.expected_amount,
|
|
271
|
+
// type: 'master-transfer-in',
|
|
272
|
+
// });
|
|
273
|
+
// if (transferResult.status !== 'ok') {
|
|
274
|
+
// return { state: 'INIT' };
|
|
275
|
+
// }
|
|
276
|
+
// return { state: 'COMPLETE' };
|
|
277
|
+
// },
|
|
278
|
+
// },
|
|
279
|
+
// onEval: async (order) => {
|
|
280
|
+
// return { received_amount: order.current_amount || order.expected_amount, state: 'COMPLETE' };
|
|
281
|
+
// },
|
|
282
|
+
// });
|
|
283
|
+
// }
|
|
284
|
+
// };
|
|
285
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../src/__archived/transfer.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,gEAAgE;AAChE,WAAW;AACX,+BAA+B;AAC/B,oCAAoC;AACpC,8BAA8B;AAC9B,iBAAiB;AACjB,6BAA6B;AAC7B,yBAAyB;AACzB,sCAAsC;AACtC,uCAAuC;AACvC,kBAAkB;AAClB,8BAA8B;AAE9B,MAAM;AACN,wBAAwB;AACxB,MAAM;AACN,uDAAuD;AACvD,wBAAwB;AACxB,2BAA2B;AAC3B,6BAA6B;AAC7B,4BAA4B;AAC5B,SAAS;AACT,0BAA0B;AAC1B,cAAc;AACd,MAAM;AAEN,wFAAwF;AACxF,6FAA6F;AAE7F,uCAAuC;AACvC,kCAAkC;AAClC,kBAAkB;AAClB,mCAAmC;AACnC,0BAA0B;AAC1B,0BAA0B;AAC1B,6BAA6B;AAC7B,mBAAmB;AACnB,mCAAmC;AACnC,2FAA2F;AAC3F,kCAAkC;AAClC,kDAAkD;AAClD,kFAAkF;AAClF,wBAAwB;AACxB,iEAAiE;AACjE,cAAc;AACd,yDAAyD;AACzD,kDAAkD;AAClD,2DAA2D;AAC3D,gCAAgC;AAChC,wBAAwB;AACxB,kCAAkC;AAClC,gBAAgB;AAChB,sCAAsC;AACtC,kEAAkE;AAClE,cAAc;AACd,iEAAiE;AACjE,aAAa;AACb,sCAAsC;AACtC,6CAA6C;AAC7C,qEAAqE;AACrE,cAAc;AACd,oDAAoD;AACpD,sEAAsE;AACtE,gCAAgC;AAChC,gCAAgC;AAChC,+BAA+B;AAC/B,gBAAgB;AAChB,2EAA2E;AAC3E,yBAAyB;AACzB,+DAA+D;AAC/D,cAAc;AACd,qBAAqB;AACrB,iCAAiC;AACjC,oCAAoC;AACpC,eAAe;AACf,aAAa;AACb,WAAW;AACX,mCAAmC;AACnC,oEAAoE;AACpE,8BAA8B;AAC9B,6BAA6B;AAC7B,4BAA4B;AAC5B,cAAc;AAEd,yCAAyC;A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AA0B;AAC1B,yCAAyC;AACzC,sCAAsC;AACtC,mBAAmB;AACnB,mCAAmC;AACnC,2EAA2E;AAC3E,qDAAqD;AACrD,gCAAgC;AAChC,qEAAqE;AACrE,0CAA0C;AAC1C,gBAAgB;AAChB,kDAAkD;AAClD,wCAAwC;AACxC,cAAc;AACd,0CAA0C;AAC1C,aAAa;AACb,WAAW;AACX,mCAAmC;AACnC,wGAAwG;AACxG,WAAW;AACX,UAAU;AACV,MAAM;AACN,KAAK","sourcesContent":["// import { Terminal } from '@yuants/protocol';\n// import { addAccountTransferAddress } from '@yuants/transfer';\n// import {\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// */\n// export 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// */\n// export 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// */\n// export 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// */\n// export 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/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './interest_rate';
|
|
3
|
-
import './
|
|
4
|
-
import './quote';
|
|
1
|
+
import './services/exchange';
|
|
2
|
+
import './services/market-data/interest_rate';
|
|
3
|
+
import './services/market-data/quote';
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,54 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require("./account-actions-with-credentials");
|
|
7
|
-
const account_info_1 = require("./account-info");
|
|
8
|
-
const super_margin_1 = require("./accounts/super-margin");
|
|
9
|
-
const private_api_1 = require("./api/private-api");
|
|
10
|
-
require("./interest_rate");
|
|
11
|
-
const order_actions_1 = require("./order-actions");
|
|
12
|
-
require("./order-actions-with-credentials");
|
|
13
|
-
require("./quote");
|
|
14
|
-
const transfer_1 = require("./transfer");
|
|
15
|
-
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
16
|
-
const credential = (0, private_api_1.getDefaultCredential)();
|
|
17
|
-
(async () => {
|
|
18
|
-
var _a;
|
|
19
|
-
// 账户类型切换
|
|
20
|
-
const swapAccountTypeRes = await (0, private_api_1.getSwapUnifiedAccountType)(credential);
|
|
21
|
-
if (((_a = swapAccountTypeRes.data) === null || _a === void 0 ? void 0 : _a.account_type) === 1) {
|
|
22
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'SwitchingAccountType', `previous: ${swapAccountTypeRes.data.account_type}, switching to 2 (unified account)`);
|
|
23
|
-
const switchRes = await (0, private_api_1.postSwapSwitchAccountType)(credential, { account_type: 2 });
|
|
24
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'SwitchingAccountType', `current: ${switchRes.data.account_type}`);
|
|
25
|
-
}
|
|
26
|
-
const huobiUid = (await (0, private_api_1.getUid)(credential)).data;
|
|
27
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'UID', huobiUid);
|
|
28
|
-
const huobiAccounts = await (0, private_api_1.getAccount)(credential);
|
|
29
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'huobiAccount', JSON.stringify(huobiAccounts));
|
|
30
|
-
const account_id = `huobi/${huobiUid}`;
|
|
31
|
-
const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;
|
|
32
|
-
const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;
|
|
33
|
-
const SWAP_ACCOUNT_ID = `${account_id}/swap`;
|
|
34
|
-
const subUsersRes = await (0, private_api_1.getSubUserList)(credential);
|
|
35
|
-
const subAccounts = subUsersRes.data;
|
|
36
|
-
const isMainAccount = subUsersRes.ok;
|
|
37
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'subAccounts', JSON.stringify(subAccounts));
|
|
38
|
-
// 设置账户信息服务
|
|
39
|
-
(0, account_info_1.provideSwapAccountInfoService)(terminal, SWAP_ACCOUNT_ID, credential);
|
|
40
|
-
(0, data_account_1.provideAccountInfoService)(terminal, SUPER_MARGIN_ACCOUNT_ID, async () => (0, super_margin_1.getSuperMarginAccountInfo)(credential, SUPER_MARGIN_ACCOUNT_ID), { auto_refresh_interval: 1000 });
|
|
41
|
-
(0, account_info_1.provideSpotAccountInfoService)(terminal, SPOT_ACCOUNT_ID, credential);
|
|
42
|
-
// 设置账户市场关联
|
|
43
|
-
(0, data_account_1.addAccountMarket)(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'HUOBI/SPOT' });
|
|
44
|
-
(0, data_account_1.addAccountMarket)(terminal, { account_id: SUPER_MARGIN_ACCOUNT_ID, market_id: 'HUOBI/SUPER-MARGIN' });
|
|
45
|
-
(0, data_account_1.addAccountMarket)(terminal, { account_id: SWAP_ACCOUNT_ID, market_id: 'HUOBI/SWAP' });
|
|
46
|
-
// 设置订单提交服务
|
|
47
|
-
(0, order_actions_1.provideOrderSubmitService)(terminal, SWAP_ACCOUNT_ID, SUPER_MARGIN_ACCOUNT_ID, credential);
|
|
48
|
-
// 设置转账功能
|
|
49
|
-
await (0, transfer_1.setupTrc20WithdrawalAddresses)(terminal, SPOT_ACCOUNT_ID, credential, isMainAccount);
|
|
50
|
-
(0, transfer_1.setupSpotSuperMarginTransfer)(terminal, SPOT_ACCOUNT_ID, SUPER_MARGIN_ACCOUNT_ID, credential, huobiUid);
|
|
51
|
-
(0, transfer_1.setupSpotSwapTransfer)(terminal, SPOT_ACCOUNT_ID, SWAP_ACCOUNT_ID, credential, huobiUid);
|
|
52
|
-
(0, transfer_1.setupSubAccountTransfers)(terminal, SPOT_ACCOUNT_ID, credential, huobiUid, subAccounts, isMainAccount);
|
|
53
|
-
})();
|
|
3
|
+
require("./services/exchange");
|
|
4
|
+
require("./services/market-data/interest_rate");
|
|
5
|
+
require("./services/market-data/quote");
|
|
54
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,gDAA8C;AAC9C,wCAAsC","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
|
|
2
|
-
import { ICredential } from '
|
|
2
|
+
import { ICredential } from '../../api/private-api';
|
|
3
3
|
export declare const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
|
|
4
4
|
//# sourceMappingURL=spot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAoB,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAyB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI3E,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAiB1E,CAAC"}
|
|
@@ -2,24 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSpotAccountInfo = void 0;
|
|
4
4
|
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const private_api_1 = require("
|
|
5
|
+
const private_api_1 = require("../../api/private-api");
|
|
6
6
|
const uid_1 = require("../uid");
|
|
7
|
+
const utils_1 = require("@yuants/utils");
|
|
7
8
|
const getSpotAccountInfo = async (credential) => {
|
|
8
9
|
const spotAccountUid = await uid_1.spotAccountUidCache.query(JSON.stringify(credential));
|
|
9
10
|
if (!spotAccountUid)
|
|
10
11
|
throw new Error('Failed to get Spot Account UID');
|
|
11
12
|
const spotBalance = await (0, private_api_1.getSpotAccountBalance)(credential, spotAccountUid);
|
|
12
|
-
return spotBalance.data.list
|
|
13
|
+
return spotBalance.data.list
|
|
14
|
+
.map((v) => {
|
|
13
15
|
var _a, _b;
|
|
14
16
|
return (0, data_account_1.makeSpotPosition)({
|
|
15
17
|
position_id: `${v.currency}`,
|
|
16
18
|
datasource_id: 'HTX',
|
|
17
|
-
product_id:
|
|
19
|
+
product_id: (0, utils_1.encodePath)('HTX', 'SPOT', v.currency),
|
|
18
20
|
volume: +((_a = v.balance) !== null && _a !== void 0 ? _a : 0),
|
|
19
21
|
free_volume: +((_b = v.balance) !== null && _b !== void 0 ? _b : 0),
|
|
20
22
|
closable_price: 1, // TODO: 获取现货币对价格
|
|
21
23
|
});
|
|
22
|
-
})
|
|
24
|
+
})
|
|
25
|
+
.filter((x) => x.volume > 0);
|
|
23
26
|
};
|
|
24
27
|
exports.getSpotAccountInfo = getSpotAccountInfo;
|
|
25
28
|
//# sourceMappingURL=spot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AACxF,uDAA2E;AAC3E,gCAA6C;AAC7C,yCAA2C;AAEpC,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;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACT,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE;YAC5B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,IAAA,kBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;YACjD,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;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC,CAAC;AAjBW,QAAA,kBAAkB,sBAiB7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../../api/private-api';\nimport { spotAccountUidCache } from '../uid';\nimport { encodePath } from '@yuants/utils';\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\n .map((v) => {\n return makeSpotPosition({\n position_id: `${v.currency}`,\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SPOT', v.currency),\n volume: +(v.balance ?? 0),\n free_volume: +(v.balance ?? 0),\n closable_price: 1, // TODO: 获取现货币对价格\n });\n })\n .filter((x) => x.volume > 0);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"super-margin.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/super-margin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAyB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAS3E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,8BAA8B,CAAC,WAAW,CA+CjF,CAAC"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSuperMarginAccountInfo = void 0;
|
|
4
4
|
const cache_1 = require("@yuants/cache");
|
|
5
5
|
const utils_1 = require("@yuants/utils");
|
|
6
|
-
const private_api_1 = require("
|
|
7
|
-
const public_api_1 = require("
|
|
6
|
+
const private_api_1 = require("../../api/private-api");
|
|
7
|
+
const public_api_1 = require("../../api/public-api");
|
|
8
8
|
const uid_1 = require("../uid");
|
|
9
9
|
const spotTickCache = (0, cache_1.createCache)((currency) => (0, public_api_1.getSpotTick)({ symbol: `${currency}usdt` }), {
|
|
10
10
|
expire: 300000,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../../src/services/accounts/super-margin.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,uDAA2E;AAC3E,qDAAmD;AACnD,gCAAoD;AAEpD,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,wBAAW,EAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC,EAAE;IAC1F,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM,EAAE,aAAa;CAChC,CAAC,CAAC;AAEH;;GAEG;AACI,MAAM,yBAAyB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IACzG,sBAAsB;IACtB,MAAM,qBAAqB,GAAG,MAAM,gCAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACjG,IAAI,CAAC,qBAAqB;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACtF,MAAM,cAAc,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IACtF,MAAM,WAAW,GAAG,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAE,IAAI,KAAI,EAAE,CAAC;IAEpD,sCAAsC;IACtC,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,iBAAiB,GAAG,WAAW;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;SACpC,MAAM,CAAC,CAAC,GAAG,EA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C,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAmD,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGrG,eAAO,MAAM,kBAAkB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAiCrF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSwapAccountInfo = void 0;
|
|
4
|
+
const utils_1 = require("@yuants/utils");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const private_api_1 = require("../../api/private-api");
|
|
7
|
+
const product_1 = require("../product");
|
|
8
|
+
const getSwapAccountInfo = async (credential) => {
|
|
9
|
+
// balance
|
|
10
|
+
const balance = await (0, private_api_1.getUnifiedAccountInfo)(credential);
|
|
11
|
+
if (!balance.data) {
|
|
12
|
+
throw new Error('Failed to get unified account info');
|
|
13
|
+
}
|
|
14
|
+
const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');
|
|
15
|
+
if (!balanceData) {
|
|
16
|
+
throw new Error('No USDT balance found in unified account');
|
|
17
|
+
}
|
|
18
|
+
// positions
|
|
19
|
+
const positionsRes = await (0, private_api_1.getSwapCrossPositionInfo)(credential);
|
|
20
|
+
const mapProductIdToPerpetualProduct = await (0, rxjs_1.firstValueFrom)(product_1.productService.mapProductIdToProduct$);
|
|
21
|
+
const positions = (positionsRes.data || []).map((v) => {
|
|
22
|
+
const product_id = (0, utils_1.encodePath)('HTX', 'SWAP', v.contract_code);
|
|
23
|
+
const theProduct = mapProductIdToPerpetualProduct === null || mapProductIdToPerpetualProduct === void 0 ? void 0 : mapProductIdToPerpetualProduct.get(product_id);
|
|
24
|
+
const valuation = v.volume * v.last_price * ((theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) || 1);
|
|
25
|
+
return {
|
|
26
|
+
position_id: `${product_id}/${v.contract_type}/${v.direction}/${v.margin_mode}`,
|
|
27
|
+
datasource_id: 'HTX',
|
|
28
|
+
product_id,
|
|
29
|
+
direction: v.direction === 'buy' ? 'LONG' : 'SHORT',
|
|
30
|
+
volume: v.volume,
|
|
31
|
+
free_volume: v.available,
|
|
32
|
+
position_price: v.cost_hold,
|
|
33
|
+
closable_price: v.last_price,
|
|
34
|
+
floating_profit: v.profit_unreal,
|
|
35
|
+
valuation,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return positions;
|
|
39
|
+
};
|
|
40
|
+
exports.getSwapAccountInfo = getSwapAccountInfo;
|
|
41
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/services/accounts/swap.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,+BAAsC;AACtC,uDAAqG;AACrG,wCAA4C;AAErC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACxF,UAAU;IACV,MAAM,OAAO,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;IACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC;IACxE,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KA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IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { firstValueFrom } from 'rxjs';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../../api/private-api';\nimport { productService } from '../product';\n\nexport const getSwapAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');\n if (!balanceData) {\n throw new Error('No USDT balance found in unified account');\n }\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n const mapProductIdToPerpetualProduct = await firstValueFrom(productService.mapProductIdToProduct$);\n const positions: IPosition[] = (positionsRes.data || []).map((v): IPosition => {\n const product_id = encodePath('HTX', 'SWAP', v.contract_code);\n const theProduct = mapProductIdToPerpetualProduct?.get(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n return {\n position_id: `${product_id}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HTX',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n valuation,\n };\n });\n\n return positions;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":""}
|