dukascopy-node-plus 1.0.0 → 1.1.1
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 +17 -1
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.js +198 -12
- package/dist/esm/chunk-3Q3J6T4N.js +6 -0
- package/dist/esm/chunk-476J4KQE.js +35 -0
- package/dist/esm/{chunk-QOULS5Y3.js → chunk-D3M3SVMW.js} +184 -14
- package/dist/esm/chunk-VHUFHYTL.js +155 -0
- package/dist/esm/chunk-YLYLH52F.js +113 -0
- package/dist/esm/cli/index.js +16 -6
- package/dist/esm/index.example.nostream.js +37 -0
- package/dist/esm/index.example.stream.js +40 -0
- package/dist/esm/index.js +15 -128
- package/dist/index.d.mts +6803 -0
- package/dist/index.d.ts +6762 -6684
- package/dist/index.example.nostream.d.mts +2 -0
- package/dist/index.example.nostream.d.ts +2 -0
- package/dist/index.example.nostream.js +13854 -0
- package/dist/index.example.stream.d.mts +2 -0
- package/dist/index.example.stream.d.ts +2 -0
- package/dist/index.example.stream.js +13875 -0
- package/dist/index.js +330 -12
- package/package.json +25 -29
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHistoricalRates
|
|
3
|
+
} from "./chunk-YLYLH52F.js";
|
|
4
|
+
import "./chunk-3Q3J6T4N.js";
|
|
5
|
+
import "./chunk-476J4KQE.js";
|
|
6
|
+
import "./chunk-D3M3SVMW.js";
|
|
7
|
+
|
|
8
|
+
// src/index.example.nostream.ts
|
|
9
|
+
var printMemory = () => {
|
|
10
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
11
|
+
const memoryData = process.memoryUsage();
|
|
12
|
+
const memoryUsage = {
|
|
13
|
+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
|
|
14
|
+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
|
|
15
|
+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
|
|
16
|
+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`
|
|
17
|
+
};
|
|
18
|
+
console.log(memoryUsage);
|
|
19
|
+
};
|
|
20
|
+
(async () => {
|
|
21
|
+
try {
|
|
22
|
+
printMemory();
|
|
23
|
+
const data = await getHistoricalRates({
|
|
24
|
+
instrument: "eurusd",
|
|
25
|
+
dates: {
|
|
26
|
+
from: /* @__PURE__ */ new Date("2021-02-01"),
|
|
27
|
+
to: /* @__PURE__ */ new Date("2021-02-03")
|
|
28
|
+
},
|
|
29
|
+
timeframe: "m1",
|
|
30
|
+
format: "csv"
|
|
31
|
+
});
|
|
32
|
+
process.stdout.write(data);
|
|
33
|
+
printMemory();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.log("error", error);
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHistoricalRatesToStream
|
|
3
|
+
} from "./chunk-VHUFHYTL.js";
|
|
4
|
+
import "./chunk-476J4KQE.js";
|
|
5
|
+
import "./chunk-D3M3SVMW.js";
|
|
6
|
+
|
|
7
|
+
// src/index.example.stream.ts
|
|
8
|
+
var printMemory = () => {
|
|
9
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
10
|
+
const memoryData = process.memoryUsage();
|
|
11
|
+
const memoryUsage = {
|
|
12
|
+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
|
|
13
|
+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
|
|
14
|
+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
|
|
15
|
+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`
|
|
16
|
+
};
|
|
17
|
+
console.log(memoryUsage);
|
|
18
|
+
};
|
|
19
|
+
(async () => {
|
|
20
|
+
try {
|
|
21
|
+
printMemory();
|
|
22
|
+
const data = await getHistoricalRatesToStream({
|
|
23
|
+
instrument: "eurusd",
|
|
24
|
+
dates: {
|
|
25
|
+
from: /* @__PURE__ */ new Date("2021-02-01"),
|
|
26
|
+
to: /* @__PURE__ */ new Date("2021-02-03")
|
|
27
|
+
},
|
|
28
|
+
timeframe: "m1",
|
|
29
|
+
format: "csv"
|
|
30
|
+
});
|
|
31
|
+
data.on("data", (_chunk) => {
|
|
32
|
+
process.stdout.write(_chunk);
|
|
33
|
+
});
|
|
34
|
+
data.on("end", () => {
|
|
35
|
+
printMemory();
|
|
36
|
+
});
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.log("error", error);
|
|
39
|
+
}
|
|
40
|
+
})();
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHistoricalRatesToStream
|
|
3
|
+
} from "./chunk-VHUFHYTL.js";
|
|
4
|
+
import {
|
|
5
|
+
getHistoricRates,
|
|
6
|
+
getHistoricalRates
|
|
7
|
+
} from "./chunk-YLYLH52F.js";
|
|
8
|
+
import "./chunk-3Q3J6T4N.js";
|
|
9
|
+
import {
|
|
10
|
+
formatOutput
|
|
11
|
+
} from "./chunk-476J4KQE.js";
|
|
1
12
|
import {
|
|
2
13
|
BufferFetcher,
|
|
3
14
|
CacheManager,
|
|
@@ -7,143 +18,18 @@ import {
|
|
|
7
18
|
Timeframe,
|
|
8
19
|
URL_ROOT,
|
|
9
20
|
defaultConfig,
|
|
10
|
-
formatBytes,
|
|
11
21
|
generateUrls,
|
|
12
22
|
instrumentMetaData,
|
|
13
23
|
normaliseDates,
|
|
14
24
|
processData,
|
|
15
25
|
schema,
|
|
16
26
|
validateConfig,
|
|
17
|
-
validateConfigNode
|
|
18
|
-
|
|
19
|
-
} from "./chunk-QOULS5Y3.js";
|
|
20
|
-
|
|
21
|
-
// src/output-formatter/index.ts
|
|
22
|
-
var headers = ["timestamp", "open", "high", "low", "close", "volume"];
|
|
23
|
-
var tickHeaders = ["timestamp", "askPrice", "bidPrice", "askVolume", "bidVolume"];
|
|
24
|
-
function formatOutput({
|
|
25
|
-
processedData,
|
|
26
|
-
format,
|
|
27
|
-
timeframe
|
|
28
|
-
}) {
|
|
29
|
-
if (processedData.length === 0) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const bodyHeaders = timeframe === "tick" /* tick */ ? tickHeaders : headers;
|
|
33
|
-
if (format === "json" /* json */) {
|
|
34
|
-
const data = processedData.map((arr) => {
|
|
35
|
-
return arr.reduce((all, item, i) => {
|
|
36
|
-
const name = bodyHeaders[i];
|
|
37
|
-
all[name] = item;
|
|
38
|
-
return all;
|
|
39
|
-
}, {});
|
|
40
|
-
});
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
if (format === "csv" /* csv */) {
|
|
44
|
-
const csvHeaders = bodyHeaders.filter((_, i) => processedData[0][i] !== void 0);
|
|
45
|
-
const csv = [csvHeaders, ...processedData].map((arr) => arr.join(",")).join("\n");
|
|
46
|
-
return csv;
|
|
47
|
-
}
|
|
48
|
-
return processedData;
|
|
49
|
-
}
|
|
27
|
+
validateConfigNode
|
|
28
|
+
} from "./chunk-D3M3SVMW.js";
|
|
50
29
|
|
|
51
30
|
// src/index.ts
|
|
52
31
|
import { RuleDate, RuleBoolean, RuleNumber, RuleString, RuleObject } from "fastest-validator";
|
|
53
32
|
|
|
54
|
-
// src/getHistoricalRates.ts
|
|
55
|
-
import debug from "debug";
|
|
56
|
-
import os from "os";
|
|
57
|
-
var DEBUG_NAMESPACE = "dukascopy-node";
|
|
58
|
-
async function getHistoricalRates(config) {
|
|
59
|
-
debug(`${DEBUG_NAMESPACE}:version`)(version);
|
|
60
|
-
debug(`${DEBUG_NAMESPACE}:nodejs`)(process.version);
|
|
61
|
-
debug(`${DEBUG_NAMESPACE}:os`)(`${os.type()}, ${os.release()} (${os.platform()})`);
|
|
62
|
-
const { input, isValid, validationErrors } = validateConfigNode(config);
|
|
63
|
-
debug(`${DEBUG_NAMESPACE}:config`)("%O", {
|
|
64
|
-
input,
|
|
65
|
-
isValid,
|
|
66
|
-
validationErrors
|
|
67
|
-
});
|
|
68
|
-
if (!isValid) {
|
|
69
|
-
throw { validationErrors };
|
|
70
|
-
}
|
|
71
|
-
const {
|
|
72
|
-
instrument,
|
|
73
|
-
dates: { from, to },
|
|
74
|
-
timeframe,
|
|
75
|
-
priceType,
|
|
76
|
-
volumes,
|
|
77
|
-
volumeUnits,
|
|
78
|
-
utcOffset,
|
|
79
|
-
ignoreFlats,
|
|
80
|
-
format,
|
|
81
|
-
batchSize,
|
|
82
|
-
pauseBetweenBatchesMs,
|
|
83
|
-
useCache,
|
|
84
|
-
cacheFolderPath,
|
|
85
|
-
retryCount,
|
|
86
|
-
pauseBetweenRetriesMs,
|
|
87
|
-
retryOnEmpty
|
|
88
|
-
} = input;
|
|
89
|
-
const [startDate, endDate] = normaliseDates({
|
|
90
|
-
instrument,
|
|
91
|
-
startDate: from,
|
|
92
|
-
endDate: to,
|
|
93
|
-
timeframe,
|
|
94
|
-
utcOffset
|
|
95
|
-
});
|
|
96
|
-
const urls = generateUrls({
|
|
97
|
-
instrument,
|
|
98
|
-
timeframe,
|
|
99
|
-
priceType,
|
|
100
|
-
startDate,
|
|
101
|
-
endDate
|
|
102
|
-
});
|
|
103
|
-
debug(`${DEBUG_NAMESPACE}:urls`)(`Generated ${urls.length} urls`);
|
|
104
|
-
debug(`${DEBUG_NAMESPACE}:urls`)(`%O`, urls);
|
|
105
|
-
const onItemFetch = process.env.DEBUG ? (url, buffer, isCacheHit) => {
|
|
106
|
-
debug(`${DEBUG_NAMESPACE}:fetcher`)(
|
|
107
|
-
url,
|
|
108
|
-
`| ${formatBytes(buffer.length)} |`,
|
|
109
|
-
`${isCacheHit ? "cache" : "network"}`
|
|
110
|
-
);
|
|
111
|
-
} : void 0;
|
|
112
|
-
const bufferFetcher = new BufferFetcher({
|
|
113
|
-
batchSize,
|
|
114
|
-
pauseBetweenBatchesMs,
|
|
115
|
-
cacheManager: useCache ? new CacheManager({ cacheFolderPath }) : void 0,
|
|
116
|
-
retryCount,
|
|
117
|
-
pauseBetweenRetriesMs,
|
|
118
|
-
onItemFetch,
|
|
119
|
-
retryOnEmpty
|
|
120
|
-
});
|
|
121
|
-
const bufferredData = await bufferFetcher.fetch(urls);
|
|
122
|
-
const processedData = processData({
|
|
123
|
-
instrument,
|
|
124
|
-
requestedTimeframe: timeframe,
|
|
125
|
-
bufferObjects: bufferredData,
|
|
126
|
-
priceType,
|
|
127
|
-
volumes,
|
|
128
|
-
volumeUnits,
|
|
129
|
-
ignoreFlats
|
|
130
|
-
});
|
|
131
|
-
const [startDateMs, endDateMs] = [+startDate, +endDate];
|
|
132
|
-
const filteredData = processedData.filter(
|
|
133
|
-
([timestamp]) => timestamp && timestamp >= startDateMs && timestamp < endDateMs
|
|
134
|
-
);
|
|
135
|
-
debug(`${DEBUG_NAMESPACE}:data`)(
|
|
136
|
-
`Generated ${filteredData.length} ${timeframe === "tick" /* tick */ ? "ticks" : "OHLC candles"}`
|
|
137
|
-
);
|
|
138
|
-
const formattedData = formatOutput({
|
|
139
|
-
processedData: filteredData,
|
|
140
|
-
format,
|
|
141
|
-
timeframe
|
|
142
|
-
});
|
|
143
|
-
return formattedData;
|
|
144
|
-
}
|
|
145
|
-
var getHistoricRates = getHistoricalRates;
|
|
146
|
-
|
|
147
33
|
// src/getCurrentRates.ts
|
|
148
34
|
import fetch from "node-fetch";
|
|
149
35
|
var timeframeMap = {
|
|
@@ -171,7 +57,7 @@ async function getCurrentRates({
|
|
|
171
57
|
const instrumentName = instrumentMetaData[instrument].name;
|
|
172
58
|
const offerSide = priceType === "bid" ? "B" : "A";
|
|
173
59
|
const timeDirection = "N";
|
|
174
|
-
const now = new Date();
|
|
60
|
+
const now = /* @__PURE__ */ new Date();
|
|
175
61
|
let fromDate = now;
|
|
176
62
|
let toDate = now;
|
|
177
63
|
if (dates) {
|
|
@@ -286,6 +172,7 @@ export {
|
|
|
286
172
|
getCurrentRates,
|
|
287
173
|
getHistoricRates,
|
|
288
174
|
getHistoricalRates,
|
|
175
|
+
getHistoricalRatesToStream,
|
|
289
176
|
normaliseDates,
|
|
290
177
|
processData,
|
|
291
178
|
schema,
|