@yuants/vendor-huobi 0.14.5 → 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 +14 -13
- package/temp/package-deps.json +31 -33
- 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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { distinct, filter, from, map, mergeMap, toArray } from 'rxjs';
|
|
3
|
+
// import { client } from './api';
|
|
4
|
+
// /**
|
|
5
|
+
// * 设置超级保证金账户的 WebSocket 订阅
|
|
6
|
+
// */
|
|
7
|
+
// export const setupSuperMarginWebSocketSubscriptions = (
|
|
8
|
+
// superMarginAccountBalance$: ReturnType<typeof getSuperMarginAccountBalance$>,
|
|
9
|
+
// subscriptions: Set<string>,
|
|
10
|
+
// ) => {
|
|
11
|
+
// from(client.spot_ws.connection$).subscribe(() => {
|
|
12
|
+
// subscriptions.clear();
|
|
13
|
+
// });
|
|
14
|
+
// // subscribe the symbols of positions we held
|
|
15
|
+
// superMarginAccountBalance$
|
|
16
|
+
// .pipe(
|
|
17
|
+
// //
|
|
18
|
+
// mergeMap((res) =>
|
|
19
|
+
// from(res?.list || []).pipe(
|
|
20
|
+
// filter((v) => v.currency !== 'usdt'),
|
|
21
|
+
// map((v) => v.currency),
|
|
22
|
+
// distinct(),
|
|
23
|
+
// toArray(),
|
|
24
|
+
// map((v) => new Set(v)),
|
|
25
|
+
// ),
|
|
26
|
+
// ),
|
|
27
|
+
// )
|
|
28
|
+
// .subscribe((v: Set<string>) => {
|
|
29
|
+
// const toUnsubscribe = [...subscriptions].filter((x) => !v.has(x));
|
|
30
|
+
// const toSubscribe = [...v].filter((x) => !subscriptions.has(x));
|
|
31
|
+
// for (const symbol of toUnsubscribe) {
|
|
32
|
+
// client.spot_ws.output$.next({
|
|
33
|
+
// unsub: `market.${symbol}usdt.ticker`,
|
|
34
|
+
// });
|
|
35
|
+
// subscriptions.delete(symbol);
|
|
36
|
+
// }
|
|
37
|
+
// for (const symbol of toSubscribe) {
|
|
38
|
+
// client.spot_ws.output$.next({
|
|
39
|
+
// sub: `market.${symbol}usdt.ticker`,
|
|
40
|
+
// });
|
|
41
|
+
// subscriptions.add(symbol);
|
|
42
|
+
// }
|
|
43
|
+
// });
|
|
44
|
+
// };
|
|
45
|
+
//# sourceMappingURL=account-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-info.js","sourceRoot":"","sources":["../../src/__archived/account-info.ts"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,kCAAkC;AAElC,MAAM;AACN,6BAA6B;AAC7B,MAAM;AACN,0DAA0D;AAC1D,kFAAkF;AAClF,gCAAgC;AAChC,SAAS;AACT,uDAAuD;AACvD,6BAA6B;AAC7B,QAAQ;AACR,kDAAkD;AAClD,+BAA+B;AAC/B,aAAa;AACb,WAAW;AACX,0BAA0B;AAC1B,sCAAsC;AACtC,kDAAkD;AAClD,oCAAoC;AACpC,wBAAwB;AACxB,uBAAuB;AACvB,oCAAoC;AACpC,aAAa;AACb,WAAW;AACX,QAAQ;AACR,uCAAuC;AACvC,2EAA2E;AAC3E,yEAAyE;AAEzE,8CAA8C;AAC9C,wCAAwC;AACxC,kDAAkD;AAClD,cAAc;AACd,wCAAwC;AACxC,UAAU;AACV,4CAA4C;AAC5C,wCAAwC;AACxC,gDAAgD;AAChD,cAAc;AACd,qCAAqC;AACrC,UAAU;AACV,UAAU;AACV,KAAK","sourcesContent":["// import { distinct, filter, from, map, mergeMap, toArray } from 'rxjs';\n// import { client } from './api';\n\n// /**\n// * 设置超级保证金账户的 WebSocket 订阅\n// */\n// export 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"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { IConnection, createConnectionWs } from '@yuants/protocol';
|
|
3
|
+
// import { Subject, filter, from, map, share, tap } from 'rxjs';
|
|
4
|
+
// import zlib from 'zlib';
|
|
5
|
+
// import { ICredential } from './api/private-api';
|
|
6
|
+
// interface IHuobiParams {
|
|
7
|
+
// auth: ICredential;
|
|
8
|
+
// }
|
|
9
|
+
// const createConnectionGzipWS = <T = any>(URL: string): IConnection<T> => {
|
|
10
|
+
// const conn = createConnectionWs(URL);
|
|
11
|
+
// const input$ = from(conn.input$).pipe(
|
|
12
|
+
// map((msg) => zlib.gunzipSync(msg)),
|
|
13
|
+
// map((msg) => msg.toString()),
|
|
14
|
+
// map((msg) => JSON.parse(msg)),
|
|
15
|
+
// share(),
|
|
16
|
+
// );
|
|
17
|
+
// const output$ = new Subject<any>();
|
|
18
|
+
// output$.pipe(map((msg) => JSON.stringify(msg))).subscribe(conn.output$);
|
|
19
|
+
// return {
|
|
20
|
+
// ...conn,
|
|
21
|
+
// input$: input$,
|
|
22
|
+
// output$: output$,
|
|
23
|
+
// };
|
|
24
|
+
// };
|
|
25
|
+
// export class HuobiClient {
|
|
26
|
+
// // https://www.htx.com/zh-cn/opend/newApiPages/?id=510
|
|
27
|
+
// swap_api_root = 'api.hbdm.com';
|
|
28
|
+
// // https://www.htx.com/zh-cn/opend/newApiPages/?id=404
|
|
29
|
+
// spot_api_root = 'api.huobi.pro';
|
|
30
|
+
// spot_ws: IConnection<any>;
|
|
31
|
+
// constructor(public params: IHuobiParams) {
|
|
32
|
+
// this.spot_ws = createConnectionGzipWS(`wss://${this.spot_api_root}/ws`);
|
|
33
|
+
// from(this.spot_ws.input$)
|
|
34
|
+
// .pipe(
|
|
35
|
+
// //
|
|
36
|
+
// filter((v) => v.ping),
|
|
37
|
+
// tap((v) => {
|
|
38
|
+
// this.spot_ws.output$.next({ pong: v.ping });
|
|
39
|
+
// }),
|
|
40
|
+
// )
|
|
41
|
+
// .subscribe();
|
|
42
|
+
// }
|
|
43
|
+
// // swap_ws = new WebSocket(new URL(`wss://${this.swap_api_root}/linear-swap-ws`));
|
|
44
|
+
// }
|
|
45
|
+
// export const client = new HuobiClient({
|
|
46
|
+
// auth: {
|
|
47
|
+
// access_key: process.env.ACCESS_KEY!,
|
|
48
|
+
// secret_key: process.env.SECRET_KEY!,
|
|
49
|
+
// },
|
|
50
|
+
// });
|
|
51
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/__archived/api.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,iEAAiE;AACjE,2BAA2B;AAC3B,mDAAmD;AAEnD,2BAA2B;AAC3B,uBAAuB;AACvB,IAAI;AAEJ,6EAA6E;AAC7E,0CAA0C;AAC1C,2CAA2C;AAC3C,0CAA0C;AAC1C,oCAAoC;AACpC,qCAAqC;AACrC,eAAe;AACf,OAAO;AAEP,wCAAwC;AACxC,6EAA6E;AAC7E,aAAa;AACb,eAAe;AACf,sBAAsB;AACtB,wBAAwB;AACxB,OAAO;AACP,KAAK;AAEL,6BAA6B;AAC7B,2DAA2D;AAC3D,oCAAoC;AACpC,2DAA2D;AAC3D,qCAAqC;AAErC,+BAA+B;AAE/B,+CAA+C;AAC/C,+EAA+E;AAC/E,gCAAgC;AAChC,eAAe;AACf,aAAa;AACb,iCAAiC;AACjC,uBAAuB;AACvB,yDAAyD;AACzD,cAAc;AACd,UAAU;AACV,sBAAsB;AACtB,MAAM;AAEN,uFAAuF;AACvF,IAAI;AAEJ,0CAA0C;AAC1C,YAAY;AACZ,2CAA2C;AAC3C,2CAA2C;AAC3C,OAAO;AACP,MAAM","sourcesContent":["// import { IConnection, createConnectionWs } from '@yuants/protocol';\n// import { Subject, filter, from, map, share, tap } from 'rxjs';\n// import zlib from 'zlib';\n// import { ICredential } from './api/private-api';\n\n// interface IHuobiParams {\n// auth: ICredential;\n// }\n\n// const createConnectionGzipWS = <T = any>(URL: string): IConnection<T> => {\n// const conn = createConnectionWs(URL);\n// const input$ = from(conn.input$).pipe(\n// map((msg) => zlib.gunzipSync(msg)),\n// map((msg) => msg.toString()),\n// map((msg) => JSON.parse(msg)),\n// share(),\n// );\n\n// const output$ = new Subject<any>();\n// output$.pipe(map((msg) => JSON.stringify(msg))).subscribe(conn.output$);\n// return {\n// ...conn,\n// input$: input$,\n// output$: output$,\n// };\n// };\n\n// export class HuobiClient {\n// // https://www.htx.com/zh-cn/opend/newApiPages/?id=510\n// swap_api_root = 'api.hbdm.com';\n// // https://www.htx.com/zh-cn/opend/newApiPages/?id=404\n// spot_api_root = 'api.huobi.pro';\n\n// spot_ws: IConnection<any>;\n\n// constructor(public params: IHuobiParams) {\n// this.spot_ws = createConnectionGzipWS(`wss://${this.spot_api_root}/ws`);\n// from(this.spot_ws.input$)\n// .pipe(\n// //\n// filter((v) => v.ping),\n// tap((v) => {\n// this.spot_ws.output$.next({ pong: v.ping });\n// }),\n// )\n// .subscribe();\n// }\n\n// // swap_ws = new WebSocket(new URL(`wss://${this.swap_api_root}/linear-swap-ws`));\n// }\n\n// export const client = new HuobiClient({\n// auth: {\n// access_key: process.env.ACCESS_KEY!,\n// secret_key: process.env.SECRET_KEY!,\n// },\n// });\n"]}
|
|
@@ -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;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C,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/dist/index.js
CHANGED
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import './account-actions-with-credentials';
|
|
5
|
-
import { provideSpotAccountInfoService, provideSwapAccountInfoService } from './account-info';
|
|
6
|
-
import { getSuperMarginAccountInfo } from './accounts/super-margin';
|
|
7
|
-
import { getAccount, getDefaultCredential, getSubUserList, getSwapUnifiedAccountType, getUid, postSwapSwitchAccountType, } from './api/private-api';
|
|
8
|
-
import './interest_rate';
|
|
9
|
-
import { provideOrderSubmitService } from './order-actions';
|
|
10
|
-
import './order-actions-with-credentials';
|
|
11
|
-
import './quote';
|
|
12
|
-
import { setupSpotSuperMarginTransfer, setupSpotSwapTransfer, setupSubAccountTransfers, setupTrc20WithdrawalAddresses, } from './transfer';
|
|
13
|
-
const terminal = Terminal.fromNodeEnv();
|
|
14
|
-
const credential = getDefaultCredential();
|
|
15
|
-
(async () => {
|
|
16
|
-
var _a;
|
|
17
|
-
// 账户类型切换
|
|
18
|
-
const swapAccountTypeRes = await getSwapUnifiedAccountType(credential);
|
|
19
|
-
if (((_a = swapAccountTypeRes.data) === null || _a === void 0 ? void 0 : _a.account_type) === 1) {
|
|
20
|
-
console.info(formatTime(Date.now()), 'SwitchingAccountType', `previous: ${swapAccountTypeRes.data.account_type}, switching to 2 (unified account)`);
|
|
21
|
-
const switchRes = await postSwapSwitchAccountType(credential, { account_type: 2 });
|
|
22
|
-
console.info(formatTime(Date.now()), 'SwitchingAccountType', `current: ${switchRes.data.account_type}`);
|
|
23
|
-
}
|
|
24
|
-
const huobiUid = (await getUid(credential)).data;
|
|
25
|
-
console.info(formatTime(Date.now()), 'UID', huobiUid);
|
|
26
|
-
const huobiAccounts = await getAccount(credential);
|
|
27
|
-
console.info(formatTime(Date.now()), 'huobiAccount', JSON.stringify(huobiAccounts));
|
|
28
|
-
const account_id = `huobi/${huobiUid}`;
|
|
29
|
-
const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;
|
|
30
|
-
const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;
|
|
31
|
-
const SWAP_ACCOUNT_ID = `${account_id}/swap`;
|
|
32
|
-
const subUsersRes = await getSubUserList(credential);
|
|
33
|
-
const subAccounts = subUsersRes.data;
|
|
34
|
-
const isMainAccount = subUsersRes.ok;
|
|
35
|
-
console.info(formatTime(Date.now()), 'subAccounts', JSON.stringify(subAccounts));
|
|
36
|
-
// 设置账户信息服务
|
|
37
|
-
provideSwapAccountInfoService(terminal, SWAP_ACCOUNT_ID, credential);
|
|
38
|
-
provideAccountInfoService(terminal, SUPER_MARGIN_ACCOUNT_ID, async () => getSuperMarginAccountInfo(credential, SUPER_MARGIN_ACCOUNT_ID), { auto_refresh_interval: 1000 });
|
|
39
|
-
provideSpotAccountInfoService(terminal, SPOT_ACCOUNT_ID, credential);
|
|
40
|
-
// 设置账户市场关联
|
|
41
|
-
addAccountMarket(terminal, { account_id: SPOT_ACCOUNT_ID, market_id: 'HUOBI/SPOT' });
|
|
42
|
-
addAccountMarket(terminal, { account_id: SUPER_MARGIN_ACCOUNT_ID, market_id: 'HUOBI/SUPER-MARGIN' });
|
|
43
|
-
addAccountMarket(terminal, { account_id: SWAP_ACCOUNT_ID, market_id: 'HUOBI/SWAP' });
|
|
44
|
-
// 设置订单提交服务
|
|
45
|
-
provideOrderSubmitService(terminal, SWAP_ACCOUNT_ID, SUPER_MARGIN_ACCOUNT_ID, credential);
|
|
46
|
-
// 设置转账功能
|
|
47
|
-
await setupTrc20WithdrawalAddresses(terminal, SPOT_ACCOUNT_ID, credential, isMainAccount);
|
|
48
|
-
setupSpotSuperMarginTransfer(terminal, SPOT_ACCOUNT_ID, SUPER_MARGIN_ACCOUNT_ID, credential, huobiUid);
|
|
49
|
-
setupSpotSwapTransfer(terminal, SPOT_ACCOUNT_ID, SWAP_ACCOUNT_ID, credential, huobiUid);
|
|
50
|
-
setupSubAccountTransfers(terminal, SPOT_ACCOUNT_ID, credential, huobiUid, subAccounts, isMainAccount);
|
|
51
|
-
})();
|
|
1
|
+
import './services/exchange';
|
|
2
|
+
import './services/market-data/interest_rate';
|
|
3
|
+
import './services/market-data/quote';
|
|
52
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\n"]}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { makeSpotPosition } from '@yuants/data-account';
|
|
2
|
-
import { getSpotAccountBalance } from '
|
|
2
|
+
import { getSpotAccountBalance } from '../../api/private-api';
|
|
3
3
|
import { spotAccountUidCache } from '../uid';
|
|
4
|
+
import { encodePath } from '@yuants/utils';
|
|
4
5
|
export const getSpotAccountInfo = async (credential) => {
|
|
5
6
|
const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));
|
|
6
7
|
if (!spotAccountUid)
|
|
7
8
|
throw new Error('Failed to get Spot Account UID');
|
|
8
9
|
const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);
|
|
9
|
-
return spotBalance.data.list
|
|
10
|
+
return spotBalance.data.list
|
|
11
|
+
.map((v) => {
|
|
10
12
|
var _a, _b;
|
|
11
13
|
return makeSpotPosition({
|
|
12
14
|
position_id: `${v.currency}`,
|
|
13
15
|
datasource_id: 'HTX',
|
|
14
|
-
product_id:
|
|
16
|
+
product_id: encodePath('HTX', 'SPOT', v.currency),
|
|
15
17
|
volume: +((_a = v.balance) !== null && _a !== void 0 ? _a : 0),
|
|
16
18
|
free_volume: +((_b = v.balance) !== null && _b !== void 0 ? _b : 0),
|
|
17
19
|
closable_price: 1, // TODO: 获取现货币对价格
|
|
18
20
|
});
|
|
19
|
-
})
|
|
21
|
+
})
|
|
22
|
+
.filter((x) => x.volume > 0);
|
|
20
23
|
};
|
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C,CAAC,CAAC;AACjC,CAAC,CAAC","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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createCache } from '@yuants/cache';
|
|
2
2
|
import { formatTime } from '@yuants/utils';
|
|
3
|
-
import { getSpotAccountBalance } from '
|
|
4
|
-
import { getSpotTick } from '
|
|
3
|
+
import { getSpotAccountBalance } from '../../api/private-api';
|
|
4
|
+
import { getSpotTick } from '../../api/public-api';
|
|
5
5
|
import { superMarginAccountUidCache } from '../uid';
|
|
6
6
|
const spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {
|
|
7
7
|
expire: 300000,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../../src/services/accounts/super-margin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAe,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CA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C,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,UAAU,CAAC,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","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,37 @@
|
|
|
1
|
+
import { encodePath } from '@yuants/utils';
|
|
2
|
+
import { firstValueFrom } from 'rxjs';
|
|
3
|
+
import { getSwapCrossPositionInfo, getUnifiedAccountInfo } from '../../api/private-api';
|
|
4
|
+
import { productService } from '../product';
|
|
5
|
+
export const getSwapAccountInfo = async (credential) => {
|
|
6
|
+
// balance
|
|
7
|
+
const balance = await getUnifiedAccountInfo(credential);
|
|
8
|
+
if (!balance.data) {
|
|
9
|
+
throw new Error('Failed to get unified account info');
|
|
10
|
+
}
|
|
11
|
+
const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');
|
|
12
|
+
if (!balanceData) {
|
|
13
|
+
throw new Error('No USDT balance found in unified account');
|
|
14
|
+
}
|
|
15
|
+
// positions
|
|
16
|
+
const positionsRes = await getSwapCrossPositionInfo(credential);
|
|
17
|
+
const mapProductIdToPerpetualProduct = await firstValueFrom(productService.mapProductIdToProduct$);
|
|
18
|
+
const positions = (positionsRes.data || []).map((v) => {
|
|
19
|
+
const product_id = encodePath('HTX', 'SWAP', v.contract_code);
|
|
20
|
+
const theProduct = mapProductIdToPerpetualProduct === null || mapProductIdToPerpetualProduct === void 0 ? void 0 : mapProductIdToPerpetualProduct.get(product_id);
|
|
21
|
+
const valuation = v.volume * v.last_price * ((theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) || 1);
|
|
22
|
+
return {
|
|
23
|
+
position_id: `${product_id}/${v.contract_type}/${v.direction}/${v.margin_mode}`,
|
|
24
|
+
datasource_id: 'HTX',
|
|
25
|
+
product_id,
|
|
26
|
+
direction: v.direction === 'buy' ? 'LONG' : 'SHORT',
|
|
27
|
+
volume: v.volume,
|
|
28
|
+
free_volume: v.available,
|
|
29
|
+
position_price: v.cost_hold,
|
|
30
|
+
closable_price: v.last_price,
|
|
31
|
+
floating_profit: v.profit_unreal,
|
|
32
|
+
valuation,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
return positions;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/services/accounts/swap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAA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AO;YACL,WAAW,EAAE,GAAG,UAAU,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,EAAE;YAC/E,aAAa,EAAE,KAAK;YACpB,UAAU;YACV,SAAS,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;YACnD,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,WAAW,EAAE,CAAC,CAAC,SAAS;YACxB,cAAc,EAAE,CAAC,CAAC,SAAS;YAC3B,cAAc,EAAE,CAAC,CAAC,UAAU;YAC5B,eAAe,EAAE,CAAC,CAAC,aAAa;YAChC,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { 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"]}
|