@yuants/vendor-okx 0.31.11 → 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/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/public-data/ohlc.js +13 -163
- package/dist/public-data/ohlc.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/public-data/ohlc.js +12 -162
- package/lib/public-data/ohlc.js.map +1 -1
- package/package.json +6 -6
- package/temp/build/typescript/ts_xKrCYDcc.json +1 -1
- package/temp/package-deps.json +6 -9
- package/temp/test/jest/haste-map-0104fb5fee08bd97aacd02300cdbf195-f3ddf881f4f21e2e5ae6006d95adf2b1-267deb988b5111321a1cf92c4d020334 +0 -0
- package/dist/public-data/interest_rate.js +0 -118
- 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 -120
- 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": "
|
|
2
|
+
"apps/vendor-okx/CHANGELOG.json": "ebd0cc367fb3c8f95cbc91e8a22a3db469d33817",
|
|
3
|
+
"apps/vendor-okx/CHANGELOG.md": "84e5e4fec4ea743835e76763251b6a000f7b9a9e",
|
|
4
|
+
"apps/vendor-okx/README.md": "4aae651c410c9f8271170ba1cae3886eb804aeef",
|
|
5
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,10 +33,9 @@
|
|
|
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",
|
|
@@ -47,8 +46,6 @@
|
|
|
47
46
|
"apps/vendor-okx/src/strategy-account.ts": "2d8f913e19c4402eab249291aaab0b77bc4d9ff8",
|
|
48
47
|
"apps/vendor-okx/src/trade.ts": "17a2afcdbf2ec69944a73d3d097660675dbe09a4",
|
|
49
48
|
"apps/vendor-okx/src/transfer.ts": "381e4bf18846c8f79d3e970277d8800a2f94dacd",
|
|
50
|
-
"apps/vendor-okx/src/utils/provideOHLCFromTimeBackwardService.ts": "3a44206410b5b73683f2395d6c551549b553d7bd",
|
|
51
|
-
"apps/vendor-okx/src/utils/provideSeriesFromTimeBackwardService.ts": "daf3c793eb4fc20e59a740bb69e50fadab5f62f0",
|
|
52
49
|
"apps/vendor-okx/src/ws.ts": "5e8fe8c97c7da92c08ddf07ab47faf7976433ca3",
|
|
53
50
|
"apps/vendor-okx/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
54
51
|
"apps/vendor-okx/.rush/temp/shrinkwrap-deps.json": "78ed978c70324a38a821b4a91b473bb6423f73e4",
|
|
Binary file
|
|
@@ -1,118 +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 = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
6
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
7
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
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
|
-
import { createSeriesProvider } from '@yuants/data-series';
|
|
15
|
-
import { Terminal } from '@yuants/protocol';
|
|
16
|
-
import { decodePath, formatTime } from '@yuants/utils';
|
|
17
|
-
import { firstValueFrom, timer } from 'rxjs';
|
|
18
|
-
import { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';
|
|
19
|
-
createSeriesProvider(Terminal.fromNodeEnv(), {
|
|
20
|
-
tableName: 'interest_rate',
|
|
21
|
-
series_id_prefix_parts: ['OKX'],
|
|
22
|
-
reversed: true,
|
|
23
|
-
serviceOptions: { concurrent: 1 },
|
|
24
|
-
queryFn: function (_a) {
|
|
25
|
-
return __asyncGenerator(this, arguments, function* ({ series_id, started_at, ended_at }) {
|
|
26
|
-
const start = started_at || 0;
|
|
27
|
-
const end = ended_at || Date.now();
|
|
28
|
-
const [, instType, instId] = decodePath(series_id);
|
|
29
|
-
if (instType === 'SWAP') {
|
|
30
|
-
let current_end = end;
|
|
31
|
-
while (true) {
|
|
32
|
-
// 接口行为备注:向前翻页,时间降序,不含 after 当前时间点
|
|
33
|
-
const res = yield __await(getFundingRateHistory({
|
|
34
|
-
instId: instId,
|
|
35
|
-
after: `${current_end}`,
|
|
36
|
-
}));
|
|
37
|
-
if (res.code !== '0') {
|
|
38
|
-
throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;
|
|
39
|
-
}
|
|
40
|
-
// 如果没有数据了,就退出
|
|
41
|
-
if (res.data.length === 0) {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));
|
|
45
|
-
const data = res.data.map((v) => ({
|
|
46
|
-
series_id: series_id,
|
|
47
|
-
product_id: series_id,
|
|
48
|
-
datasource_id: 'OKX',
|
|
49
|
-
created_at: formatTime(+v.fundingTime),
|
|
50
|
-
long_rate: `${-v.fundingRate}`,
|
|
51
|
-
short_rate: `${v.fundingRate}`,
|
|
52
|
-
settlement_price: '',
|
|
53
|
-
}));
|
|
54
|
-
yield yield __await(data);
|
|
55
|
-
current_end = +res.data[res.data.length - 1].fundingTime;
|
|
56
|
-
if (current_end <= start) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
// for API rate limit
|
|
60
|
-
yield __await(firstValueFrom(timer(1000)));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (instType === 'MARGIN') {
|
|
64
|
-
// MARGIN/BTC-USDT
|
|
65
|
-
const [base, quote] = instId.split('-');
|
|
66
|
-
let current_end = end;
|
|
67
|
-
while (true) {
|
|
68
|
-
const resBase = yield __await(getLendingRateHistory({ ccy: base, after: `${current_end}` }));
|
|
69
|
-
const resQuote = yield __await(getLendingRateHistory({ ccy: quote, after: `${current_end}` }));
|
|
70
|
-
if (resBase.code !== '0') {
|
|
71
|
-
throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;
|
|
72
|
-
}
|
|
73
|
-
if (resBase.data.length === 0) {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));
|
|
77
|
-
if (resQuote.code !== '0') {
|
|
78
|
-
throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;
|
|
79
|
-
}
|
|
80
|
-
if (resQuote.data.length === 0) {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));
|
|
84
|
-
// 做多时,借入 quote 的资金,做空时,借入 base 的资金
|
|
85
|
-
// 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate
|
|
86
|
-
const mapTsToBaseRate = new Map();
|
|
87
|
-
resBase.data.forEach((v) => {
|
|
88
|
-
mapTsToBaseRate.set(v.ts, v.rate);
|
|
89
|
-
});
|
|
90
|
-
const data = [];
|
|
91
|
-
resQuote.data.forEach((v) => {
|
|
92
|
-
if (!mapTsToBaseRate.has(v.ts))
|
|
93
|
-
return;
|
|
94
|
-
const long_rate = +v.rate / 365 / 24; // 转换为小时利率
|
|
95
|
-
const short_rate = +mapTsToBaseRate.get(v.ts) / 365 / 24; // 转换为小时利率
|
|
96
|
-
data.push({
|
|
97
|
-
series_id,
|
|
98
|
-
product_id: series_id,
|
|
99
|
-
datasource_id: 'OKX',
|
|
100
|
-
created_at: formatTime(+v.ts),
|
|
101
|
-
long_rate: `${-long_rate}`,
|
|
102
|
-
short_rate: `${-short_rate}`,
|
|
103
|
-
settlement_price: '',
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
yield yield __await(data);
|
|
107
|
-
current_end = new Date(data[data.length - 1].created_at).getTime();
|
|
108
|
-
if (current_end <= start) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
// for API rate limit
|
|
112
|
-
yield __await(firstValueFrom(timer(1000)));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
//# 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,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,M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AI,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,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,CAAC;wBACzB,MAAM;oBACR,CAAC;oBACD,qBAAqB;oBACrB,cAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC;gBACpC,CAAC;YACH,CAAC;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,CAAC;gBAC5D,MAAM,YAAY,QAAQ,mBAAmB,CAAC;YAChD,CAAC;YAED,MAAM,MAAM,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,2BAA2B,CAAC;YACpC,CAAC;YACD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,wBAAwB,CAAC;YACjC,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClB,MAAM,qBAAqB,CAAC;YAC9B,CAAC;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,2BAA2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S,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE;SAC9C;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,CAAC;YACd,OAAO,EAAE,GAAG,EAAE,CAAC;QACjB,CAAC;QAED,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,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;QACJ,CAAC;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,120 +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 = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
7
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
8
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
9
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
10
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
11
|
-
function fulfill(value) { resume("next", value); }
|
|
12
|
-
function reject(value) { resume("throw", value); }
|
|
13
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const data_series_1 = require("@yuants/data-series");
|
|
17
|
-
const protocol_1 = require("@yuants/protocol");
|
|
18
|
-
const utils_1 = require("@yuants/utils");
|
|
19
|
-
const rxjs_1 = require("rxjs");
|
|
20
|
-
const public_api_1 = require("../api/public-api");
|
|
21
|
-
(0, data_series_1.createSeriesProvider)(protocol_1.Terminal.fromNodeEnv(), {
|
|
22
|
-
tableName: 'interest_rate',
|
|
23
|
-
series_id_prefix_parts: ['OKX'],
|
|
24
|
-
reversed: true,
|
|
25
|
-
serviceOptions: { concurrent: 1 },
|
|
26
|
-
queryFn: function (_a) {
|
|
27
|
-
return __asyncGenerator(this, arguments, function* ({ series_id, started_at, ended_at }) {
|
|
28
|
-
const start = started_at || 0;
|
|
29
|
-
const end = ended_at || Date.now();
|
|
30
|
-
const [, instType, instId] = (0, utils_1.decodePath)(series_id);
|
|
31
|
-
if (instType === 'SWAP') {
|
|
32
|
-
let current_end = end;
|
|
33
|
-
while (true) {
|
|
34
|
-
// 接口行为备注:向前翻页,时间降序,不含 after 当前时间点
|
|
35
|
-
const res = yield __await((0, public_api_1.getFundingRateHistory)({
|
|
36
|
-
instId: instId,
|
|
37
|
-
after: `${current_end}`,
|
|
38
|
-
}));
|
|
39
|
-
if (res.code !== '0') {
|
|
40
|
-
throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;
|
|
41
|
-
}
|
|
42
|
-
// 如果没有数据了,就退出
|
|
43
|
-
if (res.data.length === 0) {
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));
|
|
47
|
-
const data = res.data.map((v) => ({
|
|
48
|
-
series_id: series_id,
|
|
49
|
-
product_id: series_id,
|
|
50
|
-
datasource_id: 'OKX',
|
|
51
|
-
created_at: (0, utils_1.formatTime)(+v.fundingTime),
|
|
52
|
-
long_rate: `${-v.fundingRate}`,
|
|
53
|
-
short_rate: `${v.fundingRate}`,
|
|
54
|
-
settlement_price: '',
|
|
55
|
-
}));
|
|
56
|
-
yield yield __await(data);
|
|
57
|
-
current_end = +res.data[res.data.length - 1].fundingTime;
|
|
58
|
-
if (current_end <= start) {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
// for API rate limit
|
|
62
|
-
yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (instType === 'MARGIN') {
|
|
66
|
-
// MARGIN/BTC-USDT
|
|
67
|
-
const [base, quote] = instId.split('-');
|
|
68
|
-
let current_end = end;
|
|
69
|
-
while (true) {
|
|
70
|
-
const resBase = yield __await((0, public_api_1.getLendingRateHistory)({ ccy: base, after: `${current_end}` }));
|
|
71
|
-
const resQuote = yield __await((0, public_api_1.getLendingRateHistory)({ ccy: quote, after: `${current_end}` }));
|
|
72
|
-
if (resBase.code !== '0') {
|
|
73
|
-
throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;
|
|
74
|
-
}
|
|
75
|
-
if (resBase.data.length === 0) {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));
|
|
79
|
-
if (resQuote.code !== '0') {
|
|
80
|
-
throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;
|
|
81
|
-
}
|
|
82
|
-
if (resQuote.data.length === 0) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
console.info((0, utils_1.formatTime)(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));
|
|
86
|
-
// 做多时,借入 quote 的资金,做空时,借入 base 的资金
|
|
87
|
-
// 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate
|
|
88
|
-
const mapTsToBaseRate = new Map();
|
|
89
|
-
resBase.data.forEach((v) => {
|
|
90
|
-
mapTsToBaseRate.set(v.ts, v.rate);
|
|
91
|
-
});
|
|
92
|
-
const data = [];
|
|
93
|
-
resQuote.data.forEach((v) => {
|
|
94
|
-
if (!mapTsToBaseRate.has(v.ts))
|
|
95
|
-
return;
|
|
96
|
-
const long_rate = +v.rate / 365 / 24; // 转换为小时利率
|
|
97
|
-
const short_rate = +mapTsToBaseRate.get(v.ts) / 365 / 24; // 转换为小时利率
|
|
98
|
-
data.push({
|
|
99
|
-
series_id,
|
|
100
|
-
product_id: series_id,
|
|
101
|
-
datasource_id: 'OKX',
|
|
102
|
-
created_at: (0, utils_1.formatTime)(+v.ts),
|
|
103
|
-
long_rate: `${-long_rate}`,
|
|
104
|
-
short_rate: `${-short_rate}`,
|
|
105
|
-
settlement_price: '',
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
yield yield __await(data);
|
|
109
|
-
current_end = new Date(data[data.length - 1].created_at).getTime();
|
|
110
|
-
if (current_end <= start) {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
// for API rate limit
|
|
114
|
-
yield __await((0, rxjs_1.firstValueFrom)((0, rxjs_1.timer)(1000)));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
//# 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,qDAA2D;AAC3D,+CAA4C;AAC5C,yCAAuD;AACvD,+BAA6C;AAC7C,kDAAiF;AAEjF,IAAA,kCAAoB,EAAgB,mBAAQ,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,CAAC,EAAE;IACjC,OAAO,EAAE;4DAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE;YAC3D,MAAM,KAAK,GAAG,UAAU,IAAI,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,SAAS,CAAC,CAAC;YAEnD,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACxB,IAAI,WAAW,GAAG,GAAG,CAAC;gBACtB,OAAO,IAAI,EAAE,CAAC;oBACZ,kCAAkC;oBAClC,MAAM,GAAG,GAAG,cAAM,IAAA,kCAAqB,EAAC;wBACtC,MAAM,EAAE,MAAM;wBACd,KAAK,EAAE,GAAG,WAAW,EAAE;qBACxB,CAAC,CAAA,CAAC;oBACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;wBACrB,MAAM,iC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H,CAAC;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,GAAI,KAAK;IACtD,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE;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,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACvB,cAAc,EAAE,eAAe,CAAC;CACjC,SAyCA,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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provideOHLCFromTimeBackwardService.js","sourceRoot":"","sources":["../../src/utils/provideOHLCFromTimeBackwardService.ts"],"names":[],"mappings":";;;AAAA,iDAAsE;AAEtE,iGAA8F;AAC9F,yCAAoE;AAEpE;;;;;;GAMG;AACI,MAAM,kCAAkC,GAAG,CAAC,GAalD,EAAE,EAAE;IACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAE5D,IAAA,sCAA0B,EAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAE3F,IAAA,2EAAoC,EAAQ;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,IAAA,kBAAU,EAAC,SAAS,CAAC,CAAC;YAEpE,IAAI,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5D,MAAM,YAAY,QAAQ,mBAAmB,CAAC;YAChD,CAAC;YAED,MAAM,MAAM,GAAG,IAAA,+BAAuB,EAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,2BAA2B,CAAC;YACpC,CAAC;YACD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,wBAAwB,CAAC;YACjC,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClB,MAAM,qBAAqB,CAAC;YAC9B,CAAC;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;AAtDW,QAAA,kCAAkC,sCAsD7C","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,22 +0,0 @@
|
|
|
1
|
-
import { IServiceOptions, Terminal } from '@yuants/protocol';
|
|
2
|
-
/**
|
|
3
|
-
* Provide series from time backward service
|
|
4
|
-
*
|
|
5
|
-
* 提供从时间点向前 (不包含该时间点) 查询序列数据的服务
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export declare const provideSeriesFromTimeBackwardService: <T extends {
|
|
10
|
-
series_id: string;
|
|
11
|
-
created_at: string;
|
|
12
|
-
}>(ctx: {
|
|
13
|
-
terminal: Terminal;
|
|
14
|
-
type: string;
|
|
15
|
-
series_id_prefix_parts: string[];
|
|
16
|
-
queryFn: (ctx: {
|
|
17
|
-
series_id: string;
|
|
18
|
-
time: string;
|
|
19
|
-
}) => Promise<T[]>;
|
|
20
|
-
serviceOptions?: IServiceOptions;
|
|
21
|
-
}) => void;
|
|
22
|
-
//# sourceMappingURL=provideSeriesFromTimeBackwardService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provideSeriesFromTimeBackwardService.d.ts","sourceRoot":"","sources":["../../src/utils/provideSeriesFromTimeBackwardService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI7D;;;;;;GAMG;AACH,eAAO,MAAM,oCAAoC,GAC/C,CAAC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EACnD,KAAK;IACL,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,GAAG,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACpE,cAAc,CAAC,EAAE,eAAe,CAAC;CAClC,SA2EA,CAAC"}
|