dukascopy-node-plus 1.1.0 → 1.1.2
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/cli/index.js +1 -1
- package/dist/esm/chunk-476J4KQE.js +35 -0
- package/dist/esm/{chunk-DWZJECKF.js → chunk-7MFC3GUP.js} +1 -1
- package/dist/esm/chunk-MTHVPJMW.js +113 -0
- package/dist/esm/chunk-NBUGCZCI.js +164 -0
- package/dist/esm/cli/index.js +1 -1
- package/dist/esm/index.example.nostream.js +38 -0
- package/dist/esm/index.example.stream.js +41 -0
- package/dist/esm/index.js +9 -99
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.example.nostream.js +13855 -0
- package/dist/index.example.stream.d.mts +2 -0
- package/dist/index.example.stream.d.ts +2 -0
- package/dist/{index.example.js → index.example.stream.js} +149 -129
- package/dist/index.js +132 -125
- package/package.json +2 -2
- package/dist/esm/chunk-KWYYNULA.js +0 -184
- package/dist/esm/index.example.js +0 -27
- /package/dist/{index.example.d.mts → index.example.nostream.d.mts} +0 -0
- /package/dist/{index.example.d.ts → index.example.nostream.d.ts} +0 -0
|
@@ -13706,158 +13706,178 @@ var import_debug = __toESM(require("debug"));
|
|
|
13706
13706
|
var import_stream = require("stream");
|
|
13707
13707
|
var import_promises = require("stream/promises");
|
|
13708
13708
|
var DEBUG_NAMESPACE = "dukascopy-node";
|
|
13709
|
-
|
|
13709
|
+
function getHistoricalRatesToStream(config) {
|
|
13710
13710
|
const stream = new import_stream.Readable({
|
|
13711
13711
|
objectMode: true,
|
|
13712
13712
|
async read(_size) {
|
|
13713
|
-
|
|
13714
|
-
|
|
13715
|
-
|
|
13716
|
-
|
|
13717
|
-
|
|
13718
|
-
|
|
13719
|
-
|
|
13720
|
-
|
|
13721
|
-
|
|
13722
|
-
|
|
13723
|
-
|
|
13724
|
-
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
|
|
13729
|
-
|
|
13730
|
-
|
|
13731
|
-
|
|
13732
|
-
|
|
13733
|
-
|
|
13734
|
-
|
|
13735
|
-
|
|
13736
|
-
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13758
|
-
|
|
13759
|
-
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13713
|
+
}
|
|
13714
|
+
});
|
|
13715
|
+
try {
|
|
13716
|
+
const { input, isValid, validationErrors } = validateConfigNode(config);
|
|
13717
|
+
(0, import_debug.default)(`${DEBUG_NAMESPACE}:config`)("%O", {
|
|
13718
|
+
input,
|
|
13719
|
+
isValid,
|
|
13720
|
+
validationErrors
|
|
13721
|
+
});
|
|
13722
|
+
if (!isValid) {
|
|
13723
|
+
stream.emit("error", { validationErrors });
|
|
13724
|
+
stream.push(null);
|
|
13725
|
+
return stream;
|
|
13726
|
+
}
|
|
13727
|
+
const {
|
|
13728
|
+
instrument,
|
|
13729
|
+
dates: { from, to },
|
|
13730
|
+
timeframe,
|
|
13731
|
+
priceType,
|
|
13732
|
+
volumes,
|
|
13733
|
+
volumeUnits,
|
|
13734
|
+
utcOffset,
|
|
13735
|
+
ignoreFlats,
|
|
13736
|
+
format,
|
|
13737
|
+
batchSize,
|
|
13738
|
+
pauseBetweenBatchesMs,
|
|
13739
|
+
useCache,
|
|
13740
|
+
cacheFolderPath,
|
|
13741
|
+
retryCount,
|
|
13742
|
+
pauseBetweenRetriesMs,
|
|
13743
|
+
retryOnEmpty
|
|
13744
|
+
} = input;
|
|
13745
|
+
const [startDate, endDate] = normaliseDates({
|
|
13746
|
+
instrument,
|
|
13747
|
+
startDate: from,
|
|
13748
|
+
endDate: to,
|
|
13749
|
+
timeframe,
|
|
13750
|
+
utcOffset
|
|
13751
|
+
});
|
|
13752
|
+
const [startDateMs, endDateMs] = [+startDate, +endDate];
|
|
13753
|
+
const onItemFetch = process.env.DEBUG ? (url, buffer, isCacheHit) => {
|
|
13754
|
+
(0, import_debug.default)(`${DEBUG_NAMESPACE}:fetcher`)(
|
|
13755
|
+
url,
|
|
13756
|
+
`| ${formatBytes(buffer.length)} |`,
|
|
13757
|
+
`${isCacheHit ? "cache" : "network"}`
|
|
13758
|
+
);
|
|
13759
|
+
} : void 0;
|
|
13760
|
+
const bufferFetcher = new BufferFetcher({
|
|
13761
|
+
batchSize,
|
|
13762
|
+
pauseBetweenBatchesMs,
|
|
13763
|
+
cacheManager: useCache ? new CacheManager({ cacheFolderPath }) : void 0,
|
|
13764
|
+
retryCount,
|
|
13765
|
+
pauseBetweenRetriesMs,
|
|
13766
|
+
onItemFetch,
|
|
13767
|
+
retryOnEmpty
|
|
13768
|
+
});
|
|
13769
|
+
const bodyHeaders = timeframe === "tick" /* tick */ ? tickHeaders : candleHeaders;
|
|
13770
|
+
let firstLine = true;
|
|
13771
|
+
let urlsProcessed = 0;
|
|
13772
|
+
const urlsforFetchingData = generateUrls({
|
|
13773
|
+
instrument: input.instrument,
|
|
13774
|
+
timeframe: input.timeframe,
|
|
13775
|
+
priceType: input.priceType,
|
|
13776
|
+
startDate,
|
|
13777
|
+
endDate
|
|
13778
|
+
});
|
|
13779
|
+
const promiseProcessedData = urlsforFetchingData.map((url) => {
|
|
13780
|
+
return new Promise((resolve2, reject) => {
|
|
13781
|
+
bufferFetcher.fetch([url]).then((bufferObjects) => {
|
|
13782
|
+
try {
|
|
13783
|
+
const processedData = processData({
|
|
13784
|
+
instrument: input.instrument,
|
|
13785
|
+
requestedTimeframe: input.timeframe,
|
|
13786
|
+
bufferObjects,
|
|
13787
|
+
priceType: input.priceType,
|
|
13788
|
+
volumes: input.volumes,
|
|
13789
|
+
volumeUnits: input.volumeUnits,
|
|
13790
|
+
ignoreFlats: input.ignoreFlats
|
|
13791
|
+
});
|
|
13792
|
+
resolve2(processedData);
|
|
13793
|
+
} catch (err) {
|
|
13794
|
+
reject(err);
|
|
13795
|
+
}
|
|
13796
|
+
}).catch((err) => {
|
|
13797
|
+
reject(err);
|
|
13775
13798
|
});
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
|
|
13785
|
-
|
|
13786
|
-
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13795
|
-
|
|
13796
|
-
|
|
13797
|
-
|
|
13798
|
-
if (
|
|
13799
|
-
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
const bodyHeaders = timeframe === "tick" /* tick */ ? tickHeaders : candleHeaders;
|
|
13803
|
-
if (format === "json" /* json */) {
|
|
13804
|
-
const data = item.reduce((all, item2, i) => {
|
|
13805
|
-
const name = bodyHeaders[i];
|
|
13806
|
-
all[name] = item2;
|
|
13807
|
-
return all;
|
|
13808
|
-
}, {});
|
|
13809
|
-
this.push(data);
|
|
13810
|
-
} else if (format === "csv" /* csv */) {
|
|
13811
|
-
if (firstLine) {
|
|
13812
|
-
const csvHeaders = bodyHeaders.join(",");
|
|
13813
|
-
this.push(csvHeaders);
|
|
13814
|
-
firstLine = false;
|
|
13815
|
-
}
|
|
13816
|
-
this.push(item.join(","));
|
|
13817
|
-
}
|
|
13818
|
-
}
|
|
13799
|
+
});
|
|
13800
|
+
});
|
|
13801
|
+
(0, import_promises.pipeline)(
|
|
13802
|
+
import_stream.Readable.from(promiseProcessedData),
|
|
13803
|
+
new import_stream.Transform({
|
|
13804
|
+
objectMode: true,
|
|
13805
|
+
transform: async (processedDataPr, _, callback) => {
|
|
13806
|
+
const processedData = await processedDataPr;
|
|
13807
|
+
try {
|
|
13808
|
+
processedData.forEach((item) => {
|
|
13809
|
+
const [timestamp] = item;
|
|
13810
|
+
if (timestamp && timestamp >= startDateMs && timestamp < endDateMs) {
|
|
13811
|
+
if (input.format === "array" /* array */) {
|
|
13812
|
+
stream.push(item);
|
|
13813
|
+
} else if (format === "json" /* json */) {
|
|
13814
|
+
const data = item.reduce((all, item2, i) => {
|
|
13815
|
+
const name = bodyHeaders[i];
|
|
13816
|
+
all[name] = item2;
|
|
13817
|
+
return all;
|
|
13818
|
+
}, {});
|
|
13819
|
+
stream.push(data);
|
|
13820
|
+
} else if (format === "csv" /* csv */) {
|
|
13821
|
+
if (firstLine) {
|
|
13822
|
+
const csvHeaders = bodyHeaders.join(",");
|
|
13823
|
+
stream.push(csvHeaders);
|
|
13824
|
+
firstLine = false;
|
|
13819
13825
|
}
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
13823
|
-
callback(err);
|
|
13826
|
+
stream.push(`
|
|
13827
|
+
${item.join(",")}`);
|
|
13828
|
+
}
|
|
13824
13829
|
}
|
|
13830
|
+
});
|
|
13831
|
+
if (++urlsProcessed === urlsforFetchingData.length) {
|
|
13832
|
+
stream.push(null);
|
|
13825
13833
|
}
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
this.push(null);
|
|
13834
|
+
callback();
|
|
13835
|
+
} catch (err) {
|
|
13836
|
+
callback(err);
|
|
13830
13837
|
}
|
|
13831
|
-
}
|
|
13832
|
-
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
13838
|
-
|
|
13839
|
-
|
|
13840
|
-
}
|
|
13838
|
+
}
|
|
13839
|
+
})
|
|
13840
|
+
).catch((err) => {
|
|
13841
|
+
stream.emit("error", err);
|
|
13842
|
+
stream.push(null);
|
|
13843
|
+
});
|
|
13844
|
+
} catch (err) {
|
|
13845
|
+
stream.emit("error", err);
|
|
13846
|
+
stream.push(null);
|
|
13847
|
+
}
|
|
13841
13848
|
return stream;
|
|
13842
13849
|
}
|
|
13843
13850
|
|
|
13844
|
-
// src/index.example.ts
|
|
13851
|
+
// src/index.example.stream.ts
|
|
13852
|
+
var printMemory = () => {
|
|
13853
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
13854
|
+
const memoryData = process.memoryUsage();
|
|
13855
|
+
const memoryUsage = {
|
|
13856
|
+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
|
|
13857
|
+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
|
|
13858
|
+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
|
|
13859
|
+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`
|
|
13860
|
+
};
|
|
13861
|
+
console.log(memoryUsage);
|
|
13862
|
+
};
|
|
13845
13863
|
(async () => {
|
|
13846
13864
|
try {
|
|
13865
|
+
printMemory();
|
|
13847
13866
|
const data = await getHistoricalRatesToStream({
|
|
13848
13867
|
instrument: "eurusd",
|
|
13849
13868
|
dates: {
|
|
13850
13869
|
from: /* @__PURE__ */ new Date("2021-02-01"),
|
|
13851
|
-
to: /* @__PURE__ */ new Date("2021-03
|
|
13870
|
+
to: /* @__PURE__ */ new Date("2021-06-03")
|
|
13852
13871
|
},
|
|
13853
|
-
timeframe: "
|
|
13872
|
+
timeframe: "m1",
|
|
13854
13873
|
format: "csv"
|
|
13855
13874
|
});
|
|
13856
13875
|
data.on("data", (chunk) => {
|
|
13857
|
-
|
|
13876
|
+
process.stdout.write(chunk);
|
|
13858
13877
|
});
|
|
13859
13878
|
data.on("end", () => {
|
|
13860
|
-
console.log(
|
|
13879
|
+
console.log();
|
|
13880
|
+
printMemory();
|
|
13861
13881
|
});
|
|
13862
13882
|
} catch (error) {
|
|
13863
13883
|
console.log("error", error);
|
package/dist/index.js
CHANGED
|
@@ -13767,7 +13767,7 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
13767
13767
|
}
|
|
13768
13768
|
|
|
13769
13769
|
// package.json
|
|
13770
|
-
var version = "1.1.
|
|
13770
|
+
var version = "1.1.2";
|
|
13771
13771
|
|
|
13772
13772
|
// src/getHistoricalRates.ts
|
|
13773
13773
|
var import_debug = __toESM(require("debug"));
|
|
@@ -13990,138 +13990,145 @@ var import_debug2 = __toESM(require("debug"));
|
|
|
13990
13990
|
var import_stream = require("stream");
|
|
13991
13991
|
var import_promises = require("stream/promises");
|
|
13992
13992
|
var DEBUG_NAMESPACE2 = "dukascopy-node";
|
|
13993
|
-
|
|
13993
|
+
function getHistoricalRatesToStream(config) {
|
|
13994
13994
|
const stream = new import_stream.Readable({
|
|
13995
13995
|
objectMode: true,
|
|
13996
13996
|
async read(_size) {
|
|
13997
|
-
|
|
13998
|
-
|
|
13999
|
-
|
|
14000
|
-
|
|
14001
|
-
|
|
14002
|
-
|
|
14003
|
-
|
|
14004
|
-
|
|
14005
|
-
|
|
14006
|
-
|
|
14007
|
-
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
|
|
14011
|
-
|
|
14012
|
-
|
|
14013
|
-
|
|
14014
|
-
|
|
14015
|
-
|
|
14016
|
-
|
|
14017
|
-
|
|
14018
|
-
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
|
|
14022
|
-
|
|
14023
|
-
|
|
14024
|
-
|
|
14025
|
-
|
|
14026
|
-
|
|
14027
|
-
|
|
14028
|
-
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
|
|
14033
|
-
|
|
14034
|
-
|
|
14035
|
-
|
|
14036
|
-
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
|
|
14044
|
-
|
|
14045
|
-
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
|
|
14055
|
-
|
|
14056
|
-
|
|
14057
|
-
|
|
14058
|
-
|
|
13997
|
+
}
|
|
13998
|
+
});
|
|
13999
|
+
try {
|
|
14000
|
+
const { input, isValid, validationErrors } = validateConfigNode(config);
|
|
14001
|
+
(0, import_debug2.default)(`${DEBUG_NAMESPACE2}:config`)("%O", {
|
|
14002
|
+
input,
|
|
14003
|
+
isValid,
|
|
14004
|
+
validationErrors
|
|
14005
|
+
});
|
|
14006
|
+
if (!isValid) {
|
|
14007
|
+
stream.emit("error", { validationErrors });
|
|
14008
|
+
stream.push(null);
|
|
14009
|
+
return stream;
|
|
14010
|
+
}
|
|
14011
|
+
const {
|
|
14012
|
+
instrument,
|
|
14013
|
+
dates: { from, to },
|
|
14014
|
+
timeframe,
|
|
14015
|
+
priceType,
|
|
14016
|
+
volumes,
|
|
14017
|
+
volumeUnits,
|
|
14018
|
+
utcOffset,
|
|
14019
|
+
ignoreFlats,
|
|
14020
|
+
format,
|
|
14021
|
+
batchSize,
|
|
14022
|
+
pauseBetweenBatchesMs,
|
|
14023
|
+
useCache,
|
|
14024
|
+
cacheFolderPath,
|
|
14025
|
+
retryCount,
|
|
14026
|
+
pauseBetweenRetriesMs,
|
|
14027
|
+
retryOnEmpty
|
|
14028
|
+
} = input;
|
|
14029
|
+
const [startDate, endDate] = normaliseDates({
|
|
14030
|
+
instrument,
|
|
14031
|
+
startDate: from,
|
|
14032
|
+
endDate: to,
|
|
14033
|
+
timeframe,
|
|
14034
|
+
utcOffset
|
|
14035
|
+
});
|
|
14036
|
+
const [startDateMs, endDateMs] = [+startDate, +endDate];
|
|
14037
|
+
const onItemFetch = process.env.DEBUG ? (url, buffer, isCacheHit) => {
|
|
14038
|
+
(0, import_debug2.default)(`${DEBUG_NAMESPACE2}:fetcher`)(
|
|
14039
|
+
url,
|
|
14040
|
+
`| ${formatBytes(buffer.length)} |`,
|
|
14041
|
+
`${isCacheHit ? "cache" : "network"}`
|
|
14042
|
+
);
|
|
14043
|
+
} : void 0;
|
|
14044
|
+
const bufferFetcher = new BufferFetcher({
|
|
14045
|
+
batchSize,
|
|
14046
|
+
pauseBetweenBatchesMs,
|
|
14047
|
+
cacheManager: useCache ? new CacheManager({ cacheFolderPath }) : void 0,
|
|
14048
|
+
retryCount,
|
|
14049
|
+
pauseBetweenRetriesMs,
|
|
14050
|
+
onItemFetch,
|
|
14051
|
+
retryOnEmpty
|
|
14052
|
+
});
|
|
14053
|
+
const bodyHeaders = timeframe === "tick" /* tick */ ? tickHeaders : candleHeaders;
|
|
14054
|
+
let firstLine = true;
|
|
14055
|
+
let urlsProcessed = 0;
|
|
14056
|
+
const urlsforFetchingData = generateUrls({
|
|
14057
|
+
instrument: input.instrument,
|
|
14058
|
+
timeframe: input.timeframe,
|
|
14059
|
+
priceType: input.priceType,
|
|
14060
|
+
startDate,
|
|
14061
|
+
endDate
|
|
14062
|
+
});
|
|
14063
|
+
const promiseProcessedData = urlsforFetchingData.map((url) => {
|
|
14064
|
+
return new Promise((resolve2, reject) => {
|
|
14065
|
+
bufferFetcher.fetch([url]).then((bufferObjects) => {
|
|
14066
|
+
try {
|
|
14067
|
+
const processedData = processData({
|
|
14068
|
+
instrument: input.instrument,
|
|
14069
|
+
requestedTimeframe: input.timeframe,
|
|
14070
|
+
bufferObjects,
|
|
14071
|
+
priceType: input.priceType,
|
|
14072
|
+
volumes: input.volumes,
|
|
14073
|
+
volumeUnits: input.volumeUnits,
|
|
14074
|
+
ignoreFlats: input.ignoreFlats
|
|
14075
|
+
});
|
|
14076
|
+
resolve2(processedData);
|
|
14077
|
+
} catch (err) {
|
|
14078
|
+
reject(err);
|
|
14079
|
+
}
|
|
14080
|
+
}).catch((err) => {
|
|
14081
|
+
reject(err);
|
|
14059
14082
|
});
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
if (
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
const bodyHeaders = timeframe === "tick" /* tick */ ? tickHeaders : candleHeaders;
|
|
14087
|
-
if (format === "json" /* json */) {
|
|
14088
|
-
const data = item.reduce((all, item2, i) => {
|
|
14089
|
-
const name = bodyHeaders[i];
|
|
14090
|
-
all[name] = item2;
|
|
14091
|
-
return all;
|
|
14092
|
-
}, {});
|
|
14093
|
-
this.push(data);
|
|
14094
|
-
} else if (format === "csv" /* csv */) {
|
|
14095
|
-
if (firstLine) {
|
|
14096
|
-
const csvHeaders = bodyHeaders.join(",");
|
|
14097
|
-
this.push(csvHeaders);
|
|
14098
|
-
firstLine = false;
|
|
14099
|
-
}
|
|
14100
|
-
this.push(item.join(","));
|
|
14101
|
-
}
|
|
14102
|
-
}
|
|
14083
|
+
});
|
|
14084
|
+
});
|
|
14085
|
+
(0, import_promises.pipeline)(
|
|
14086
|
+
import_stream.Readable.from(promiseProcessedData),
|
|
14087
|
+
new import_stream.Transform({
|
|
14088
|
+
objectMode: true,
|
|
14089
|
+
transform: async (processedDataPr, _, callback) => {
|
|
14090
|
+
const processedData = await processedDataPr;
|
|
14091
|
+
try {
|
|
14092
|
+
processedData.forEach((item) => {
|
|
14093
|
+
const [timestamp] = item;
|
|
14094
|
+
if (timestamp && timestamp >= startDateMs && timestamp < endDateMs) {
|
|
14095
|
+
if (input.format === "array" /* array */) {
|
|
14096
|
+
stream.push(item);
|
|
14097
|
+
} else if (format === "json" /* json */) {
|
|
14098
|
+
const data = item.reduce((all, item2, i) => {
|
|
14099
|
+
const name = bodyHeaders[i];
|
|
14100
|
+
all[name] = item2;
|
|
14101
|
+
return all;
|
|
14102
|
+
}, {});
|
|
14103
|
+
stream.push(data);
|
|
14104
|
+
} else if (format === "csv" /* csv */) {
|
|
14105
|
+
if (firstLine) {
|
|
14106
|
+
const csvHeaders = bodyHeaders.join(",");
|
|
14107
|
+
stream.push(csvHeaders);
|
|
14108
|
+
firstLine = false;
|
|
14103
14109
|
}
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
callback(err);
|
|
14110
|
+
stream.push(`
|
|
14111
|
+
${item.join(",")}`);
|
|
14112
|
+
}
|
|
14108
14113
|
}
|
|
14114
|
+
});
|
|
14115
|
+
if (++urlsProcessed === urlsforFetchingData.length) {
|
|
14116
|
+
stream.push(null);
|
|
14109
14117
|
}
|
|
14110
|
-
|
|
14111
|
-
|
|
14112
|
-
|
|
14113
|
-
this.push(null);
|
|
14118
|
+
callback();
|
|
14119
|
+
} catch (err) {
|
|
14120
|
+
callback(err);
|
|
14114
14121
|
}
|
|
14115
|
-
}
|
|
14116
|
-
|
|
14117
|
-
|
|
14118
|
-
|
|
14119
|
-
|
|
14120
|
-
|
|
14121
|
-
|
|
14122
|
-
|
|
14123
|
-
|
|
14124
|
-
}
|
|
14122
|
+
}
|
|
14123
|
+
})
|
|
14124
|
+
).catch((err) => {
|
|
14125
|
+
stream.emit("error", err);
|
|
14126
|
+
stream.push(null);
|
|
14127
|
+
});
|
|
14128
|
+
} catch (err) {
|
|
14129
|
+
stream.emit("error", err);
|
|
14130
|
+
stream.push(null);
|
|
14131
|
+
}
|
|
14125
14132
|
return stream;
|
|
14126
14133
|
}
|
|
14127
14134
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dukascopy-node-plus",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Node.js library for downloading historical market tick data for for Crypto, Stocks, ETFs, CFDs, Forex",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dukascopy-node": "./dist/cli/index.js"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "rm -rf dist && tsup-node src/index.ts src/cli/index.ts src/index.example.ts --format esm,cjs --dts --legacy-output",
|
|
16
|
+
"build": "rm -rf dist && tsup-node src/index.ts src/cli/index.ts src/index.example.stream.ts src/index.example.nostream.ts --format esm,cjs --dts --legacy-output",
|
|
17
17
|
"test": "vitest run",
|
|
18
18
|
"coverage": "vitest run --coverage",
|
|
19
19
|
"format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|