Skip to content
dukascopy-node

Quick start

Download your first historical price dataset in under a minute, from the command line or from Node.js, and learn what the output looks like.

dukascopy-node downloads historical prices from Dukascopy’s free data feed and turns them into CSV or JSON. You choose an instrument, a date range and a timeframe, and get the prices back as a file or as data in your code.

  1. Find the id of the instrument you want on the instruments page, for example eurusd for EUR/USD.

  2. Run the CLI with a date range and a timeframe. This downloads daily EUR/USD candles for February 2021 as CSV:

    Terminal window
    npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t d1 -f csv
  3. Open the saved file, download/eurusd-d1-bid-2021-02-01-2021-03-01.csv:

    timestamp,open,high,low,close
    1612137600000,1.21225,1.21363,1.2056,1.20676
    1612224000000,1.20676,1.20877,1.20115,1.20365
    1612310400000,1.20365,1.205,1.2004,1.20412

While it runs, the CLI prints what it is downloading, followed by a progress bar:

----------------------------------------------------
Downloading historical price data for:
----------------------------------------------------
Instrument: Euro vs US Dollar
Timeframe: d1
From date: Feb 1, 2021
To date: Mar 1, 2021
Price type: bid
Volumes: false
UTC Offset: 0
Include flats: false
Format: csv
----------------------------------------------------

Tip

The CLI leaves volumes out unless you pass -v. Add -v to get a volume column.

Install the package (see installation), then call getHistoricalRates:

download.mjs
import { getHistoricalRates } from 'dukascopy-node';
const candles = await getHistoricalRates({
instrument: 'eurusd',
dates: { from: '2021-02-01', to: '2021-03-01' },
timeframe: 'd1',
format: 'json'
});
console.log(candles[0]);
// {
// timestamp: 1612137600000,
// open: 1.21225,
// high: 1.21363,
// low: 1.2056,
// close: 1.20676,
// volume: 165569.8187
// }

CommonJS works too: const { getHistoricalRates } = require('dukascopy-node');.

  • Timestamps are Unix epoch milliseconds in UTC, marking the start of each candle (1612137600000 is 2021-02-01 00:00 UTC). The CLI can format them.
  • Candles (s1 to mn1) have open, high, low, close and, optionally, volume.
  • Ticks (tick) have askPrice, bidPrice, askVolume and bidVolume for every price change. See tick data.
  • Formats: array (Node.js default), json (CLI default) or csv. See output formats.