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'});Functions
Section titled “Functions”getHistoricalRates(config)
Section titled “getHistoricalRates(config)”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.
getRealTimeRates(config)
Section titled “getRealTimeRates(config)”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 id, for example eurusd, btcusd or aaplususd. Find ids on the instruments page.
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.
End of the range (exclusive), in the same formats as dates.from. Future dates are clamped to the current time.
Aggregation of the data: tick, s1, m1, m5, m15, m30, h1, h4, d1 or mn1. See timeframes.
Side of the market used for candles: bid or ask. Ignored for tick, which always includes both.
Shifts both ends of the requested range by this many minutes. Output timestamps stay in UTC; to convert them, see time zones.
Output
Section titled “Output”Output format: array, json or csv. See output formats.
Include volume columns in the output.
Unit of volume values: millions, thousands or units.
Skip candles with zero volume (flats), typically weekends and market holidays.
Batching and rate limits
Section titled “Batching and rate limits”Number of requests sent concurrently in one batch.
Pause between batches, in milliseconds. Skipped when a whole batch is served from the cache.
Minimum time between individual requests, in milliseconds. 0 keeps the requests of a batch concurrent.
Retries after HTTP 429 (Too Many Requests), separate from regular retries. Waits back off exponentially and honour Retry-After.
Retries
Section titled “Retries”Number of retries for a failed request. 0 disables retries. Refused requests (HTTP 403) are never retried.
Pause between retries, in milliseconds.
Treat successful responses with an empty dataset as failed attempts, so they are retried.
Throw when a request still fails after all attempts. Set to false to skip the failed period and continue, also when retryCount is 0.
Cache
Section titled “Cache”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.
Folder for cached data, relative to the working directory.
Full example
Section titled “Full example”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});Other exports
Section titled “Other exports”| 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. |