@yuants/vendor-binance 0.11.4 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/interest-rate-service.js +68 -0
- package/dist/services/interest-rate-service.js.map +1 -0
- package/dist/services/ohlc-service.js +73 -0
- package/dist/services/ohlc-service.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/services/interest-rate-service.d.ts +2 -0
- package/lib/services/interest-rate-service.d.ts.map +1 -0
- package/lib/services/interest-rate-service.js +70 -0
- package/lib/services/interest-rate-service.js.map +1 -0
- package/lib/services/ohlc-service.d.ts +2 -0
- package/lib/services/ohlc-service.d.ts.map +1 -0
- package/lib/services/ohlc-service.js +75 -0
- package/lib/services/ohlc-service.js.map +1 -0
- package/package.json +2 -2
- package/temp/package-deps.json +7 -5
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC","sourcesContent":["import './public-data/interest_rate';\nimport './public-data/ohlc';\nimport './public-data/product';\nimport './public-data/quote';\nimport './services/exchange';\nimport './services/quotes';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC","sourcesContent":["import './public-data/interest_rate';\nimport './public-data/ohlc';\nimport './public-data/product';\nimport './public-data/quote';\nimport './services/exchange';\nimport './services/quotes';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { provideInterestRateService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getMarginInterestRateHistory } from '../api/private-api';
|
|
5
|
+
import { getFutureFundingRate } from '../api/public-api';
|
|
6
|
+
const terminal = Terminal.fromNodeEnv();
|
|
7
|
+
const WINDOW_MS = 365 * 24 * 3600000;
|
|
8
|
+
const fetchUsdtFutureFundingRateForward = async (req) => {
|
|
9
|
+
const [, instType, symbol] = decodePath(req.product_id);
|
|
10
|
+
if (instType !== 'USDT-FUTURE' || !symbol)
|
|
11
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
12
|
+
const startTime = req.time;
|
|
13
|
+
const res = await getFutureFundingRate({
|
|
14
|
+
symbol,
|
|
15
|
+
startTime,
|
|
16
|
+
endTime: startTime + WINDOW_MS,
|
|
17
|
+
limit: 1000,
|
|
18
|
+
});
|
|
19
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
20
|
+
.map((v) => {
|
|
21
|
+
const ms = Number(v.fundingTime);
|
|
22
|
+
const rate = Number(v.fundingRate);
|
|
23
|
+
return {
|
|
24
|
+
series_id: req.series_id,
|
|
25
|
+
product_id: req.product_id,
|
|
26
|
+
datasource_id: 'BINANCE',
|
|
27
|
+
created_at: formatTime(ms),
|
|
28
|
+
long_rate: `${-rate}`,
|
|
29
|
+
short_rate: `${rate}`,
|
|
30
|
+
settlement_price: '',
|
|
31
|
+
};
|
|
32
|
+
})
|
|
33
|
+
.filter((x) => Date.parse(x.created_at) >= startTime);
|
|
34
|
+
};
|
|
35
|
+
const fetchMarginBorrowRateForward = async (req) => {
|
|
36
|
+
const [, instType, asset] = decodePath(req.product_id);
|
|
37
|
+
if (instType !== 'MARGIN' || !asset)
|
|
38
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
39
|
+
const startTime = req.time;
|
|
40
|
+
const res = await getMarginInterestRateHistory({
|
|
41
|
+
asset,
|
|
42
|
+
startTime,
|
|
43
|
+
endTime: startTime + WINDOW_MS,
|
|
44
|
+
limit: 100,
|
|
45
|
+
});
|
|
46
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
47
|
+
.map((v) => {
|
|
48
|
+
return {
|
|
49
|
+
series_id: req.series_id,
|
|
50
|
+
product_id: req.product_id,
|
|
51
|
+
datasource_id: 'BINANCE',
|
|
52
|
+
created_at: formatTime(v.timestamp),
|
|
53
|
+
long_rate: v.dailyInterestRate,
|
|
54
|
+
short_rate: '0',
|
|
55
|
+
settlement_price: '',
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
.filter((x) => Date.parse(x.created_at) >= startTime);
|
|
59
|
+
};
|
|
60
|
+
provideInterestRateService(terminal, {
|
|
61
|
+
product_id_prefix: 'BINANCE/USDT-FUTURE/',
|
|
62
|
+
direction: 'forward',
|
|
63
|
+
}, fetchUsdtFutureFundingRateForward);
|
|
64
|
+
provideInterestRateService(terminal, {
|
|
65
|
+
product_id_prefix: 'BINANCE/MARGIN/',
|
|
66
|
+
direction: 'forward',
|
|
67
|
+
}, fetchMarginBorrowRateForward);
|
|
68
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAA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sBAAsB;IACzC,SAAS,EAAE,SAAS;CACrB,EACD,iCAAiC,CAClC,CAAC;AAEF,0BAA0B,CACxB,QAAQ,EACR;IACE,iBAAiB,EAAE,iBAAiB;IACpC,SAAS,EAAE,SAAS;CACrB,EACD,4BAA4B,CAC7B,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getMarginInterestRateHistory } from '../api/private-api';\nimport { getFutureFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst WINDOW_MS = 365 * 24 * 3600_000;\n\nconst fetchUsdtFutureFundingRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (instType !== 'USDT-FUTURE' || !symbol) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getFutureFundingRate({\n symbol,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 1000,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n const ms = Number(v.fundingTime);\n const rate = Number(v.fundingRate);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nconst fetchMarginBorrowRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, asset] = decodePath(req.product_id);\n if (instType !== 'MARGIN' || !asset) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getMarginInterestRateHistory({\n asset,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 100,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(v.timestamp),\n long_rate: v.dailyInterestRate,\n short_rate: '0',\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n direction: 'forward',\n },\n fetchUsdtFutureFundingRateForward,\n);\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n direction: 'forward',\n },\n fetchMarginBorrowRateForward,\n);\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { provideOHLCService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { requestPublic } from '../api/client';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const DURATION_TO_BINANCE_INTERVAL = {
|
|
7
|
+
PT1M: '1m',
|
|
8
|
+
PT3M: '3m',
|
|
9
|
+
PT5M: '5m',
|
|
10
|
+
PT15M: '15m',
|
|
11
|
+
PT30M: '30m',
|
|
12
|
+
PT1H: '1h',
|
|
13
|
+
PT2H: '2h',
|
|
14
|
+
PT4H: '4h',
|
|
15
|
+
PT6H: '6h',
|
|
16
|
+
PT8H: '8h',
|
|
17
|
+
PT12H: '12h',
|
|
18
|
+
P1D: '1d',
|
|
19
|
+
P3D: '3d',
|
|
20
|
+
P1W: '1w',
|
|
21
|
+
P1M: '1M',
|
|
22
|
+
};
|
|
23
|
+
const fetchOHLCPageBackward = async (req) => {
|
|
24
|
+
const [, instType, symbol] = decodePath(req.product_id);
|
|
25
|
+
if (!instType || !symbol)
|
|
26
|
+
throw new Error(`Invalid product_id: ${req.product_id}`);
|
|
27
|
+
const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];
|
|
28
|
+
if (!interval)
|
|
29
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
30
|
+
const offset = convertDurationToOffset(req.duration);
|
|
31
|
+
const endedAtMs = req.time;
|
|
32
|
+
const baseUrl = instType === 'USDT-FUTURE'
|
|
33
|
+
? 'https://fapi.binance.com/fapi/v1/klines'
|
|
34
|
+
: 'https://api.binance.com/api/v3/klines';
|
|
35
|
+
const res = await requestPublic('GET', baseUrl, {
|
|
36
|
+
symbol,
|
|
37
|
+
interval,
|
|
38
|
+
endTime: endedAtMs,
|
|
39
|
+
limit: 1000,
|
|
40
|
+
});
|
|
41
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
42
|
+
.map((k) => ({
|
|
43
|
+
series_id: req.series_id,
|
|
44
|
+
datasource_id: 'BINANCE',
|
|
45
|
+
product_id: req.product_id,
|
|
46
|
+
duration: req.duration,
|
|
47
|
+
created_at: formatTime(k[0]),
|
|
48
|
+
closed_at: formatTime(k[0] + offset),
|
|
49
|
+
open: `${k[1]}`,
|
|
50
|
+
high: `${k[2]}`,
|
|
51
|
+
low: `${k[3]}`,
|
|
52
|
+
close: `${k[4]}`,
|
|
53
|
+
volume: `${k[5]}`,
|
|
54
|
+
open_interest: '0',
|
|
55
|
+
}))
|
|
56
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
57
|
+
};
|
|
58
|
+
provideOHLCService(terminal, {
|
|
59
|
+
product_id_prefix: 'BINANCE/USDT-FUTURE/',
|
|
60
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
61
|
+
direction: 'backward',
|
|
62
|
+
}, fetchOHLCPageBackward);
|
|
63
|
+
provideOHLCService(terminal, {
|
|
64
|
+
product_id_prefix: 'BINANCE/SPOT/',
|
|
65
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
66
|
+
direction: 'backward',
|
|
67
|
+
}, fetchOHLCPageBackward);
|
|
68
|
+
provideOHLCService(terminal, {
|
|
69
|
+
product_id_prefix: 'BINANCE/MARGIN/',
|
|
70
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
71
|
+
direction: 'backward',
|
|
72
|
+
}, fetchOHLCPageBackward);
|
|
73
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,4BAA4B,GAA2B;IAC3D,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAiBF,MAAM,qBAAqB,GAAG,KAAK,EAAE,GAKpC,EAAoB,EAAE;IACrB,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;IAEnF,MAAM,QAAQ,GAAG,4BAA4B,CAAC,GAAG,CAA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,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,kBAAkB,CAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,sBAAsB;IACzC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC;AAEF,kBAAkB,CAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,eAAe;IAClC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC;AAEF,kBAAkB,CAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { requestPublic } from '../api/client';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst DURATION_TO_BINANCE_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT3M: '3m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT2H: '2h',\n PT4H: '4h',\n PT6H: '6h',\n PT8H: '8h',\n PT12H: '12h',\n P1D: '1d',\n P3D: '3d',\n P1W: '1w',\n P1M: '1M',\n};\n\ntype IBinanceKline = [\n number, // Open time\n string, // Open\n string, // High\n string, // Low\n string, // Close\n string, // Volume\n number, // Close time\n string, // Quote asset volume\n number, // Number of trades\n string, // Taker buy base asset volume\n string, // Taker buy quote asset volume\n string, // Ignore\n];\n\nconst fetchOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (!instType || !symbol) throw new Error(`Invalid product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const baseUrl =\n instType === 'USDT-FUTURE'\n ? 'https://fapi.binance.com/fapi/v1/klines'\n : 'https://api.binance.com/api/v3/klines';\n\n const res = await requestPublic<IBinanceKline[]>('GET', baseUrl, {\n symbol,\n interval,\n endTime: endedAtMs,\n limit: 1000,\n });\n\n return (res ?? [])\n .map(\n (k): IOHLC => ({\n series_id: req.series_id,\n datasource_id: 'BINANCE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k[0]),\n closed_at: formatTime(k[0] + offset),\n open: `${k[1]}`,\n high: `${k[2]}`,\n low: `${k[3]}`,\n close: `${k[4]}`,\n volume: `${k[5]}`,\n open_interest: '0',\n }),\n )\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/SPOT/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAqC;AACrC,8BAA4B;AAC5B,iCAA+B;AAC/B,+BAA6B;AAC7B,+BAA6B;AAC7B,6BAA2B","sourcesContent":["import './public-data/interest_rate';\nimport './public-data/ohlc';\nimport './public-data/product';\nimport './public-data/quote';\nimport './services/exchange';\nimport './services/quotes';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAqC;AACrC,8BAA4B;AAC5B,iCAA+B;AAC/B,+BAA6B;AAC7B,+BAA6B;AAC7B,6BAA2B;AAC3B,mCAAiC;AACjC,4CAA0C","sourcesContent":["import './public-data/interest_rate';\nimport './public-data/ohlc';\nimport './public-data/product';\nimport './public-data/quote';\nimport './services/exchange';\nimport './services/quotes';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.d.ts","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const private_api_1 = require("../api/private-api");
|
|
7
|
+
const public_api_1 = require("../api/public-api");
|
|
8
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
9
|
+
const WINDOW_MS = 365 * 24 * 3600000;
|
|
10
|
+
const fetchUsdtFutureFundingRateForward = async (req) => {
|
|
11
|
+
const [, instType, symbol] = (0, utils_1.decodePath)(req.product_id);
|
|
12
|
+
if (instType !== 'USDT-FUTURE' || !symbol)
|
|
13
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
14
|
+
const startTime = req.time;
|
|
15
|
+
const res = await (0, public_api_1.getFutureFundingRate)({
|
|
16
|
+
symbol,
|
|
17
|
+
startTime,
|
|
18
|
+
endTime: startTime + WINDOW_MS,
|
|
19
|
+
limit: 1000,
|
|
20
|
+
});
|
|
21
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
22
|
+
.map((v) => {
|
|
23
|
+
const ms = Number(v.fundingTime);
|
|
24
|
+
const rate = Number(v.fundingRate);
|
|
25
|
+
return {
|
|
26
|
+
series_id: req.series_id,
|
|
27
|
+
product_id: req.product_id,
|
|
28
|
+
datasource_id: 'BINANCE',
|
|
29
|
+
created_at: (0, utils_1.formatTime)(ms),
|
|
30
|
+
long_rate: `${-rate}`,
|
|
31
|
+
short_rate: `${rate}`,
|
|
32
|
+
settlement_price: '',
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
|
+
.filter((x) => Date.parse(x.created_at) >= startTime);
|
|
36
|
+
};
|
|
37
|
+
const fetchMarginBorrowRateForward = async (req) => {
|
|
38
|
+
const [, instType, asset] = (0, utils_1.decodePath)(req.product_id);
|
|
39
|
+
if (instType !== 'MARGIN' || !asset)
|
|
40
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
41
|
+
const startTime = req.time;
|
|
42
|
+
const res = await (0, private_api_1.getMarginInterestRateHistory)({
|
|
43
|
+
asset,
|
|
44
|
+
startTime,
|
|
45
|
+
endTime: startTime + WINDOW_MS,
|
|
46
|
+
limit: 100,
|
|
47
|
+
});
|
|
48
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
49
|
+
.map((v) => {
|
|
50
|
+
return {
|
|
51
|
+
series_id: req.series_id,
|
|
52
|
+
product_id: req.product_id,
|
|
53
|
+
datasource_id: 'BINANCE',
|
|
54
|
+
created_at: (0, utils_1.formatTime)(v.timestamp),
|
|
55
|
+
long_rate: v.dailyInterestRate,
|
|
56
|
+
short_rate: '0',
|
|
57
|
+
settlement_price: '',
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
.filter((x) => Date.parse(x.created_at) >= startTime);
|
|
61
|
+
};
|
|
62
|
+
(0, exchange_1.provideInterestRateService)(terminal, {
|
|
63
|
+
product_id_prefix: 'BINANCE/USDT-FUTURE/',
|
|
64
|
+
direction: 'forward',
|
|
65
|
+
}, fetchUsdtFutureFundingRateForward);
|
|
66
|
+
(0, exchange_1.provideInterestRateService)(terminal, {
|
|
67
|
+
product_id_prefix: 'BINANCE/MARGIN/',
|
|
68
|
+
direction: 'forward',
|
|
69
|
+
}, fetchMarginBorrowRateForward);
|
|
70
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":";;AACA,+CAA8D;AAC9D,+CAA4C;AAC5C,yCAAuD;AACvD,oDAAkE;AAClE,kDAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,SAAS,GAAG,GAAG,GAAG,EAAE,G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IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getMarginInterestRateHistory } from '../api/private-api';\nimport { getFutureFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst WINDOW_MS = 365 * 24 * 3600_000;\n\nconst fetchUsdtFutureFundingRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (instType !== 'USDT-FUTURE' || !symbol) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getFutureFundingRate({\n symbol,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 1000,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n const ms = Number(v.fundingTime);\n const rate = Number(v.fundingRate);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nconst fetchMarginBorrowRateForward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, asset] = decodePath(req.product_id);\n if (instType !== 'MARGIN' || !asset) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const startTime = req.time;\n const res = await getMarginInterestRateHistory({\n asset,\n startTime,\n endTime: startTime + WINDOW_MS,\n limit: 100,\n });\n\n return (res ?? [])\n .map((v): IInterestRate => {\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'BINANCE',\n created_at: formatTime(v.timestamp),\n long_rate: v.dailyInterestRate,\n short_rate: '0',\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) >= startTime);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n direction: 'forward',\n },\n fetchUsdtFutureFundingRateForward,\n);\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n direction: 'forward',\n },\n fetchMarginBorrowRateForward,\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.d.ts","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const client_1 = require("../api/client");
|
|
7
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const DURATION_TO_BINANCE_INTERVAL = {
|
|
9
|
+
PT1M: '1m',
|
|
10
|
+
PT3M: '3m',
|
|
11
|
+
PT5M: '5m',
|
|
12
|
+
PT15M: '15m',
|
|
13
|
+
PT30M: '30m',
|
|
14
|
+
PT1H: '1h',
|
|
15
|
+
PT2H: '2h',
|
|
16
|
+
PT4H: '4h',
|
|
17
|
+
PT6H: '6h',
|
|
18
|
+
PT8H: '8h',
|
|
19
|
+
PT12H: '12h',
|
|
20
|
+
P1D: '1d',
|
|
21
|
+
P3D: '3d',
|
|
22
|
+
P1W: '1w',
|
|
23
|
+
P1M: '1M',
|
|
24
|
+
};
|
|
25
|
+
const fetchOHLCPageBackward = async (req) => {
|
|
26
|
+
const [, instType, symbol] = (0, utils_1.decodePath)(req.product_id);
|
|
27
|
+
if (!instType || !symbol)
|
|
28
|
+
throw new Error(`Invalid product_id: ${req.product_id}`);
|
|
29
|
+
const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];
|
|
30
|
+
if (!interval)
|
|
31
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
32
|
+
const offset = (0, utils_1.convertDurationToOffset)(req.duration);
|
|
33
|
+
const endedAtMs = req.time;
|
|
34
|
+
const baseUrl = instType === 'USDT-FUTURE'
|
|
35
|
+
? 'https://fapi.binance.com/fapi/v1/klines'
|
|
36
|
+
: 'https://api.binance.com/api/v3/klines';
|
|
37
|
+
const res = await (0, client_1.requestPublic)('GET', baseUrl, {
|
|
38
|
+
symbol,
|
|
39
|
+
interval,
|
|
40
|
+
endTime: endedAtMs,
|
|
41
|
+
limit: 1000,
|
|
42
|
+
});
|
|
43
|
+
return (res !== null && res !== void 0 ? res : [])
|
|
44
|
+
.map((k) => ({
|
|
45
|
+
series_id: req.series_id,
|
|
46
|
+
datasource_id: 'BINANCE',
|
|
47
|
+
product_id: req.product_id,
|
|
48
|
+
duration: req.duration,
|
|
49
|
+
created_at: (0, utils_1.formatTime)(k[0]),
|
|
50
|
+
closed_at: (0, utils_1.formatTime)(k[0] + offset),
|
|
51
|
+
open: `${k[1]}`,
|
|
52
|
+
high: `${k[2]}`,
|
|
53
|
+
low: `${k[3]}`,
|
|
54
|
+
close: `${k[4]}`,
|
|
55
|
+
volume: `${k[5]}`,
|
|
56
|
+
open_interest: '0',
|
|
57
|
+
}))
|
|
58
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
59
|
+
};
|
|
60
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
61
|
+
product_id_prefix: 'BINANCE/USDT-FUTURE/',
|
|
62
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
63
|
+
direction: 'backward',
|
|
64
|
+
}, fetchOHLCPageBackward);
|
|
65
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
66
|
+
product_id_prefix: 'BINANCE/SPOT/',
|
|
67
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
68
|
+
direction: 'backward',
|
|
69
|
+
}, fetchOHLCPageBackward);
|
|
70
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
71
|
+
product_id_prefix: 'BINANCE/MARGIN/',
|
|
72
|
+
duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),
|
|
73
|
+
direction: 'backward',
|
|
74
|
+
}, fetchOHLCPageBackward);
|
|
75
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":";;AACA,+CAAsD;AACtD,+CAA4C;AAC5C,yCAAgF;AAChF,0CAA8C;AAE9C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,4BAA4B,GAA2B;IAC3D,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAiBF,MAAM,qBAAqB,GAAG,KAAK,EAAE,GAKpC,EAAoB,EAAE;IACrB,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;IAEnF,MAAM,QAAQ,GAAG,4BAA4B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,CAAC,QAAQ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AC,CAAC;AACzD,CAAC,CAAC;AAEF,IAAA,6BAAkB,EAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,sBAAsB;IACzC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC;AAEF,IAAA,6BAAkB,EAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,eAAe;IAClC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC;AAEF,IAAA,6BAAkB,EAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC;IACxD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { requestPublic } from '../api/client';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst DURATION_TO_BINANCE_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT3M: '3m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT2H: '2h',\n PT4H: '4h',\n PT6H: '6h',\n PT8H: '8h',\n PT12H: '12h',\n P1D: '1d',\n P3D: '3d',\n P1W: '1w',\n P1M: '1M',\n};\n\ntype IBinanceKline = [\n number, // Open time\n string, // Open\n string, // High\n string, // Low\n string, // Close\n string, // Volume\n number, // Close time\n string, // Quote asset volume\n number, // Number of trades\n string, // Taker buy base asset volume\n string, // Taker buy quote asset volume\n string, // Ignore\n];\n\nconst fetchOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (!instType || !symbol) throw new Error(`Invalid product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_BINANCE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const baseUrl =\n instType === 'USDT-FUTURE'\n ? 'https://fapi.binance.com/fapi/v1/klines'\n : 'https://api.binance.com/api/v3/klines';\n\n const res = await requestPublic<IBinanceKline[]>('GET', baseUrl, {\n symbol,\n interval,\n endTime: endedAtMs,\n limit: 1000,\n });\n\n return (res ?? [])\n .map(\n (k): IOHLC => ({\n series_id: req.series_id,\n datasource_id: 'BINANCE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k[0]),\n closed_at: formatTime(k[0] + offset),\n open: `${k[1]}`,\n high: `${k[2]}`,\n low: `${k[3]}`,\n close: `${k[4]}`,\n volume: `${k[5]}`,\n open_interest: '0',\n }),\n )\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/USDT-FUTURE/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/SPOT/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'BINANCE/MARGIN/',\n duration_list: Object.keys(DURATION_TO_BINANCE_INTERVAL),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-binance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@yuants/data-order": "0.7.1",
|
|
21
21
|
"@yuants/data-interest-rate": "0.1.49",
|
|
22
22
|
"@yuants/transfer": "0.2.40",
|
|
23
|
-
"@yuants/exchange": "0.8.
|
|
23
|
+
"@yuants/exchange": "0.8.1",
|
|
24
24
|
"rxjs": "~7.5.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/temp/package-deps.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-binance/AGENTS.md": "378369925bffa237cd5e8ef459fe2bc2a141337c",
|
|
3
|
-
"apps/vendor-binance/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-binance/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-binance/CHANGELOG.json": "efb7ab1016a81a780e472f9904a0d3d3bc2eb59f",
|
|
4
|
+
"apps/vendor-binance/CHANGELOG.md": "c7d90d4d12fe54c97d65d7e42ecbebee418701a6",
|
|
5
5
|
"apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
|
|
6
6
|
"apps/vendor-binance/SESSION_NOTES.md": "dd49b3364394c502fdcaf687ed5942811d89abe9",
|
|
7
7
|
"apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"apps/vendor-binance/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-binance/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-binance/etc/vendor-binance.api.md": "2094b84e9b5e7503f5c42b31fffee8d7db47fe7b",
|
|
12
|
-
"apps/vendor-binance/package.json": "
|
|
12
|
+
"apps/vendor-binance/package.json": "9d63baaf2321176f62b1d407c9b9649bfe28a7e6",
|
|
13
13
|
"apps/vendor-binance/src/api/client.ts": "fab85d85d10577f0b6430a551dab46d7c1d2258a",
|
|
14
14
|
"apps/vendor-binance/src/api/private-api.ts": "982c1902b8417aba1f75df5fa63db76dfc416dac",
|
|
15
15
|
"apps/vendor-binance/src/api/public-api.ts": "70dc33214e05ec3ead45271bfae70abdb0623c1e",
|
|
16
|
-
"apps/vendor-binance/src/index.ts": "
|
|
16
|
+
"apps/vendor-binance/src/index.ts": "8a1559cfd02fccf4d9c6686669bf177d86b62106",
|
|
17
17
|
"apps/vendor-binance/src/legacy_index.ts": "a2b44c041aa7ef1f4b77249e11f84d97cde5525f",
|
|
18
18
|
"apps/vendor-binance/src/public-data/interest_rate.ts": "a197c30a2cf8acbb389fed8c0687a091320d8113",
|
|
19
19
|
"apps/vendor-binance/src/public-data/ohlc.ts": "bb4f791f96064eca7d45d361ea36cb8ba0ab8fe0",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"apps/vendor-binance/src/services/accounts/spot.ts": "7561d3054c967b48711a4dcedf96946eeab9fab4",
|
|
24
24
|
"apps/vendor-binance/src/services/accounts/unified.ts": "46c772fdad40056462b0b28848d46944954518c8",
|
|
25
25
|
"apps/vendor-binance/src/services/exchange.ts": "c989e025b771f5d5c49efcc779ca388dfb1d488d",
|
|
26
|
+
"apps/vendor-binance/src/services/interest-rate-service.ts": "45d73bedcdc3a4e8de4ee6398b1ad09d09a61b0c",
|
|
27
|
+
"apps/vendor-binance/src/services/ohlc-service.ts": "e8394f9189505afcb3841a34a7219fd03b013b85",
|
|
26
28
|
"apps/vendor-binance/src/services/orders/cancelOrder.ts": "7177ca56fd09b11651edbb38e1962363ac67d4ff",
|
|
27
29
|
"apps/vendor-binance/src/services/orders/listOrders.ts": "baa21b8e858c1ec593415145cc63fb38a6841d3f",
|
|
28
30
|
"apps/vendor-binance/src/services/orders/modifyOrder.ts": "0d1ec4d683e43876e9d53ee29cdc5324301b287e",
|
|
@@ -43,7 +45,7 @@
|
|
|
43
45
|
"libraries/data-order/temp/package-deps.json": "8aa3e27ff80629d417bfe920e85d8525fbb52f42",
|
|
44
46
|
"libraries/data-interest-rate/temp/package-deps.json": "5a1011b097b18b96c2d8c932d874f69472621efd",
|
|
45
47
|
"libraries/transfer/temp/package-deps.json": "7b0db8291734d10d4f1d9c2c25d9e3918cabc79e",
|
|
46
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
48
|
+
"libraries/exchange/temp/package-deps.json": "0f0549ddf97292ceadb8c3cbcc8799e31e7a0901",
|
|
47
49
|
"libraries/extension/temp/package-deps.json": "3e0a81b0c863c2daf342dfaf284b8fd7d18c8562",
|
|
48
50
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
49
51
|
}
|