@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,75 @@
|
|
|
1
|
+
import { provideExchangeServices } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { decodePath, encodePath, newError } from '@yuants/utils';
|
|
4
|
+
import { getUid } from '../api/private-api';
|
|
5
|
+
import { getSpotAccountInfo } from './accounts/spot';
|
|
6
|
+
import { getSuperMarginAccountInfo } from './accounts/super-margin';
|
|
7
|
+
import { getSwapAccountInfo } from './accounts/swap';
|
|
8
|
+
import { listSwapOrders } from './orders/listOrders';
|
|
9
|
+
import { submitOrder } from './orders/submitOrder';
|
|
10
|
+
import { listProducts } from './product';
|
|
11
|
+
const terminal = Terminal.fromNodeEnv();
|
|
12
|
+
provideExchangeServices(terminal, {
|
|
13
|
+
name: 'HTX',
|
|
14
|
+
credentialSchema: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
required: ['access_key', 'secret_key'],
|
|
17
|
+
properties: {
|
|
18
|
+
access_key: { type: 'string' },
|
|
19
|
+
secret_key: { type: 'string' },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
getCredentialId: async (credential) => {
|
|
23
|
+
const res = await getUid(credential);
|
|
24
|
+
return encodePath('HTX', res.data);
|
|
25
|
+
},
|
|
26
|
+
listProducts,
|
|
27
|
+
getPositions: async (credential) => {
|
|
28
|
+
const [swap, spot, superMargin] = await Promise.all([
|
|
29
|
+
getSwapAccountInfo(credential),
|
|
30
|
+
getSpotAccountInfo(credential, 'spot'),
|
|
31
|
+
getSuperMarginAccountInfo(credential, 'super-margin'),
|
|
32
|
+
]);
|
|
33
|
+
return [...swap, ...spot, ...superMargin];
|
|
34
|
+
},
|
|
35
|
+
getOrders: async (credential) => {
|
|
36
|
+
const swapOrders = await listSwapOrders(credential);
|
|
37
|
+
return swapOrders;
|
|
38
|
+
},
|
|
39
|
+
submitOrder,
|
|
40
|
+
cancelOrder: async (credential, order) => {
|
|
41
|
+
throw new Error('Not Implemented');
|
|
42
|
+
},
|
|
43
|
+
modifyOrder: async (credential, order) => {
|
|
44
|
+
throw new Error('Not Implemented');
|
|
45
|
+
},
|
|
46
|
+
getPositionsByProductId: async (credential, product_id) => {
|
|
47
|
+
const [, instType] = decodePath(product_id);
|
|
48
|
+
if (instType === 'SPOT') {
|
|
49
|
+
const positions = await getSpotAccountInfo(credential, product_id);
|
|
50
|
+
return positions.filter((pos) => pos.product_id === product_id);
|
|
51
|
+
}
|
|
52
|
+
if (instType === 'SWAP') {
|
|
53
|
+
const positions = await getSwapAccountInfo(credential);
|
|
54
|
+
return positions.filter((pos) => pos.product_id === product_id);
|
|
55
|
+
}
|
|
56
|
+
if (instType === 'SUPER-MARGIN') {
|
|
57
|
+
const positions = await getSuperMarginAccountInfo(credential, product_id);
|
|
58
|
+
return positions.filter((pos) => pos.product_id === product_id);
|
|
59
|
+
}
|
|
60
|
+
throw newError('UnsupportedProductId', { product_id });
|
|
61
|
+
},
|
|
62
|
+
getOrdersByProductId: async (credential, product_id) => {
|
|
63
|
+
const [, instType] = decodePath(product_id);
|
|
64
|
+
// if (instType === 'SPOT') {
|
|
65
|
+
// const orders = await listSpotOrders(credential, product_id);
|
|
66
|
+
// return orders.filter((order) => order.product_id === product_id);
|
|
67
|
+
// }
|
|
68
|
+
if (instType === 'SWAP') {
|
|
69
|
+
const orders = await listSwapOrders(credential);
|
|
70
|
+
return orders.filter((order) => order.product_id === product_id);
|
|
71
|
+
}
|
|
72
|
+
throw newError('UnsupportedProductId', { product_id });
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=exchange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAe,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YA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,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,MAAM,QAAQ,CAAC,sBAAsB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACzD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, encodePath, newError } from '@yuants/utils';\nimport { ICredential, getUid } from '../api/private-api';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getSuperMarginAccountInfo } from './accounts/super-margin';\nimport { getSwapAccountInfo } from './accounts/swap';\nimport { listSwapOrders } from './orders/listOrders';\nimport { submitOrder } from './orders/submitOrder';\nimport { listProducts } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'HTX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId: async (credential) => {\n const res = await getUid(credential);\n return encodePath('HTX', res.data);\n },\n listProducts,\n getPositions: async (credential) => {\n const [swap, spot, superMargin] = await Promise.all([\n getSwapAccountInfo(credential),\n getSpotAccountInfo(credential, 'spot'),\n getSuperMarginAccountInfo(credential, 'super-margin'),\n ]);\n return [...swap, ...spot, ...superMargin];\n },\n getOrders: async (credential) => {\n const swapOrders = await listSwapOrders(credential);\n return swapOrders;\n },\n submitOrder,\n cancelOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n modifyOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n getPositionsByProductId: async (credential, product_id) => {\n const [, instType] = decodePath(product_id);\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SWAP') {\n const positions = await getSwapAccountInfo(credential);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SUPER-MARGIN') {\n const positions = await getSuperMarginAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n getOrdersByProductId: async (credential: ICredential, product_id: string): Promise<IOrder[]> => {\n const [, instType] = decodePath(product_id);\n // if (instType === 'SPOT') {\n // const orders = await listSpotOrders(credential, product_id);\n // return orders.filter((order) => order.product_id === product_id);\n // }\n if (instType === 'SWAP') {\n const orders = await listSwapOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n});\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
2
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
5
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
6
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
7
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
8
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
9
|
+
function fulfill(value) { resume("next", value); }
|
|
10
|
+
function reject(value) { resume("throw", value); }
|
|
11
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
12
|
+
};
|
|
13
|
+
import { createSeriesProvider } from '@yuants/data-series';
|
|
14
|
+
import { Terminal } from '@yuants/protocol';
|
|
15
|
+
import { decodePath, formatTime, newError } from '@yuants/utils';
|
|
16
|
+
import { firstValueFrom, timer } from 'rxjs';
|
|
17
|
+
import { getSwapHistoricalFundingRate } from '../../api/public-api';
|
|
18
|
+
createSeriesProvider(Terminal.fromNodeEnv(), {
|
|
19
|
+
tableName: 'interest_rate',
|
|
20
|
+
series_id_prefix_parts: ['HTX'],
|
|
21
|
+
reversed: true,
|
|
22
|
+
serviceOptions: { concurrent: 10 },
|
|
23
|
+
queryFn: function ({ series_id, started_at }) {
|
|
24
|
+
return __asyncGenerator(this, arguments, function* () {
|
|
25
|
+
const [datasource_id, product_id] = decodePath(series_id);
|
|
26
|
+
const [, instType] = decodePath(product_id);
|
|
27
|
+
if (instType === 'SWAP') {
|
|
28
|
+
let current_page = 0;
|
|
29
|
+
let total_page = 1;
|
|
30
|
+
while (true) {
|
|
31
|
+
// 向前翻页,时间降序
|
|
32
|
+
const res = yield __await(getSwapHistoricalFundingRate({
|
|
33
|
+
contract_code: product_id,
|
|
34
|
+
page_index: current_page,
|
|
35
|
+
}));
|
|
36
|
+
if (res.status !== 'ok') {
|
|
37
|
+
throw `API failed: ${res.status}`;
|
|
38
|
+
}
|
|
39
|
+
if (res.data.data.length === 0)
|
|
40
|
+
break;
|
|
41
|
+
yield yield __await(res.data.data.map((v) => ({
|
|
42
|
+
series_id,
|
|
43
|
+
datasource_id,
|
|
44
|
+
product_id,
|
|
45
|
+
created_at: formatTime(+v.funding_time),
|
|
46
|
+
long_rate: `${-v.funding_rate}`,
|
|
47
|
+
short_rate: `${v.funding_rate}`,
|
|
48
|
+
settlement_price: '',
|
|
49
|
+
})));
|
|
50
|
+
total_page = res.data.total_page;
|
|
51
|
+
current_page++;
|
|
52
|
+
if (current_page >= total_page)
|
|
53
|
+
break;
|
|
54
|
+
if (+res.data.data[res.data.data.length - 1].funding_time <= started_at)
|
|
55
|
+
break;
|
|
56
|
+
yield __await(firstValueFrom(timer(1000)));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw newError('UNSUPPORTED_INST_TYPE', { instType });
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=interest_rate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/market-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEpE,oBAAoB,CAAgB,QAAQ,CAAC,WAAW,EAAE,EAAE;IAC1D,SAAS,EAAE,eAAe;IAC1B,sBAAsB,EAAE,CAAC,KAAK,CAAC;IAC/B,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;IAClC,OAAO,EAAE,UAAiB,EAAE,SAAS,EAAE,UAAU,EAAE;;YACjD,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1D,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;YAE5C,IAAI,QAAQ,KAAK,MAAM,EAAE;gBACvB,IAAI,YAAY,GAAG,CAAC,CAAC;gBACrB,IAAI,UAAU,GAAG,CAAC,CAAC;gBACnB,OAAO,IAAI,EAAE;oBACX,YAAY;oBACZ,MAAM,GAAG,GAAG,cAAM,4BAA4B,CAAC;wBAC7C,aAAa,EAAE,UAAU;wBACzB,UAAU,EAAE,YAAY;qBACzB,CAAC,CAAA,CAAC;oBACH,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE;wBACvB,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,CAAC;qBACnC;oBACD,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;wBAAE,MAAM;oBACtC,oBAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACrB,CAAC,CAAC,EAAiB,EAAE,CAAC,CAAC;wBACrB,SAAS;wBACT,aAAa;wBACb,UAAU;wBACV,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;wBACvC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,YAAY,EAAE;wBAC/B,UAAU,EAAE,GAAG,CAAC,CAAC,YAAY,EAAE;wBAC/B,gBAAgB,EAAE,EAAE;qBACrB,CAAC,CACH,CAAA,CAAC;oBACF,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC;oBACjC,YAAY,EAAE,CAAC;oBACf,IAAI,YAAY,IAAI,UAAU;wBAAE,MAAM;oBACtC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU;wBAAE,MAAM;oBAC/E,cAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;YACD,MAAM,QAAQ,CAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime, newError } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getSwapHistoricalFundingRate } from '../../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['HTX'],\n reversed: true,\n serviceOptions: { concurrent: 10 },\n queryFn: async function* ({ series_id, started_at }) {\n const [datasource_id, product_id] = decodePath(series_id);\n const [, instType] = decodePath(product_id);\n\n if (instType === 'SWAP') {\n let current_page = 0;\n let total_page = 1;\n while (true) {\n // 向前翻页,时间降序\n const res = await getSwapHistoricalFundingRate({\n contract_code: product_id,\n page_index: current_page,\n });\n if (res.status !== 'ok') {\n throw `API failed: ${res.status}`;\n }\n if (res.data.data.length === 0) break;\n yield res.data.data.map(\n (v): IInterestRate => ({\n series_id,\n datasource_id,\n product_id,\n created_at: formatTime(+v.funding_time),\n long_rate: `${-v.funding_rate}`,\n short_rate: `${v.funding_rate}`,\n settlement_price: '',\n }),\n );\n total_page = res.data.total_page;\n current_page++;\n if (current_page >= total_page) break;\n if (+res.data.data[res.data.data.length - 1].funding_time <= started_at) break;\n await firstValueFrom(timer(1000));\n }\n }\n throw newError('UNSUPPORTED_INST_TYPE', { instType });\n },\n});\n"]}
|
|
@@ -2,14 +2,14 @@ import { Terminal } from '@yuants/protocol';
|
|
|
2
2
|
import { writeToSQL } from '@yuants/sql';
|
|
3
3
|
import { encodePath, formatTime } from '@yuants/utils';
|
|
4
4
|
import { defer, from, groupBy, map, merge, mergeMap, repeat, retry, scan, shareReplay, toArray } from 'rxjs';
|
|
5
|
-
import { getSwapBatchFundingRate, getSwapMarketBbo, getSwapMarketTrade, getSwapOpenInterest, } from '
|
|
5
|
+
import { getSwapBatchFundingRate, getSwapMarketBbo, getSwapMarketTrade, getSwapOpenInterest, } from '../../api/public-api';
|
|
6
6
|
const swapBboTick$ = defer(() => getSwapMarketBbo({})).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
7
7
|
const quote1$ = swapBboTick$.pipe(mergeMap((res) => res.ticks || []), map((tick) => {
|
|
8
8
|
const [ask_price = '', ask_volume = ''] = tick.ask || [];
|
|
9
9
|
const [bid_price = '', bid_volume = ''] = tick.bid || [];
|
|
10
10
|
return {
|
|
11
|
-
datasource_id: '
|
|
12
|
-
product_id: tick.contract_code,
|
|
11
|
+
datasource_id: 'HTX',
|
|
12
|
+
product_id: encodePath('HTX', 'SWAP', tick.contract_code),
|
|
13
13
|
ask_price: `${ask_price}`,
|
|
14
14
|
bid_price: `${bid_price}`,
|
|
15
15
|
ask_volume: `${ask_volume}`,
|
|
@@ -19,15 +19,15 @@ const quote1$ = swapBboTick$.pipe(mergeMap((res) => res.ticks || []), map((tick)
|
|
|
19
19
|
const mapSwapContractCodeToBboTick$ = defer(() => swapBboTick$).pipe(mergeMap((res) => from(res.ticks).pipe(map((tick) => [tick.contract_code, tick]), toArray(), map((ticks) => Object.fromEntries(ticks)))), repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
20
20
|
const swapTradeTick$ = defer(() => getSwapMarketTrade({})).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
21
21
|
const quote2$ = swapTradeTick$.pipe(mergeMap((res) => { var _a; return ((_a = res.tick) === null || _a === void 0 ? void 0 : _a.data) || []; }), map((tick) => ({
|
|
22
|
-
datasource_id: '
|
|
23
|
-
product_id: tick.contract_code,
|
|
22
|
+
datasource_id: 'HTX',
|
|
23
|
+
product_id: encodePath('HTX', 'SWAP', tick.contract_code),
|
|
24
24
|
last_price: `${tick.price}`,
|
|
25
25
|
})));
|
|
26
26
|
const mapSwapContractCodeToTradeTick$ = defer(() => swapTradeTick$).pipe(mergeMap((res) => from(res.tick.data).pipe(map((tick) => [tick.contract_code, tick]), toArray(), map((ticks) => Object.fromEntries(ticks)))), repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
27
27
|
const swapFundingRateTick$ = defer(() => getSwapBatchFundingRate({})).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
28
28
|
const quote3$ = swapFundingRateTick$.pipe(mergeMap((res) => res.data || []), map((tick) => ({
|
|
29
|
-
datasource_id: '
|
|
30
|
-
product_id: tick.contract_code,
|
|
29
|
+
datasource_id: 'HTX',
|
|
30
|
+
product_id: encodePath('HTX', 'SWAP', tick.contract_code),
|
|
31
31
|
interest_rate_long: `${-tick.funding_rate}`,
|
|
32
32
|
interest_rate_short: `${tick.funding_rate}`,
|
|
33
33
|
interest_rate_next_settled_at: formatTime(+tick.funding_time),
|
|
@@ -35,8 +35,8 @@ const quote3$ = swapFundingRateTick$.pipe(mergeMap((res) => res.data || []), map
|
|
|
35
35
|
const mapSwapContractCodeToFundingRateTick$ = defer(() => swapFundingRateTick$).pipe(mergeMap((res) => from(res.data).pipe(map((tick) => [tick.contract_code, tick]), toArray(), map((ticks) => Object.fromEntries(ticks)))), repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
36
36
|
const swapOpenInterest$ = defer(() => getSwapOpenInterest({})).pipe(repeat({ delay: 1000 }), retry({ delay: 1000 }), shareReplay(1));
|
|
37
37
|
const quote4$ = swapOpenInterest$.pipe(mergeMap((res) => res.data || []), map((tick) => ({
|
|
38
|
-
datasource_id: '
|
|
39
|
-
product_id: tick.contract_code,
|
|
38
|
+
datasource_id: 'HTX',
|
|
39
|
+
product_id: encodePath('HTX', 'SWAP', tick.contract_code),
|
|
40
40
|
open_interest: `${tick.volume}`,
|
|
41
41
|
})));
|
|
42
42
|
if (process.env.WRITE_QUOTE_TO_SQL === 'true') {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/market-data/quote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,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,uCAAuC;AACvC,yCAAyC;AACzC,+CAA+C;AAC/C,4CAA4C;AAC5C,kBAAkB;AAClB,aAAa;AACb,+BAA+B;AAC/B,sBAAsB;AACtB,+BAA+B;AAC/B,4FAA4F;AAC5F,qBAAqB;AACrB,2CAA2C;AAC3C,0BAA0B;AAC1B,sCAAsC;AACtC,kFAAkF;AAClF,mDAAmD;AACnD,8DAA8D;AAC9D,8DAA8D;AAC9D,qDAAqD;AACrD,kFAAkF;AAClF,kFAAkF;AAClF,gEAAgE;AAChE,eAAe;AACf,cAAc;AACd,WAAW;AACX,SAAS;AACT,OAAO;AACP,MAAM","sourcesContent":["import { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, groupBy, map, merge, mergeMap, repeat, retry, scan, shareReplay, toArray } from 'rxjs';\nimport {\n getSwapBatchFundingRate,\n getSwapMarketBbo,\n getSwapMarketTrade,\n getSwapOpenInterest,\n} from '../../api/public-api';\n\nconst swapBboTick$ = defer(() => getSwapMarketBbo({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote1$ = swapBboTick$.pipe(\n mergeMap((res) => res.ticks || []),\n map((tick): Partial<IQuote> => {\n const [ask_price = '', ask_volume = ''] = tick.ask || [];\n const [bid_price = '', bid_volume = ''] = tick.bid || [];\n return {\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n ask_price: `${ask_price}`,\n bid_price: `${bid_price}`,\n ask_volume: `${ask_volume}`,\n bid_volume: `${bid_volume}`,\n };\n }),\n);\n\nconst mapSwapContractCodeToBboTick$ = defer(() => swapBboTick$).pipe(\n mergeMap((res) =>\n from(res.ticks).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst swapTradeTick$ = defer(() => getSwapMarketTrade({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote2$ = swapTradeTick$.pipe(\n mergeMap((res) => res.tick?.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n last_price: `${tick.price}`,\n }),\n ),\n);\n\nconst mapSwapContractCodeToTradeTick$ = defer(() => swapTradeTick$).pipe(\n mergeMap((res) =>\n from(res.tick.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\nconst swapFundingRateTick$ = defer(() => getSwapBatchFundingRate({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote3$ = swapFundingRateTick$.pipe(\n mergeMap((res) => res.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n interest_rate_long: `${-tick.funding_rate}`,\n interest_rate_short: `${tick.funding_rate}`,\n interest_rate_next_settled_at: formatTime(+tick.funding_time),\n }),\n ),\n);\n\nconst mapSwapContractCodeToFundingRateTick$ = defer(() => swapFundingRateTick$).pipe(\n mergeMap((res) =>\n from(res.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst swapOpenInterest$ = defer(() => getSwapOpenInterest({})).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\nconst quote4$ = swapOpenInterest$.pipe(\n mergeMap((res) => res.data || []),\n map(\n (tick): Partial<IQuote> => ({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', tick.contract_code),\n open_interest: `${tick.volume}`,\n }),\n ),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n // 合并不同来源的数据并进行合并,避免死锁\n merge(quote1$, quote2$, quote3$, quote4$)\n .pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>));\n }),\n )\n .pipe(\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: 'quote',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n\nconst mapSwapContractCodeToOpenInterest$ = defer(() => swapOpenInterest$).pipe(\n mergeMap((res) =>\n from(res.data).pipe(\n map((tick) => [tick.contract_code, tick] as const),\n toArray(),\n map((ticks) => Object.fromEntries(ticks)),\n ),\n ),\n\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n);\n\n// provideTicks(Terminal.fromNodeEnv(), 'HUOBI-SWAP', (product_id) => {\n// return defer(async () => {\n// const products = await firstValueFrom(perpetualContractProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n\n// return [\n// of(theProduct),\n// mapSwapContractCodeToBboTick$,\n// mapSwapContractCodeToTradeTick$,\n// mapSwapContractCodeToFundingRateTick$,\n// mapSwapContractCodeToOpenInterest$,\n// ] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(([theProduct, bboTick, tradeTick, fundingRateTick, openInterest]): ITick => {\n// return {\n// datasource_id: 'HUOBI-SWAP',\n// product_id,\n// updated_at: Date.now(),\n// settlement_scheduled_at: +fundingRateTick[product_id].funding_time,\n// price: +tradeTick[product_id].price,\n// ask: bboTick[product_id].ask?.[0] ?? undefined,\n// bid: bboTick[product_id].bid?.[0] ?? undefined,\n// volume: +tradeTick[product_id].amount,\n// interest_rate_for_long: -+fundingRateTick[product_id].funding_rate,\n// interest_rate_for_short: +fundingRateTick[product_id].funding_rate,\n// open_interest: +openInterest[product_id]?.volume,\n// };\n// }),\n// ),\n// ),\n// );\n// });\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getSwapOpenOrders } from '../../api/private-api';
|
|
2
|
+
export const listSwapOrders = async (credential) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const orders = [];
|
|
5
|
+
let page_index = 1;
|
|
6
|
+
const page_size = 50;
|
|
7
|
+
while (true) {
|
|
8
|
+
const ordersRes = await getSwapOpenOrders(credential, { page_index, page_size });
|
|
9
|
+
if (!((_a = ordersRes.data) === null || _a === void 0 ? void 0 : _a.orders) || ordersRes.data.orders.length === 0) {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
const pageOrders = ordersRes.data.orders.map((v) => {
|
|
13
|
+
return {
|
|
14
|
+
order_id: v.order_id_str,
|
|
15
|
+
account_id: `huobi/swap`,
|
|
16
|
+
product_id: v.contract_code,
|
|
17
|
+
order_type: ['lightning'].includes(v.order_price_type)
|
|
18
|
+
? 'MARKET'
|
|
19
|
+
: ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(v.order_price_type)
|
|
20
|
+
? 'LIMIT'
|
|
21
|
+
: ['fok'].includes(v.order_price_type)
|
|
22
|
+
? 'FOK'
|
|
23
|
+
: v.order_price_type.includes('ioc')
|
|
24
|
+
? 'IOC'
|
|
25
|
+
: 'STOP',
|
|
26
|
+
order_direction: v.direction === 'open'
|
|
27
|
+
? v.offset === 'buy'
|
|
28
|
+
? 'OPEN_LONG'
|
|
29
|
+
: 'OPEN_SHORT'
|
|
30
|
+
: v.offset === 'buy'
|
|
31
|
+
? 'CLOSE_SHORT'
|
|
32
|
+
: 'CLOSE_LONG',
|
|
33
|
+
volume: v.volume,
|
|
34
|
+
submit_at: v.created_at,
|
|
35
|
+
price: v.price,
|
|
36
|
+
traded_volume: v.trade_volume,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
orders.push(...pageOrders);
|
|
40
|
+
page_index++;
|
|
41
|
+
}
|
|
42
|
+
return orders;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=listOrders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAe,MAAM,uBAAuB,CAAC;AAEvE,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,UAAuB,EAAqB,EAAE;;IACjF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,OAAO,IAAI,EAAE;QACX,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,CAAA,MAAA,SAAS,CAAC,IAAI,0CAAE,MAAM,CAAA,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACjE,MAAM;SACP;QAED,MAAM,UAAU,GAAa,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAU,EAAE;YACnE,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,YAAY;gBACxB,UAAU,EAAE,YAAY;gBACxB,UAAU,EAAE,CAAC,CAAC,aAAa;gBAC3B,UAAU,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;oBACpD,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,QAAQ,CAClF,CAAC,CAAC,gBAAgB,CACnB;wBACH,CAAC,CAAC,OAAO;wBACT,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;4BACtC,CAAC,CAAC,KAAK;4BACP,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC;gCACpC,CAAC,CAAC,KAAK;gCACP,CAAC,CAAC,MAAM;gBACV,eAAe,EACb,CAAC,CAAC,SAAS,KAAK,MAAM;oBACpB,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK;wBAClB,CAAC,CAAC,WAAW;wBACb,CAAC,CAAC,YAAY;oBAChB,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK;wBACpB,CAAC,CAAC,aAAa;wBACf,CAAC,CAAC,YAAY;gBAClB,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,SAAS,EAAE,CAAC,CAAC,UAAU;gBACvB,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,aAAa,EAAE,CAAC,CAAC,YAAY;aAC9B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;QAC3B,UAAU,EAAE,CAAC;KACd;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { getSwapOpenOrders, ICredential } from '../../api/private-api';\n\nexport const listSwapOrders = async (credential: ICredential): Promise<IOrder[]> => {\n const orders: IOrder[] = [];\n let page_index = 1;\n const page_size = 50;\n\n while (true) {\n const ordersRes = await getSwapOpenOrders(credential, { page_index, page_size });\n if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n break;\n }\n\n const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n return {\n order_id: v.order_id_str,\n account_id: `huobi/swap`, // Placeholder, will be adjusted if needed\n product_id: v.contract_code,\n order_type: ['lightning'].includes(v.order_price_type)\n ? 'MARKET'\n : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n v.order_price_type,\n )\n ? 'LIMIT'\n : ['fok'].includes(v.order_price_type)\n ? 'FOK'\n : v.order_price_type.includes('ioc')\n ? 'IOC'\n : 'STOP', // unreachable code\n order_direction:\n v.direction === 'open'\n ? v.offset === 'buy'\n ? 'OPEN_LONG'\n : 'OPEN_SHORT'\n : v.offset === 'buy'\n ? 'CLOSE_SHORT'\n : 'CLOSE_LONG',\n volume: v.volume,\n submit_at: v.created_at,\n price: v.price,\n traded_volume: v.trade_volume,\n };\n });\n\n orders.push(...pageOrders);\n page_index++;\n }\n return orders;\n};\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { formatTime, roundToStep } from '@yuants/utils';
|
|
1
|
+
import { decodePath, formatTime, newError, roundToStep } from '@yuants/utils';
|
|
2
2
|
import { firstValueFrom } from 'rxjs';
|
|
3
|
-
import { getCrossMarginLoanInfo, getSpotAccountBalance, getSwapCrossPositionInfo, postSpotOrder, postSwapOrder, } from '
|
|
4
|
-
import { getSpotTick } from '
|
|
5
|
-
import {
|
|
3
|
+
import { getCrossMarginLoanInfo, getSpotAccountBalance, getSwapCrossPositionInfo, postSpotOrder, postSwapOrder, } from '../../api/private-api';
|
|
4
|
+
import { getSpotTick } from '../../api/public-api';
|
|
5
|
+
import { productService } from '../product';
|
|
6
6
|
import { superMarginAccountUidCache } from '../uid';
|
|
7
7
|
/**
|
|
8
8
|
* 处理 swap 账户订单提交
|
|
@@ -47,7 +47,7 @@ async function handleSuperMarginOrder(order, credential) {
|
|
|
47
47
|
// 获取账户余额, 产品信息和价格
|
|
48
48
|
const [balanceRes, mapProductIdToProduct, priceRes] = await Promise.all([
|
|
49
49
|
getSpotAccountBalance(credential, superMarginAccountUid),
|
|
50
|
-
firstValueFrom(
|
|
50
|
+
firstValueFrom(productService.mapProductIdToProduct$),
|
|
51
51
|
getSpotTick({ symbol: order.product_id }),
|
|
52
52
|
]);
|
|
53
53
|
const balance = balanceRes.data.list
|
|
@@ -83,12 +83,13 @@ async function handleSuperMarginOrder(order, credential) {
|
|
|
83
83
|
return { order_id: result.data.orderId.toString() };
|
|
84
84
|
}
|
|
85
85
|
export const submitOrder = (credential, order) => {
|
|
86
|
-
|
|
86
|
+
const [, instType] = decodePath(order.product_id);
|
|
87
|
+
if (instType === 'SWAP') {
|
|
87
88
|
return handleSwapOrder(order, credential);
|
|
88
89
|
}
|
|
89
|
-
if (
|
|
90
|
+
if (instType === 'SUPER-MARGIN') {
|
|
90
91
|
return handleSuperMarginOrder(order, credential);
|
|
91
92
|
}
|
|
92
|
-
throw
|
|
93
|
+
throw newError('UNSUPPORTED_INST_TYPE', { order_type: instType });
|
|
93
94
|
};
|
|
94
95
|
//# sourceMappingURL=submitOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAEL,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAEpD;;GAEG;AACH,KAAK,UAAU,eAAe,CAAC,KAAa,EAAE,UAAuB;;IACnE,SAAS;IACT,MAAM,YAAY,GAAG,MAAM,wBAAwB,CAAC,UAAU,CAAC,CAAC;IAChE,MAAM,qBAAqB,GAAG,MAAM,CAAC,WAAW,CAC9C,Y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,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK;QACnE,MAAM,EAAE,kBAAkB;KAC3B,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpG,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,CAAC,IAAI,YAAY,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KACvG;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAuB,EAAE,KAAa,EAAiC,EAAE;IACnG,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;KAC3C;IACD,IAAI,QAAQ,KAAK,cAAc,EAAE;QAC/B,OAAO,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;KAClD;IACD,MAAM,QAAQ,CAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, newError, roundToStep } from '@yuants/utils';\nimport { firstValueFrom } from 'rxjs';\nimport {\n ICredential,\n getCrossMarginLoanInfo,\n getSpotAccountBalance,\n getSwapCrossPositionInfo,\n postSpotOrder,\n postSwapOrder,\n} from '../../api/private-api';\nimport { getSpotTick } from '../../api/public-api';\nimport { productService } from '../product';\nimport { superMarginAccountUidCache } from '../uid';\n\n/**\n * 处理 swap 账户订单提交\n */\nasync function handleSwapOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取仓位信息\n const positionInfo = await getSwapCrossPositionInfo(credential);\n const mapContractCodeToRate = Object.fromEntries(\n positionInfo.data.map((v) => [v.contract_code, v.lever_rate]),\n );\n\n const lever_rate = mapContractCodeToRate[order.product_id] ?? 20;\n const params = {\n contract_code: order.product_id,\n contract_type: 'swap',\n price: order.price,\n volume: order.volume,\n offset:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'OPEN_SHORT' ? 'open' : 'close',\n direction:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell',\n // dynamically adjust the leverage\n lever_rate,\n order_price_type: order.order_type === 'MARKET' ? 'market' : 'limit',\n };\n\n const result = await postSwapOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.status !== 'ok') {\n throw new Error(`Failed to submit swap order: status=${result.status}`);\n }\n return { order_id: result.data.order_id_str };\n}\n\n/**\n * 处理 super-margin 账户订单提交\n */\nasync function handleSuperMarginOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取可贷款金额\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Super margin account UID not found');\n const loanInfo = await getCrossMarginLoanInfo(credential);\n const usdtLoanable = loanInfo.data.find((v) => v.currency === 'usdt');\n if (!usdtLoanable) throw new Error('USDT loanable amount not found');\n const loanable = +usdtLoanable['loanable-amt'];\n\n // 获取账户余额, 产品信息和价格\n const [balanceRes, mapProductIdToProduct, priceRes] = await Promise.all([\n getSpotAccountBalance(credential, superMarginAccountUid),\n firstValueFrom(productService.mapProductIdToProduct$),\n getSpotTick({ symbol: order.product_id }),\n ]);\n\n const balance = balanceRes.data.list\n .filter((v) => v.currency === 'usdt' && v.type === 'trade')\n .reduce((acc, cur) => acc + +cur.balance, 0);\n\n if (!mapProductIdToProduct) throw new Error('Product map not found');\n\n const theProduct = mapProductIdToProduct.get(order.product_id);\n const price = priceRes.tick.close;\n const borrow_amount =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? Math.max(Math.min(loanable, order.volume * price - balance), 0)\n : undefined;\n\n const params = {\n symbol: order.product_id,\n 'account-id': '' + superMarginAccountUid,\n amount:\n '' +\n (order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? roundToStep(order.volume * price, theProduct?.volume_step!)\n : order.volume),\n 'borrow-amount': '' + borrow_amount,\n type: `${\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell'\n }-${'LIMIT' === order.order_type ? 'limit' : 'market'}`,\n 'trade-purpose':\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? '1' // auto borrow\n : '2', // auto repay\n price: order.order_type === 'MARKET' ? undefined : '' + order.price,\n source: 'super-margin-api',\n };\n\n const result = await postSpotOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.success === false) {\n throw new Error(`Failed to submit super margin order: code=${result.code} message=${result.message}`);\n }\n\n return { order_id: result.data.orderId.toString() };\n}\n\nexport const submitOrder = (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [, instType] = decodePath(order.product_id);\n if (instType === 'SWAP') {\n return handleSwapOrder(order, credential);\n }\n if (instType === 'SUPER-MARGIN') {\n return handleSuperMarginOrder(order, credential);\n }\n throw newError('UNSUPPORTED_INST_TYPE', { order_type: instType });\n};\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { provideQueryProductsService } from '@yuants/data-product';
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
|
-
import {
|
|
3
|
+
import { encodePath } from '@yuants/utils';
|
|
4
|
+
import { getPerpetualContractSymbols, getSpotSymbols, getSwapCrossLadderMargin } from '../api/public-api';
|
|
4
5
|
const terminal = Terminal.fromNodeEnv();
|
|
5
6
|
// Provide QueryProducts service for swap products
|
|
6
|
-
|
|
7
|
+
const listSwapProducts = async () => {
|
|
7
8
|
var _a;
|
|
8
9
|
const products = [];
|
|
9
10
|
// Get perpetual contract products and cross leverage data in parallel
|
|
@@ -16,8 +17,8 @@ export const swapProductService = provideQueryProductsService(terminal, 'HUOBI-S
|
|
|
16
17
|
continue; // Only include active contracts
|
|
17
18
|
const maxLeverage = (_a = crossLeverage === null || crossLeverage === void 0 ? void 0 : crossLeverage.data.find((x) => x.contract_code === symbol.contract_code)) === null || _a === void 0 ? void 0 : _a.list.reduce((acc, cur) => Math.max(acc, cur.lever_rate), 1);
|
|
18
19
|
products.push({
|
|
19
|
-
datasource_id: '
|
|
20
|
-
product_id: symbol.contract_code,
|
|
20
|
+
datasource_id: 'HTX',
|
|
21
|
+
product_id: encodePath('HTX', 'SWAP', symbol.contract_code),
|
|
21
22
|
base_currency: symbol.symbol,
|
|
22
23
|
quote_currency: 'USDT',
|
|
23
24
|
value_scale: symbol.contract_size,
|
|
@@ -32,16 +33,14 @@ export const swapProductService = provideQueryProductsService(terminal, 'HUOBI-S
|
|
|
32
33
|
max_volume: 0,
|
|
33
34
|
allow_long: true,
|
|
34
35
|
allow_short: true,
|
|
35
|
-
market_id: '
|
|
36
|
+
market_id: 'HTX',
|
|
36
37
|
no_interest_rate: false,
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
return products;
|
|
40
|
-
}
|
|
41
|
-
auto_refresh_interval: 3600000,
|
|
42
|
-
});
|
|
41
|
+
};
|
|
43
42
|
// Provide QueryProducts service for spot products
|
|
44
|
-
|
|
43
|
+
const listSpotProducts = async () => {
|
|
45
44
|
const products = [];
|
|
46
45
|
// Get spot products
|
|
47
46
|
const spotSymbols = await getSpotSymbols();
|
|
@@ -49,8 +48,8 @@ export const spotProductService = provideQueryProductsService(terminal, 'HUOBI-S
|
|
|
49
48
|
if (symbol.state !== 'online')
|
|
50
49
|
continue; // Only include online symbols
|
|
51
50
|
products.push({
|
|
52
|
-
datasource_id: '
|
|
53
|
-
product_id: symbol.sc,
|
|
51
|
+
datasource_id: 'HTX',
|
|
52
|
+
product_id: encodePath('HTX', 'SPOT', symbol.sc),
|
|
54
53
|
base_currency: symbol.bc,
|
|
55
54
|
quote_currency: symbol.qc,
|
|
56
55
|
value_scale: 1,
|
|
@@ -70,7 +69,12 @@ export const spotProductService = provideQueryProductsService(terminal, 'HUOBI-S
|
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
return products;
|
|
73
|
-
}
|
|
72
|
+
};
|
|
73
|
+
export const listProducts = async () => {
|
|
74
|
+
const [swapProducts, spotProducts] = await Promise.all([listSwapProducts(), listSpotProducts()]);
|
|
75
|
+
return [...swapProducts, ...spotProducts];
|
|
76
|
+
};
|
|
77
|
+
export const productService = provideQueryProductsService(terminal, 'HTX', listProducts, {
|
|
74
78
|
auto_refresh_interval: 3600000,
|
|
75
79
|
});
|
|
76
80
|
//# sourceMappingURL=product.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/services/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE1G,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EA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M,YAAY,GAAG,KAAK,IAAyB,EAAE;IAC1D,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;IACjG,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,YAAY,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE;IACvF,qBAAqB,EAAE,OAAQ;CAChC,CAAC,CAAC","sourcesContent":["import { IProduct, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getPerpetualContractSymbols, getSpotSymbols, getSwapCrossLadderMargin } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// Provide QueryProducts service for swap products\nconst listSwapProducts = async (): Promise<IProduct[]> => {\n const products: IProduct[] = [];\n\n // Get perpetual contract products and cross leverage data in parallel\n const [swapSymbols, crossLeverage] = await Promise.all([\n getPerpetualContractSymbols(),\n getSwapCrossLadderMargin(),\n ]);\n\n for (const symbol of swapSymbols?.data || []) {\n if (symbol.contract_status !== 1) continue; // Only include active contracts\n\n const maxLeverage = crossLeverage?.data\n .find((x) => x.contract_code === symbol.contract_code)\n ?.list.reduce((acc, cur) => Math.max(acc, cur.lever_rate), 1);\n\n products.push({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP', symbol.contract_code),\n base_currency: symbol.symbol,\n quote_currency: 'USDT',\n value_scale: symbol.contract_size,\n price_step: symbol.price_tick,\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / (maxLeverage || 1),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'HTX',\n no_interest_rate: false,\n });\n }\n\n return products;\n};\n\n// Provide QueryProducts service for spot products\nconst listSpotProducts = async (): Promise<IProduct[]> => {\n const products: IProduct[] = [];\n\n // Get spot products\n const spotSymbols = await getSpotSymbols();\n\n for (const symbol of spotSymbols?.data || []) {\n if (symbol.state !== 'online') continue; // Only include online symbols\n\n products.push({\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SPOT', symbol.sc),\n base_currency: symbol.bc,\n quote_currency: symbol.qc,\n value_scale: 1,\n price_step: 1 / 10 ** symbol.tpp,\n volume_step: 1 / 10 ** symbol.tap,\n name: '',\n value_scale_unit: '',\n margin_rate: 1,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'HUOBI/SPOT',\n no_interest_rate: true,\n });\n }\n\n return products;\n};\n\nexport const listProducts = async (): Promise<IProduct[]> => {\n const [swapProducts, spotProducts] = await Promise.all([listSwapProducts(), listSpotProducts()]);\n return [...swapProducts, ...spotProducts];\n};\n\nexport const productService = provideQueryProductsService(terminal, 'HTX', listProducts, {\n auto_refresh_interval: 3600_000,\n});\n"]}
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { createCache } from '@yuants/cache';
|
|
2
|
-
import { getAccount, getUid } from '
|
|
2
|
+
import { getAccount, getUid } from '../api/private-api';
|
|
3
3
|
export const uidCache = createCache((key) => getUid(JSON.parse(key)));
|
|
4
4
|
const huobiAccounts = createCache((key) => getAccount(JSON.parse(key)));
|
|
5
5
|
export const superMarginAccountUidCache = createCache((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'super-margin')) === null || _a === void 0 ? void 0 : _a.id; }));
|
|
6
6
|
export const spotAccountUidCache = createCache((key) => huobiAccounts.query(key).then((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.data.find((v) => v.type === 'spot')) === null || _a === void 0 ? void 0 : _a.id; }));
|
|
7
|
-
export const getAccountIds = async (key) => {
|
|
8
|
-
const uid = await uidCache.query(key);
|
|
9
|
-
if (!uid)
|
|
10
|
-
throw new Error('Failed to get UID');
|
|
11
|
-
const account_id = `huobi/${uid}`;
|
|
12
|
-
const SPOT_ACCOUNT_ID = `${account_id}/spot/usdt`;
|
|
13
|
-
const SUPER_MARGIN_ACCOUNT_ID = `${account_id}/super-margin`;
|
|
14
|
-
const SWAP_ACCOUNT_ID = `${account_id}/swap`;
|
|
15
|
-
return {
|
|
16
|
-
spot: SPOT_ACCOUNT_ID,
|
|
17
|
-
superMargin: SUPER_MARGIN_ACCOUNT_ID,
|
|
18
|
-
swap: SWAP_ACCOUNT_ID,
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
7
|
//# sourceMappingURL=uid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/services/uid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtE,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAC5D,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACzF,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CACrD,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAC,CACjF,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccount, getUid } from '../api/private-api';\n\nexport const uidCache = createCache((key) => getUid(JSON.parse(key)));\n\nconst huobiAccounts = createCache((key) => getAccount(JSON.parse(key)));\n\nexport const superMarginAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'super-margin')?.id),\n);\n\nexport const spotAccountUidCache = createCache((key) =>\n huobiAccounts.query(key).then((x) => x?.data.find((v) => v.type === 'spot')?.id),\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=account-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-info.d.ts","sourceRoot":"","sources":["../../src/__archived/account-info.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
1
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/__archived/api.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
1
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../src/__archived/transfer.ts"],"names":[],"mappings":""}
|