Using the cache
Store downloaded data on disk so repeated or overlapping requests are served locally instead of from the network.
The cache is off by default. When you turn it on, every downloaded period is saved to disk, and later requests for the same instrument, timeframe and dates read it from there instead of the network. It speeds up repeated and overlapping downloads, and lets interrupted CLI downloads resume quickly.
Enable the cache
Section titled “Enable the cache”npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t m1 -f json --cacheimport { getHistoricalRates } from 'dukascopy-node';
const data = await getHistoricalRates({ instrument: 'eurusd', dates: { from: '2021-02-01', to: '2021-03-01' }, timeframe: 'm1', format: 'json', useCache: true});The first run downloads the data and fills the cache. Run it again and the data comes from disk, which is much faster and sends no requests to Dukascopy.
Cache folder
Section titled “Cache folder”Cached data lives in .dukascopy-cache in the current working directory. Choose another folder with cacheFolderPath (Node.js) or --cache-path (CLI):
npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t m1 --cache --cache-path ~/market-data/cacheconst data = await getHistoricalRates({ instrument: 'eurusd', dates: { from: '2021-02-01', to: '2021-03-01' }, timeframe: 'm1', useCache: true, cacheFolderPath: '/home/me/market-data/cache'});To clear the cache, delete the folder. Add it to .gitignore if it lives inside a repository.
What gets cached
Section titled “What gets cached”The cache stores the raw responses for completed periods: one file per hour of ticks, day of minute candles, month of hour candles or year of day candles. The output is built from these, so a cached period serves every format and every timeframe built from the same source; for example, m1 to m30 all reuse cached minute candles. Bid and ask candles are cached separately.
Periods that contain the current time are not cached, because their data is still changing:
| Timeframes | Not cached while in progress |
|---|---|
tick, s1 |
the current hour |
m1, m5, m15, m30 |
the current day |
h1, h4 |
the current month |
d1, mn1 |
the current year |
When a whole batch is served from the cache, the pause between batches is skipped too.
Upgrading from 1.46.4 or earlier
The cache now stores JSON responses under new file names. Older .bi5 files in .dukascopy-cache
are no longer read and can be deleted, unless you still use an older version of dukascopy-node.