By default, caching is disabled in dukascopy-node. Enabling it allows completed-period JSON responses to be stored on disk, enabling faster subsequent requests for the same instrument and date range by serving data from the local file system instead of the network.
To enable caching, set the useCache flag to true. You can optionally specify a custom directory using cacheFolderPath (the default is .dukascopy-cache).
Caching Limitations
Buckets containing the current time are not cached because the data is still changing. This applies to:
tick and s1: current hourm1, m5, m15, and m30: current dayh1 and h4: current monthd1 and mn1: current year
Note that requests for an earlier range inside one of these active buckets will still be fetched from the network.
const { getHistoricalRates } = require("dukascopy-node");
(async () => {
try {
const data = await getHistoricalRates({
instrument: "eurusd",
dates: {
from: new Date("2021-02-01"),
to: new Date("2021-03-01"),
},
timeframe: "d1",
format: "json",
useCache: true, // Enables caching
});
console.log(data);
} catch (error) {
console.log("error", error);
}
})();