@yuants/vendor-okx 0.31.10 → 0.32.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/README.md +0 -4
- package/dist/account-actions-with-credential.js.map +1 -1
- package/dist/accountInfos/loan.js.map +1 -1
- package/dist/accountInfos/strategy.js.map +1 -1
- package/dist/accountInfos/uid.js +1 -1
- package/dist/accountInfos/uid.js.map +1 -1
- package/dist/api/private-api.js.map +1 -1
- package/dist/api/public-api.js.map +1 -1
- package/dist/experimental/getOrders.js.map +1 -1
- package/dist/experimental/getPositions.js.map +1 -1
- package/dist/experimental/product.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/orders/cancelOrder.js.map +1 -1
- package/dist/orders/listOrders.js.map +1 -1
- package/dist/orders/modifyOrder.js.map +1 -1
- package/dist/orders/submitOrder.js.map +1 -1
- package/dist/public-data/market-order.js.map +1 -1
- package/dist/public-data/new-quote.js.map +1 -1
- package/dist/public-data/ohlc.js +13 -162
- package/dist/public-data/ohlc.js.map +1 -1
- package/dist/public-data/product.js.map +1 -1
- package/dist/public-data/quote.js.map +1 -1
- package/dist/services/interest-ledger-service.js +33 -0
- package/dist/services/interest-ledger-service.js.map +1 -0
- package/dist/services/interest-rate-service.js.map +1 -1
- package/dist/services/ohlc-service.js.map +1 -1
- package/dist/services.js.map +1 -1
- package/dist/trade.js.map +1 -1
- package/dist/transfer.js +1 -1
- package/dist/transfer.js.map +1 -1
- package/dist/ws.js +24 -24
- package/dist/ws.js.map +1 -1
- package/lib/account-actions-with-credential.js.map +1 -1
- package/lib/accountInfos/loan.js.map +1 -1
- package/lib/accountInfos/strategy.js.map +1 -1
- package/lib/accountInfos/trading.d.ts.map +1 -1
- package/lib/accountInfos/uid.d.ts +2 -2
- package/lib/accountInfos/uid.d.ts.map +1 -1
- package/lib/accountInfos/uid.js +1 -1
- package/lib/accountInfos/uid.js.map +1 -1
- package/lib/api/private-api.d.ts +4 -4
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js +32 -32
- package/lib/api/private-api.js.map +1 -1
- package/lib/api/public-api.d.ts +1 -11
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js.map +1 -1
- package/lib/experimental/getOrders.d.ts.map +1 -1
- package/lib/experimental/getOrders.js.map +1 -1
- package/lib/experimental/getPositions.d.ts.map +1 -1
- package/lib/experimental/getPositions.js.map +1 -1
- package/lib/experimental/product.d.ts.map +1 -1
- package/lib/experimental/product.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/orders/cancelOrder.d.ts.map +1 -1
- package/lib/orders/cancelOrder.js.map +1 -1
- package/lib/orders/listOrders.d.ts.map +1 -1
- package/lib/orders/listOrders.js.map +1 -1
- package/lib/orders/modifyOrder.d.ts.map +1 -1
- package/lib/orders/modifyOrder.js.map +1 -1
- package/lib/orders/submitOrder.d.ts.map +1 -1
- package/lib/orders/submitOrder.js.map +1 -1
- package/lib/public-data/market-order.js.map +1 -1
- package/lib/public-data/new-quote.js.map +1 -1
- package/lib/public-data/ohlc.js +12 -161
- package/lib/public-data/ohlc.js.map +1 -1
- package/lib/public-data/product.js.map +1 -1
- package/lib/public-data/quote.js.map +1 -1
- package/lib/services/interest-ledger-service.d.ts +2 -0
- package/lib/services/interest-ledger-service.d.ts.map +1 -0
- package/lib/services/interest-ledger-service.js +35 -0
- package/lib/services/interest-ledger-service.js.map +1 -0
- package/lib/services/interest-rate-service.js.map +1 -1
- package/lib/services/ohlc-service.js.map +1 -1
- package/lib/services.js.map +1 -1
- package/lib/trade.js.map +1 -1
- package/lib/transfer.js +1 -1
- package/lib/transfer.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/ws.d.ts +1 -1
- package/lib/ws.d.ts.map +1 -1
- package/lib/ws.js +24 -24
- package/lib/ws.js.map +1 -1
- package/package.json +48 -48
- package/temp/build/typescript/ts_xKrCYDcc.json +1 -0
- package/temp/package-deps.json +25 -27
- package/temp/test/jest/haste-map-0104fb5fee08bd97aacd02300cdbf195-f3ddf881f4f21e2e5ae6006d95adf2b1-267deb988b5111321a1cf92c4d020334 +0 -0
- package/temp/vendor-okx.api.json +18 -2
- package/dist/public-data/interest_rate.js +0 -117
- package/dist/public-data/interest_rate.js.map +0 -1
- package/dist/utils/provideOHLCFromTimeBackwardService.js +0 -49
- package/dist/utils/provideOHLCFromTimeBackwardService.js.map +0 -1
- package/dist/utils/provideSeriesFromTimeBackwardService.js +0 -59
- package/dist/utils/provideSeriesFromTimeBackwardService.js.map +0 -1
- package/lib/public-data/interest_rate.d.ts +0 -2
- package/lib/public-data/interest_rate.d.ts.map +0 -1
- package/lib/public-data/interest_rate.js +0 -119
- package/lib/public-data/interest_rate.js.map +0 -1
- package/lib/utils/provideOHLCFromTimeBackwardService.d.ts +0 -24
- package/lib/utils/provideOHLCFromTimeBackwardService.d.ts.map +0 -1
- package/lib/utils/provideOHLCFromTimeBackwardService.js +0 -53
- package/lib/utils/provideOHLCFromTimeBackwardService.js.map +0 -1
- package/lib/utils/provideSeriesFromTimeBackwardService.d.ts +0 -22
- package/lib/utils/provideSeriesFromTimeBackwardService.d.ts.map +0 -1
- package/lib/utils/provideSeriesFromTimeBackwardService.js +0 -63
- package/lib/utils/provideSeriesFromTimeBackwardService.js.map +0 -1
package/temp/package-deps.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/vendor-okx/CHANGELOG.json": "
|
|
3
|
-
"apps/vendor-okx/CHANGELOG.md": "
|
|
4
|
-
"apps/vendor-okx/README.md": "
|
|
5
|
-
"apps/vendor-okx/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
2
|
+
"apps/vendor-okx/CHANGELOG.json": "ebd0cc367fb3c8f95cbc91e8a22a3db469d33817",
|
|
3
|
+
"apps/vendor-okx/CHANGELOG.md": "84e5e4fec4ea743835e76763251b6a000f7b9a9e",
|
|
4
|
+
"apps/vendor-okx/README.md": "4aae651c410c9f8271170ba1cae3886eb804aeef",
|
|
5
|
+
"apps/vendor-okx/config/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
6
6
|
"apps/vendor-okx/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-okx/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-okx/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
9
|
"apps/vendor-okx/etc/vendor-okx.api.md": "92c54ccd547d2ad81ca6088158ca193e85c208df",
|
|
10
|
-
"apps/vendor-okx/package.json": "
|
|
10
|
+
"apps/vendor-okx/package.json": "62f871886f90d6a181a6f7fc1b16653bd73a9215",
|
|
11
11
|
"apps/vendor-okx/src/account-actions-with-credential.ts": "1a2de787b588e98ceef60b3ffb951f298504bf12",
|
|
12
12
|
"apps/vendor-okx/src/account.ts": "672014c974457b438cf026f763d6eecfe585c82b",
|
|
13
13
|
"apps/vendor-okx/src/accountInfos/earning.ts": "62aaeb3b62fa9197d07ee14155625530cdb9b1cd",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"apps/vendor-okx/src/experimental/getOrders.ts": "f89b8334fa55163a78f91cf675cea8c7c869d4a7",
|
|
26
26
|
"apps/vendor-okx/src/experimental/getPositions.ts": "5fe0bd5ebc3db151be7ae897aaad256dea878122",
|
|
27
27
|
"apps/vendor-okx/src/experimental/product.ts": "808bb037c1559ead2260a6b1eb2552f246da45c6",
|
|
28
|
-
"apps/vendor-okx/src/index.ts": "
|
|
28
|
+
"apps/vendor-okx/src/index.ts": "40ad85782469972d4745934751be3e8ce568ec63",
|
|
29
29
|
"apps/vendor-okx/src/order-actions-with-credential.ts": "f58b164c57a776db0fd0ad3a9f7197603ab2f66e",
|
|
30
30
|
"apps/vendor-okx/src/order-actions.ts": "18907924c81ab679bf8a58142fcbc3addd160a94",
|
|
31
31
|
"apps/vendor-okx/src/order.ts": "342f08dbc4a760e5f29bdaa1fe840872219f9ab5",
|
|
@@ -33,38 +33,36 @@
|
|
|
33
33
|
"apps/vendor-okx/src/orders/listOrders.ts": "c4739eb4c0f54391164a7d8e6c7fde44b41cb268",
|
|
34
34
|
"apps/vendor-okx/src/orders/modifyOrder.ts": "9101b5049743f302b0f0ad84f929ed8a88040bad",
|
|
35
35
|
"apps/vendor-okx/src/orders/submitOrder.ts": "abf283641c9b1ef893b9de9737a3870485744a39",
|
|
36
|
-
"apps/vendor-okx/src/public-data/interest_rate.ts": "f3171f2753955d500ae00ce7e263ea26e05e5421",
|
|
37
36
|
"apps/vendor-okx/src/public-data/market-order.ts": "c7269e9fe1f339b320e8b4cd98652854446a245c",
|
|
38
37
|
"apps/vendor-okx/src/public-data/new-quote.ts": "8807510a0e248184eaf0f1dfa00a7e3bed131943",
|
|
39
|
-
"apps/vendor-okx/src/public-data/ohlc.ts": "
|
|
38
|
+
"apps/vendor-okx/src/public-data/ohlc.ts": "41cf9b0d04d1317f0f255484cd5243ddc4c152e5",
|
|
40
39
|
"apps/vendor-okx/src/public-data/product.ts": "9caa1b0d9fa621800870ef47086767f6f5810ad9",
|
|
41
40
|
"apps/vendor-okx/src/public-data/quote.ts": "da471098f6c59376f7221bf6fc3d2625eeacecee",
|
|
42
41
|
"apps/vendor-okx/src/services.ts": "aeaf5f9d0a87347be6150b28961c5a7c0886b1d8",
|
|
42
|
+
"apps/vendor-okx/src/services/interest-ledger-service.ts": "c941cc7cbd485463723be911106576f51c6e19fb",
|
|
43
43
|
"apps/vendor-okx/src/services/interest-rate-service.ts": "025ee9fef91529509f088872956ed3d439f49fb8",
|
|
44
44
|
"apps/vendor-okx/src/services/ohlc-service.ts": "bda7d07646fc54c0cbf4a5ec6e90e773c4a4c4bb",
|
|
45
45
|
"apps/vendor-okx/src/services/quotes.ts": "2f2278acf1884c8c8b29f9bb79221955b2eb8016",
|
|
46
46
|
"apps/vendor-okx/src/strategy-account.ts": "2d8f913e19c4402eab249291aaab0b77bc4d9ff8",
|
|
47
47
|
"apps/vendor-okx/src/trade.ts": "17a2afcdbf2ec69944a73d3d097660675dbe09a4",
|
|
48
48
|
"apps/vendor-okx/src/transfer.ts": "381e4bf18846c8f79d3e970277d8800a2f94dacd",
|
|
49
|
-
"apps/vendor-okx/src/utils/provideOHLCFromTimeBackwardService.ts": "3a44206410b5b73683f2395d6c551549b553d7bd",
|
|
50
|
-
"apps/vendor-okx/src/utils/provideSeriesFromTimeBackwardService.ts": "daf3c793eb4fc20e59a740bb69e50fadab5f62f0",
|
|
51
49
|
"apps/vendor-okx/src/ws.ts": "5e8fe8c97c7da92c08ddf07ab47faf7976433ca3",
|
|
52
50
|
"apps/vendor-okx/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
53
|
-
"apps/vendor-okx/.rush/temp/shrinkwrap-deps.json": "
|
|
54
|
-
"libraries/protocol/temp/package-deps.json": "
|
|
55
|
-
"libraries/transfer/temp/package-deps.json": "
|
|
56
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
57
|
-
"libraries/data-order/temp/package-deps.json": "
|
|
58
|
-
"libraries/utils/temp/package-deps.json": "
|
|
59
|
-
"libraries/cache/temp/package-deps.json": "
|
|
60
|
-
"libraries/sql/temp/package-deps.json": "
|
|
61
|
-
"libraries/data-series/temp/package-deps.json": "
|
|
62
|
-
"libraries/data-product/temp/package-deps.json": "
|
|
63
|
-
"libraries/data-ohlc/temp/package-deps.json": "
|
|
64
|
-
"libraries/data-interest-rate/temp/package-deps.json": "
|
|
65
|
-
"libraries/data-quote/temp/package-deps.json": "
|
|
66
|
-
"libraries/data-trade/temp/package-deps.json": "
|
|
67
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
68
|
-
"libraries/extension/temp/package-deps.json": "
|
|
69
|
-
"tools/toolkit/temp/package-deps.json": "
|
|
51
|
+
"apps/vendor-okx/.rush/temp/shrinkwrap-deps.json": "78ed978c70324a38a821b4a91b473bb6423f73e4",
|
|
52
|
+
"libraries/protocol/temp/package-deps.json": "1ed7faa57c156fc1b7ff9f13fe5566aacda70447",
|
|
53
|
+
"libraries/transfer/temp/package-deps.json": "56f1b09fff53f23da4c19c0c71307cd636a4421f",
|
|
54
|
+
"libraries/data-account/temp/package-deps.json": "9bfd92d0e975a4ad3f2e79ce68233e832865b579",
|
|
55
|
+
"libraries/data-order/temp/package-deps.json": "3495abc01b406b0c63a2725d361512a996a23a79",
|
|
56
|
+
"libraries/utils/temp/package-deps.json": "018cb7f334c7419da6d55993eec202580b95f794",
|
|
57
|
+
"libraries/cache/temp/package-deps.json": "53c7e65e4fbefc731eef11e41145ecc3b90d9845",
|
|
58
|
+
"libraries/sql/temp/package-deps.json": "88cd4d4a8648dfa8d3aeec991aa734f9ab3374dc",
|
|
59
|
+
"libraries/data-series/temp/package-deps.json": "ca8fb8d7fa67d7a77b7254eb785f4aa14c1d928c",
|
|
60
|
+
"libraries/data-product/temp/package-deps.json": "2b9736cd4a54002df2be4e72f9a4b9641aa71201",
|
|
61
|
+
"libraries/data-ohlc/temp/package-deps.json": "4d744c19879a13bbdb1959b5aef0cc1a5da7f726",
|
|
62
|
+
"libraries/data-interest-rate/temp/package-deps.json": "42fb3cc90524c7bba423d19f038add1ea2d1e4bd",
|
|
63
|
+
"libraries/data-quote/temp/package-deps.json": "ecee1e69820ccb2072ea6977a3971555e9e68e11",
|
|
64
|
+
"libraries/data-trade/temp/package-deps.json": "d6312e206cfd0de7eed81bcb551c5c2f4fb163f2",
|
|
65
|
+
"libraries/exchange/temp/package-deps.json": "522ed703d78091e161f719f0b0db4666c65316a8",
|
|
66
|
+
"libraries/extension/temp/package-deps.json": "454f577565ee01a0838c468fb1fc59e1f5d5f37c",
|
|
67
|
+
"tools/toolkit/temp/package-deps.json": "580f13201f076fa393117989256a2fee58e354f8"
|
|
70
68
|
}
|
|
Binary file
|
package/temp/vendor-okx.api.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"metadata": {
|
|
3
3
|
"toolPackage": "@microsoft/api-extractor",
|
|
4
|
-
"toolVersion": "7.
|
|
5
|
-
"schemaVersion":
|
|
4
|
+
"toolVersion": "7.55.2",
|
|
5
|
+
"schemaVersion": 1011,
|
|
6
6
|
"oldestForwardsCompatibleVersion": 1001,
|
|
7
7
|
"tsdocConfig": {
|
|
8
8
|
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
|
|
@@ -114,6 +114,22 @@
|
|
|
114
114
|
"tagName": "@virtual",
|
|
115
115
|
"syntaxKind": "modifier"
|
|
116
116
|
},
|
|
117
|
+
{
|
|
118
|
+
"tagName": "@jsx",
|
|
119
|
+
"syntaxKind": "block"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"tagName": "@jsxRuntime",
|
|
123
|
+
"syntaxKind": "block"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"tagName": "@jsxFrag",
|
|
127
|
+
"syntaxKind": "block"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"tagName": "@jsxImportSource",
|
|
131
|
+
"syntaxKind": "block"
|
|
132
|
+
},
|
|
117
133
|
{
|
|
118
134
|
"tagName": "@betaDocumentation",
|
|
119
135
|
"syntaxKind": "modifier"
|
|
@@ -1,117 +0,0 @@
|
|
|
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 } from '@yuants/utils';
|
|
16
|
-
import { firstValueFrom, timer } from 'rxjs';
|
|
17
|
-
import { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';
|
|
18
|
-
createSeriesProvider(Terminal.fromNodeEnv(), {
|
|
19
|
-
tableName: 'interest_rate',
|
|
20
|
-
series_id_prefix_parts: ['OKX'],
|
|
21
|
-
reversed: true,
|
|
22
|
-
serviceOptions: { concurrent: 1 },
|
|
23
|
-
queryFn: function ({ series_id, started_at, ended_at }) {
|
|
24
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
25
|
-
const start = started_at || 0;
|
|
26
|
-
const end = ended_at || Date.now();
|
|
27
|
-
const [, instType, instId] = decodePath(series_id);
|
|
28
|
-
if (instType === 'SWAP') {
|
|
29
|
-
let current_end = end;
|
|
30
|
-
while (true) {
|
|
31
|
-
// 接口行为备注:向前翻页,时间降序,不含 after 当前时间点
|
|
32
|
-
const res = yield __await(getFundingRateHistory({
|
|
33
|
-
instId: instId,
|
|
34
|
-
after: `${current_end}`,
|
|
35
|
-
}));
|
|
36
|
-
if (res.code !== '0') {
|
|
37
|
-
throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;
|
|
38
|
-
}
|
|
39
|
-
// 如果没有数据了,就退出
|
|
40
|
-
if (res.data.length === 0) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));
|
|
44
|
-
const data = res.data.map((v) => ({
|
|
45
|
-
series_id: series_id,
|
|
46
|
-
product_id: series_id,
|
|
47
|
-
datasource_id: 'OKX',
|
|
48
|
-
created_at: formatTime(+v.fundingTime),
|
|
49
|
-
long_rate: `${-v.fundingRate}`,
|
|
50
|
-
short_rate: `${v.fundingRate}`,
|
|
51
|
-
settlement_price: '',
|
|
52
|
-
}));
|
|
53
|
-
yield yield __await(data);
|
|
54
|
-
current_end = +res.data[res.data.length - 1].fundingTime;
|
|
55
|
-
if (current_end <= start) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
// for API rate limit
|
|
59
|
-
yield __await(firstValueFrom(timer(1000)));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (instType === 'MARGIN') {
|
|
63
|
-
// MARGIN/BTC-USDT
|
|
64
|
-
const [base, quote] = instId.split('-');
|
|
65
|
-
let current_end = end;
|
|
66
|
-
while (true) {
|
|
67
|
-
const resBase = yield __await(getLendingRateHistory({ ccy: base, after: `${current_end}` }));
|
|
68
|
-
const resQuote = yield __await(getLendingRateHistory({ ccy: quote, after: `${current_end}` }));
|
|
69
|
-
if (resBase.code !== '0') {
|
|
70
|
-
throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;
|
|
71
|
-
}
|
|
72
|
-
if (resBase.data.length === 0) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));
|
|
76
|
-
if (resQuote.code !== '0') {
|
|
77
|
-
throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;
|
|
78
|
-
}
|
|
79
|
-
if (resQuote.data.length === 0) {
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));
|
|
83
|
-
// 做多时,借入 quote 的资金,做空时,借入 base 的资金
|
|
84
|
-
// 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate
|
|
85
|
-
const mapTsToBaseRate = new Map();
|
|
86
|
-
resBase.data.forEach((v) => {
|
|
87
|
-
mapTsToBaseRate.set(v.ts, v.rate);
|
|
88
|
-
});
|
|
89
|
-
const data = [];
|
|
90
|
-
resQuote.data.forEach((v) => {
|
|
91
|
-
if (!mapTsToBaseRate.has(v.ts))
|
|
92
|
-
return;
|
|
93
|
-
const long_rate = +v.rate / 365 / 24; // 转换为小时利率
|
|
94
|
-
const short_rate = +mapTsToBaseRate.get(v.ts) / 365 / 24; // 转换为小时利率
|
|
95
|
-
data.push({
|
|
96
|
-
series_id,
|
|
97
|
-
product_id: series_id,
|
|
98
|
-
datasource_id: 'OKX',
|
|
99
|
-
created_at: formatTime(+v.ts),
|
|
100
|
-
long_rate: `${-long_rate}`,
|
|
101
|
-
short_rate: `${-short_rate}`,
|
|
102
|
-
settlement_price: '',
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
yield yield __await(data);
|
|
106
|
-
current_end = new Date(data[data.length - 1].created_at).getTime();
|
|
107
|
-
if (current_end <= start) {
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
// for API rate limit
|
|
111
|
-
yield __await(firstValueFrom(timer(1000)));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
//# sourceMappingURL=interest_rate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../src/public-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,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BAChD,MAAM,UAAU,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBACrE,IAAI,CAAC,IAAI,CAAC;4BACR,SAAS;4BACT,UAAU,EAAE,SAAS;4BACrB,aAAa,EAAE,KAAK;4BACpB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE;4BAC1B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;4BAC5B,gBAAgB,EAAE,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,oBAAM,IAAI,CAAA,CAAC;oBACX,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,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 } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\n});\n"]}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { provideOHLCDurationService } from '@yuants/data-ohlc';
|
|
2
|
-
import { provideSeriesFromTimeBackwardService } from './provideSeriesFromTimeBackwardService';
|
|
3
|
-
import { convertDurationToOffset, decodePath } from '@yuants/utils';
|
|
4
|
-
/**
|
|
5
|
-
* Provide OHLC from time backward service
|
|
6
|
-
*
|
|
7
|
-
* 提供 K线数据 按时间向后查询服务
|
|
8
|
-
*
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export const provideOHLCFromTimeBackwardService = (ctx) => {
|
|
12
|
-
const supportedDurations = new Set(ctx.supported_durations);
|
|
13
|
-
provideOHLCDurationService(ctx.terminal, ctx.datasource_id, () => ctx.supported_durations);
|
|
14
|
-
provideSeriesFromTimeBackwardService({
|
|
15
|
-
terminal: ctx.terminal,
|
|
16
|
-
type: 'ohlc',
|
|
17
|
-
series_id_prefix_parts: [ctx.datasource_id],
|
|
18
|
-
queryFn: async ({ series_id, time }) => {
|
|
19
|
-
// series_id 格式: OKX/{product_id}/{duration}
|
|
20
|
-
// 其中 product_id 可能包含转义的 /,如 SPOT\/BTC-USDT
|
|
21
|
-
const [datasource_id, product_id, duration] = decodePath(series_id);
|
|
22
|
-
if (supportedDurations && !supportedDurations.has(duration)) {
|
|
23
|
-
throw `duration ${duration} is not supported`;
|
|
24
|
-
}
|
|
25
|
-
const offset = convertDurationToOffset(duration);
|
|
26
|
-
if (!datasource_id) {
|
|
27
|
-
throw 'datasource_id is required';
|
|
28
|
-
}
|
|
29
|
-
if (!product_id) {
|
|
30
|
-
throw 'product_id is required';
|
|
31
|
-
}
|
|
32
|
-
if (isNaN(offset)) {
|
|
33
|
-
throw 'duration is invalid';
|
|
34
|
-
}
|
|
35
|
-
const data = await ctx.queryFn({
|
|
36
|
-
//
|
|
37
|
-
series_id,
|
|
38
|
-
datasource_id,
|
|
39
|
-
product_id,
|
|
40
|
-
duration,
|
|
41
|
-
offset,
|
|
42
|
-
time,
|
|
43
|
-
});
|
|
44
|
-
return data;
|
|
45
|
-
},
|
|
46
|
-
serviceOptions: ctx.serviceOptions,
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=provideOHLCFromTimeBackwardService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provideOHLCFromTimeBackwardService.js","sourceRoot":"","sources":["../../src/utils/provideOHLCFromTimeBackwardService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,oCAAoC,EAAE,MAAM,wCAAwC,CAAC;AAC9F,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAalD,EAAE,EAAE;IACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAE5D,0BAA0B,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAE3F,oCAAoC,CAAQ;QAC1C,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,MAAM;QACZ,sBAAsB,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC;QAC3C,OAAO,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;YACrC,4CAA4C;YAC5C,2CAA2C;YAC3C,MAAM,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;YAEpE,IAAI,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBAC3D,MAAM,YAAY,QAAQ,mBAAmB,CAAC;aAC/C;YAED,MAAM,MAAM,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,CAAC,aAAa,EAAE;gBAClB,MAAM,2BAA2B,CAAC;aACnC;YACD,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,wBAAwB,CAAC;aAChC;YACD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE;gBACjB,MAAM,qBAAqB,CAAC;aAC7B;YACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC;gBAC7B,EAAE;gBACF,SAAS;gBACT,aAAa;gBACb,UAAU;gBACV,QAAQ;gBACR,MAAM;gBACN,IAAI;aACL,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;QACD,cAAc,EAAE,GAAG,CAAC,cAAc;KACnC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { IOHLC, provideOHLCDurationService } from '@yuants/data-ohlc';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { provideSeriesFromTimeBackwardService } from './provideSeriesFromTimeBackwardService';\nimport { convertDurationToOffset, decodePath } from '@yuants/utils';\n\n/**\n * Provide OHLC from time backward service\n *\n * 提供 K线数据 按时间向后查询服务\n *\n * @public\n */\nexport const provideOHLCFromTimeBackwardService = (ctx: {\n terminal: Terminal;\n datasource_id: string;\n supported_durations: string[];\n queryFn: (ctx: {\n series_id: string;\n datasource_id: string;\n product_id: string;\n duration: string;\n offset: number;\n time: string;\n }) => Promise<IOHLC[]>;\n serviceOptions: IServiceOptions;\n}) => {\n const supportedDurations = new Set(ctx.supported_durations);\n\n provideOHLCDurationService(ctx.terminal, ctx.datasource_id, () => ctx.supported_durations);\n\n provideSeriesFromTimeBackwardService<IOHLC>({\n terminal: ctx.terminal,\n type: 'ohlc',\n series_id_prefix_parts: [ctx.datasource_id],\n queryFn: async ({ series_id, time }) => {\n // series_id 格式: OKX/{product_id}/{duration}\n // 其中 product_id 可能包含转义的 /,如 SPOT\\/BTC-USDT\n const [datasource_id, product_id, duration] = decodePath(series_id);\n\n if (supportedDurations && !supportedDurations.has(duration)) {\n throw `duration ${duration} is not supported`;\n }\n\n const offset = convertDurationToOffset(duration);\n if (!datasource_id) {\n throw 'datasource_id is required';\n }\n if (!product_id) {\n throw 'product_id is required';\n }\n if (isNaN(offset)) {\n throw 'duration is invalid';\n }\n const data = await ctx.queryFn({\n //\n series_id,\n datasource_id,\n product_id,\n duration,\n offset,\n time,\n });\n return data;\n },\n serviceOptions: ctx.serviceOptions,\n });\n};\n"]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { buildInsertManyIntoTableSQL, requestSQL } from '@yuants/sql';
|
|
2
|
-
import { encodePath, escapeRegExp } from '@yuants/utils';
|
|
3
|
-
/**
|
|
4
|
-
* Provide series from time backward service
|
|
5
|
-
*
|
|
6
|
-
* 提供从时间点向前 (不包含该时间点) 查询序列数据的服务
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export const provideSeriesFromTimeBackwardService = (ctx) => {
|
|
11
|
-
ctx.terminal.server.provideService('QuerySeriesFromTimeBackward', {
|
|
12
|
-
type: 'object',
|
|
13
|
-
required: ['type', 'series_id', 'time'],
|
|
14
|
-
properties: {
|
|
15
|
-
type: { const: ctx.type },
|
|
16
|
-
series_id: { type: 'string', pattern: `^${escapeRegExp(encodePath(ctx.series_id_prefix_parts))}/` },
|
|
17
|
-
time: { type: 'string', format: 'date-time' },
|
|
18
|
-
},
|
|
19
|
-
}, async (msg) => {
|
|
20
|
-
const { time, series_id } = msg.req;
|
|
21
|
-
const data = await ctx.queryFn({ series_id, time });
|
|
22
|
-
return {
|
|
23
|
-
res: {
|
|
24
|
-
code: 0,
|
|
25
|
-
message: 'OK',
|
|
26
|
-
data,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}, ctx.serviceOptions);
|
|
30
|
-
ctx.terminal.server.provideService('UpdateSeriesFromTimeBackward', {
|
|
31
|
-
type: 'object',
|
|
32
|
-
required: ['type', 'series_id', 'time'],
|
|
33
|
-
properties: {
|
|
34
|
-
type: { const: ctx.type },
|
|
35
|
-
series_id: { type: 'string' },
|
|
36
|
-
time: { type: 'string', format: 'date-time' },
|
|
37
|
-
},
|
|
38
|
-
}, async (msg) => {
|
|
39
|
-
const res = await ctx.terminal.client.requestForResponse('QuerySeriesFromTimeBackward', msg.req);
|
|
40
|
-
if (!res.data) {
|
|
41
|
-
return { res };
|
|
42
|
-
}
|
|
43
|
-
if (res.data.length > 0) {
|
|
44
|
-
await requestSQL(ctx.terminal, buildInsertManyIntoTableSQL(res.data, 'ohlc', {
|
|
45
|
-
conflictKeys: ['series_id', 'created_at'],
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
res: {
|
|
50
|
-
code: 0,
|
|
51
|
-
message: 'OK',
|
|
52
|
-
data: {
|
|
53
|
-
count: res.data.length,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=provideSeriesFromTimeBackwardService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provideSeriesFromTimeBackwardService.js","sourceRoot":"","sources":["../../src/utils/provideSeriesFromTimeBackwardService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzD;;;;;;GAMG;A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C;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtD,6BAA6B,EAC7B,GAAG,CAAC,GAAG,CACR,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACb,OAAO,EAAE,GAAG,EAAE,CAAC;SAChB;QAED,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,MAAM,UAAU,CACd,GAAG,CAAC,QAAQ,EACZ,2BAA2B,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE;gBAC5C,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;aAC1C,CAAC,CACH,CAAC;SACH;QAED,OAAO;YACL,GAAG,EAAE;gBACH,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE;oBACJ,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM;iBACvB;aACF;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { buildInsertManyIntoTableSQL, requestSQL } from '@yuants/sql';\nimport { encodePath, escapeRegExp } from '@yuants/utils';\n\n/**\n * Provide series from time backward service\n *\n * 提供从时间点向前 (不包含该时间点) 查询序列数据的服务\n *\n * @public\n */\nexport const provideSeriesFromTimeBackwardService = <\n T extends { series_id: string; created_at: string },\n>(ctx: {\n terminal: Terminal;\n type: string;\n series_id_prefix_parts: string[];\n queryFn: (ctx: { series_id: string; time: string }) => Promise<T[]>;\n serviceOptions?: IServiceOptions;\n}) => {\n interface IQuerySeriesFromTimeBackwardReq {\n time: string;\n type: string;\n series_id: string;\n }\n\n ctx.terminal.server.provideService<IQuerySeriesFromTimeBackwardReq, T[]>(\n 'QuerySeriesFromTimeBackward',\n {\n type: 'object',\n required: ['type', 'series_id', 'time'],\n properties: {\n type: { const: ctx.type },\n series_id: { type: 'string', pattern: `^${escapeRegExp(encodePath(ctx.series_id_prefix_parts))}/` },\n time: { type: 'string', format: 'date-time' },\n },\n },\n async (msg) => {\n const { time, series_id } = msg.req;\n\n const data = await ctx.queryFn({ series_id, time });\n\n return {\n res: {\n code: 0,\n message: 'OK',\n data,\n },\n };\n },\n ctx.serviceOptions,\n );\n\n ctx.terminal.server.provideService<IQuerySeriesFromTimeBackwardReq, {}>(\n 'UpdateSeriesFromTimeBackward',\n {\n type: 'object',\n required: ['type', 'series_id', 'time'],\n properties: {\n type: { const: ctx.type },\n series_id: { type: 'string' },\n time: { type: 'string', format: 'date-time' },\n },\n },\n async (msg) => {\n const res = await ctx.terminal.client.requestForResponse<IQuerySeriesFromTimeBackwardReq, T[]>(\n 'QuerySeriesFromTimeBackward',\n msg.req,\n );\n\n if (!res.data) {\n return { res };\n }\n\n if (res.data.length > 0) {\n await requestSQL(\n ctx.terminal,\n buildInsertManyIntoTableSQL(res.data, 'ohlc', {\n conflictKeys: ['series_id', 'created_at'],\n }),\n );\n }\n\n return {\n res: {\n code: 0,\n message: 'OK',\n data: {\n count: res.data.length,\n },\n },\n };\n },\n );\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../../src/public-data/interest_rate.ts"],"names":[],"mappings":""}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
3
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
4
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
5
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
6
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
7
|
-
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); }); }; }
|
|
8
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
9
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
10
|
-
function fulfill(value) { resume("next", value); }
|
|
11
|
-
function reject(value) { resume("throw", value); }
|
|
12
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const data_series_1 = require("@yuants/data-series");
|
|
16
|
-
const protocol_1 = require("@yuants/protocol");
|
|
17
|
-
const utils_1 = require("@yuants/utils");
|
|
18
|
-
const rxjs_1 = require("rxjs");
|
|
19
|
-
const public_api_1 = require("../api/public-api");
|
|
20
|
-
(0, data_series_1.createSeriesProvider)(protocol_1.Terminal.fromNodeEnv(), {
|
|
21
|
-
tableName: 'interest_rate',
|
|
22
|
-
series_id_prefix_parts: ['OKX'],
|
|
23
|
-
reversed: true,
|
|
24
|
-
serviceOptions: { concurrent: 1 },
|
|
25
|
-
queryFn: function ({ series_id, started_at, ended_at }) {
|
|
26
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
27
|
-
const start = started_at || 0;
|
|
28
|
-
const end = ended_at || Date.now();
|
|
29
|
-
const [, instType, instId] = (0, utils_1.decodePath)(series_id);
|
|
30
|
-
if (instType === 'SWAP') {
|
|
31
|
-
let current_end = end;
|
|
32
|
-
while (true) {
|
|
33
|
-
// 接口行为备注:向前翻页,时间降序,不含 after 当前时间点
|
|
34
|
-
const res = yield __await((0, public_api_1.getFundingRateHistory)({
|
|
35
|
-
instId: instId,
|
|
36
|
-
after: `${current_end}`,
|
|
37
|
-
}));
|
|
38
|
-
if (res.code !== '0') {
|
|
39
|
-
throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;
|
|
40
|
-
}
|
|
41
|
-
// 如果没有数据了,就退出
|
|
42
|
-
if (res.data.length === 0) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));
|
|
46
|
-
const data = res.data.map((v) => ({
|
|
47
|
-
series_id: series_id,
|
|
48
|
-
product_id: series_id,
|
|
49
|
-
datasource_id: 'OKX',
|
|
50
|
-
created_at: (0, utils_1.formatTime)(+v.fundingTime),
|
|
51
|
-
long_rate: `${-v.fundingRate}`,
|
|
52
|
-
short_rate: `${v.fundingRate}`,
|
|
53
|
-
settlement_price: '',
|
|
54
|
-
}));
|
|
55
|
-
yield yield __await(data);
|
|
56
|
-
current_end = +res.data[res.data.length - 1].fundingTime;
|
|
57
|
-
if (current_end <= start) {
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
// for API rate limit
|
|
61
|
-
yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (instType === 'MARGIN') {
|
|
65
|
-
// MARGIN/BTC-USDT
|
|
66
|
-
const [base, quote] = instId.split('-');
|
|
67
|
-
let current_end = end;
|
|
68
|
-
while (true) {
|
|
69
|
-
const resBase = yield __await((0, public_api_1.getLendingRateHistory)({ ccy: base, after: `${current_end}` }));
|
|
70
|
-
const resQuote = yield __await((0, public_api_1.getLendingRateHistory)({ ccy: quote, after: `${current_end}` }));
|
|
71
|
-
if (resBase.code !== '0') {
|
|
72
|
-
throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;
|
|
73
|
-
}
|
|
74
|
-
if (resBase.data.length === 0) {
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));
|
|
78
|
-
if (resQuote.code !== '0') {
|
|
79
|
-
throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;
|
|
80
|
-
}
|
|
81
|
-
if (resQuote.data.length === 0) {
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));
|
|
85
|
-
// 做多时,借入 quote 的资金,做空时,借入 base 的资金
|
|
86
|
-
// 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate
|
|
87
|
-
const mapTsToBaseRate = new Map();
|
|
88
|
-
resBase.data.forEach((v) => {
|
|
89
|
-
mapTsToBaseRate.set(v.ts, v.rate);
|
|
90
|
-
});
|
|
91
|
-
const data = [];
|
|
92
|
-
resQuote.data.forEach((v) => {
|
|
93
|
-
if (!mapTsToBaseRate.has(v.ts))
|
|
94
|
-
return;
|
|
95
|
-
const long_rate = +v.rate / 365 / 24; // 转换为小时利率
|
|
96
|
-
const short_rate = +mapTsToBaseRate.get(v.ts) / 365 / 24; // 转换为小时利率
|
|
97
|
-
data.push({
|
|
98
|
-
series_id,
|
|
99
|
-
product_id: series_id,
|
|
100
|
-
datasource_id: 'OKX',
|
|
101
|
-
created_at: (0, utils_1.formatTime)(+v.ts),
|
|
102
|
-
long_rate: `${-long_rate}`,
|
|
103
|
-
short_rate: `${-short_rate}`,
|
|
104
|
-
settlement_price: '',
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
yield yield __await(data);
|
|
108
|
-
current_end = new Date(data[data.length - 1].created_at).getTime();
|
|
109
|
-
if (current_end <= start) {
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
// for API rate limit
|
|
113
|
-
yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
//# sourceMappingURL=interest_rate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interest_rate.js","sourceR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I,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBAChD,MAAM,UAAU,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBACrE,IAAI,CAAC,IAAI,CAAC;4BACR,SAAS;4BACT,UAAU,EAAE,SAAS;4BACrB,aAAa,EAAE,KAAK;4BACpB,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE;4BAC1B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;4BAC5B,gBAAgB,EAAE,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,oBAAM,IAAI,CAAA,CAAC;oBACX,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,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 } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\n});\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { IOHLC } from '@yuants/data-ohlc';
|
|
2
|
-
import { IServiceOptions, Terminal } from '@yuants/protocol';
|
|
3
|
-
/**
|
|
4
|
-
* Provide OHLC from time backward service
|
|
5
|
-
*
|
|
6
|
-
* 提供 K线数据 按时间向后查询服务
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export declare const provideOHLCFromTimeBackwardService: (ctx: {
|
|
11
|
-
terminal: Terminal;
|
|
12
|
-
datasource_id: string;
|
|
13
|
-
supported_durations: string[];
|
|
14
|
-
queryFn: (ctx: {
|
|
15
|
-
series_id: string;
|
|
16
|
-
datasource_id: string;
|
|
17
|
-
product_id: string;
|
|
18
|
-
duration: string;
|
|
19
|
-
offset: number;
|
|
20
|
-
time: string;
|
|
21
|
-
}) => Promise<IOHLC[]>;
|
|
22
|
-
serviceOptions: IServiceOptions;
|
|
23
|
-
}) => void;
|
|
24
|
-
//# sourceMappingURL=provideOHLCFromTimeBackwardService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provideOHLCFromTimeBackwardService.d.ts","sourceRoot":"","sources":["../../src/utils/provideOHLCFromTimeBackwardService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA8B,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI7D;;;;;;GAMG;AACH,eAAO,MAAM,kCAAkC;cACnC,QAAQ;mBACH,MAAM;yBACA,MAAM,EAAE;mBACd;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,QAAQ,KAAK,EAAE,CAAC;oBACN,eAAe;UA0ChC,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.provideOHLCFromTimeBackwardService = void 0;
|
|
4
|
-
const data_ohlc_1 = require("@yuants/data-ohlc");
|
|
5
|
-
const provideSeriesFromTimeBackwardService_1 = require("./provideSeriesFromTimeBackwardService");
|
|
6
|
-
const utils_1 = require("@yuants/utils");
|
|
7
|
-
/**
|
|
8
|
-
* Provide OHLC from time backward service
|
|
9
|
-
*
|
|
10
|
-
* 提供 K线数据 按时间向后查询服务
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
const provideOHLCFromTimeBackwardService = (ctx) => {
|
|
15
|
-
const supportedDurations = new Set(ctx.supported_durations);
|
|
16
|
-
(0, data_ohlc_1.provideOHLCDurationService)(ctx.terminal, ctx.datasource_id, () => ctx.supported_durations);
|
|
17
|
-
(0, provideSeriesFromTimeBackwardService_1.provideSeriesFromTimeBackwardService)({
|
|
18
|
-
terminal: ctx.terminal,
|
|
19
|
-
type: 'ohlc',
|
|
20
|
-
series_id_prefix_parts: [ctx.datasource_id],
|
|
21
|
-
queryFn: async ({ series_id, time }) => {
|
|
22
|
-
// series_id 格式: OKX/{product_id}/{duration}
|
|
23
|
-
// 其中 product_id 可能包含转义的 /,如 SPOT\/BTC-USDT
|
|
24
|
-
const [datasource_id, product_id, duration] = (0, utils_1.decodePath)(series_id);
|
|
25
|
-
if (supportedDurations && !supportedDurations.has(duration)) {
|
|
26
|
-
throw `duration ${duration} is not supported`;
|
|
27
|
-
}
|
|
28
|
-
const offset = (0, utils_1.convertDurationToOffset)(duration);
|
|
29
|
-
if (!datasource_id) {
|
|
30
|
-
throw 'datasource_id is required';
|
|
31
|
-
}
|
|
32
|
-
if (!product_id) {
|
|
33
|
-
throw 'product_id is required';
|
|
34
|
-
}
|
|
35
|
-
if (isNaN(offset)) {
|
|
36
|
-
throw 'duration is invalid';
|
|
37
|
-
}
|
|
38
|
-
const data = await ctx.queryFn({
|
|
39
|
-
//
|
|
40
|
-
series_id,
|
|
41
|
-
datasource_id,
|
|
42
|
-
product_id,
|
|
43
|
-
duration,
|
|
44
|
-
offset,
|
|
45
|
-
time,
|
|
46
|
-
});
|
|
47
|
-
return data;
|
|
48
|
-
},
|
|
49
|
-
serviceOptions: ctx.serviceOptions,
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
exports.provideOHLCFromTimeBackwardService = provideOHLCFromTimeBackwardService;
|
|
53
|
-
//# sourceMappingURL=provideOHLCFromTimeBackwardService.js.map
|