Skip to content
dukascopy-node

Node.js API reference

The getHistoricalRates and getRealTimeRates functions and every config option of the dukascopy-node Node.js API, with types and defaults.

import { getHistoricalRates } from 'dukascopy-node';
const data = await getHistoricalRates({
instrument: 'eurusd',
dates: { from: '2024-01-01', to: '2024-02-01' },
timeframe: 'h1',
format: 'json'
});

Downloads historical data and resolves with the whole result. The return type depends on format and timeframe: an array of candles or ticks, or a CSV string. It rejects if the config is invalid or a request fails after all retries.

Fetches the most recent ticks or candles, including the period still in progress. Takes instrument, timeframe, format, priceType, volumes, and either last or dates. See real-time data.

instrument

Required InstrumentType Link to instrument

Instrument id, for example eurusd, btcusd or aaplususd. Find ids on the instruments page.

dates.from

Required Date | string | number Link to dates.from

Start of the range (inclusive): a Date, a date string such as 2021-03-04 or 2021-03-04T10:30:00Z, or a Unix timestamp in milliseconds. Dates before the instrument’s earliest available data are moved forward to it.

dates.to

Required Date | string | number Link to dates.to

End of the range (exclusive), in the same formats as dates.from. Future dates are clamped to the current time.

timeframe

TimeframeType Link to timeframe

Aggregation of the data: tick, s1, m1, m5, m15, m30, h1, h4, d1 or mn1. See timeframes.

Default
'd1'

priceType

'bid' | 'ask' Link to priceType

Side of the market used for candles: bid or ask. Ignored for tick, which always includes both.

Default
'bid'

utcOffset

number Link to utcOffset

Shifts both ends of the requested range by this many minutes. Output timestamps stay in UTC; to convert them, see time zones.

Default
0

format

'array' | 'json' | 'csv' Link to format

Output format: array, json or csv. See output formats.

Default
'array'

volumes

boolean Link to volumes

Include volume columns in the output.

Default
true

volumeUnits

'millions' | 'thousands' | 'units' Link to volumeUnits

Unit of volume values: millions, thousands or units.

Default
'millions'

ignoreFlats

boolean Link to ignoreFlats

Skip candles with zero volume (flats), typically weekends and market holidays.

Default
true

batchSize

number Link to batchSize

Number of requests sent concurrently in one batch.

Default
10

pauseBetweenBatchesMs

number Link to pauseBetweenBatchesMs

Pause between batches, in milliseconds. Skipped when a whole batch is served from the cache.

Default
1000

requestIntervalMs

number Link to requestIntervalMs

Minimum time between individual requests, in milliseconds. 0 keeps the requests of a batch concurrent.

Default
0

rateLimitRetryCount

number Link to rateLimitRetryCount

Retries after HTTP 429 (Too Many Requests), separate from regular retries. Waits back off exponentially and honour Retry-After.

Default
3

retryCount

number Link to retryCount

Number of retries for a failed request. 0 disables retries. Refused requests (HTTP 403) are never retried.

Default
0

pauseBetweenRetriesMs

number Link to pauseBetweenRetriesMs

Pause between retries, in milliseconds.

Default
500

retryOnEmpty

boolean Link to retryOnEmpty

Treat successful responses with an empty dataset as failed attempts, so they are retried.

Default
false

failAfterRetryCount

boolean Link to failAfterRetryCount

Throw when a request still fails after all attempts. Set to false to skip the failed period and continue, also when retryCount is 0.

Default
true

useCache

boolean Link to useCache

Store completed periods on disk and read them from there on later runs. Periods that are still changing, such as the current hour or day, are always fetched.

Default
false

cacheFolderPath

string Link to cacheFolderPath

Folder for cached data, relative to the working directory.

Default
'.dukascopy-cache'

The options above with their default values, except instrument and dates:

const data = await getHistoricalRates({
instrument: 'btcusd',
dates: { from: '2024-01-01', to: '2024-02-01' },
timeframe: 'd1',
priceType: 'bid',
utcOffset: 0,
format: 'array',
volumes: true,
volumeUnits: 'millions',
ignoreFlats: true,
batchSize: 10,
pauseBetweenBatchesMs: 1000,
requestIntervalMs: 0,
rateLimitRetryCount: 3,
retryCount: 0,
pauseBetweenRetriesMs: 500,
retryOnEmpty: false,
failAfterRetryCount: true,
useCache: false,
cacheFolderPath: '' // '' means ./.dukascopy-cache
});
Export Description
RateLimitError, DukascopyAccessDeniedError Error classes for rate limits and refused access. See errors.
instrumentMetaData Name, description and earliest data of every instrument.
Instrument, Timeframe, Format, Price String enums of allowed values.
defaultConfig The default value of every option.
getHistoricRates, getCurrentRates Aliases of getHistoricalRates (deprecated) and getRealTimeRates.