Skip to content
dukascopy-node

Output formats

dukascopy-node returns data as arrays, JSON objects or CSV. See the exact shape of candles and ticks in every format.

There are three output formats: array, json and csv. Set them with format in Node.js or -f in the CLI. The default is array in Node.js and json in the CLI.

All examples on this page download daily EUR/USD candles for February 2021.

Compact arrays of numbers. The smallest and fastest format to work with in code.

Terminal window
npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t d1 -f array -v
const data = await getHistoricalRates({
instrument: 'eurusd',
dates: { from: '2021-02-01', to: '2021-03-01' },
timeframe: 'd1',
format: 'array'
});
Output
[
[1612137600000, 1.21225, 1.21363, 1.2056, 1.20676, 165569.8187],
[1612224000000, 1.20676, 1.20877, 1.20115, 1.20365, 147916.4607],
[1612310400000, 1.20365, 1.205, 1.2004, 1.20412, 119397.1138]
]

Each candle is [timestamp, open, high, low, close, volume]. Full example: basic-array.output.json.

An array of objects with named fields. The most readable format.

Terminal window
npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t d1 -f json -v
const data = await getHistoricalRates({
instrument: 'eurusd',
dates: { from: '2021-02-01', to: '2021-03-01' },
timeframe: 'd1',
format: 'json'
});
Output
[
{
"timestamp": 1612137600000,
"open": 1.21225,
"high": 1.21363,
"low": 1.2056,
"close": 1.20676,
"volume": 165569.8187
}
]

Full example: basic-json.output.json.

A CSV string with a header row, ready for spreadsheets, pandas or a database import. In Node.js you get the whole file as one string.

Terminal window
npx dukascopy-node -i eurusd -from 2021-02-01 -to 2021-03-01 -t d1 -f csv -v
const csv = await getHistoricalRates({
instrument: 'eurusd',
dates: { from: '2021-02-01', to: '2021-03-01' },
timeframe: 'd1',
format: 'csv'
});
Output
timestamp,open,high,low,close,volume
1612137600000,1.21225,1.21363,1.2056,1.20676,165569.8187
1612224000000,1.20676,1.20877,1.20115,1.20365,147916.4607
1612310400000,1.20365,1.205,1.2004,1.20412,119397.1138

Full example: basic-csv.output.csv.

With timeframe: 'tick' every row is a single price change with both sides of the market instead of a candle:

Format Shape
array [timestamp, askPrice, bidPrice, askVolume, bidVolume]
json { timestamp, askPrice, bidPrice, askVolume, bidVolume }
csv timestamp,askPrice,bidPrice,askVolume,bidVolume header and rows

See downloading tick data for examples.

Field Description
timestamp Unix epoch milliseconds, UTC. For candles, the start of the period.
open, high, low, close Prices of the candle, for the bid or ask side chosen with priceType.
volume Traded volume in volumeUnits (millions by default). Left out when volumes is false.
askPrice, bidPrice Best ask and bid at the moment of the tick.
askVolume, bidVolume Volume available at those prices, in volumeUnits.
  • volumes: false (or leaving out -v in the CLI) removes the volume column.
  • volumeUnits scales volumes to millions (default), thousands or units.
  • Candles with zero volume, typically weekends and holidays, are skipped. Set ignoreFlats: false (or --flats) to keep them.

The CLI writes the result to ./download (change it with --directory), naming the file after the request, for example eurusd-d1-bid-2021-02-01-2021-03-01.csv. json and array both produce .json files; add --inline to write them without line breaks. Use --file-name to choose your own name.