Downloading Real Time Tick Data
getRealTimeRates is a function that fetches real-time financial market data from Dukascopy's free server API. Unlike getHistoricalRates which retrieves archived tick/candle data from Dukascopy's historical database, this function accesses live market data feeds.
const { getRealTimeRates } = require('dukascopy-node');
(async () => {
try {
const data = await getRealTimeRates({
instrument: 'eurusd',
timeframe: 'tick',
format: 'json',
last: 10
});
console.log(data);
} catch (error) {
console.log('error', error);
}
})();The snippet above downloads last 10 live price tick rates for eurusd in json format:
Type Definition
type RealTimeRatesConfig = {
instrument: InstrumentType;
timeframe?: TimeframeType;
dates?: {
from: DateInput;
to?: DateInput;
};
last?: number;
volumes?: boolean;
format?: FormatType;
priceType?: PriceType;
}Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
instrument | InstrumentType | Required | Trading instrument - See List |
timeframe | TimeframeType | d1 | Time interval for candles: tick, s1, m1, m5, m15, m30, h1, h4, d1, mn1 |
priceType | PriceType | bid | Price type: bid or ask |
volumes | boolean | true | Whether to include volume data in the response |
format | FormatType | array | Output format: array, json, or csv |
dates | object | undefined | Date range for data retrieval (see below) |
last | number | 10 | Number of most recent ticks/candles to fetch (ignored if dates is provided) |
Date Configuration
When using the dates parameter:
dates?: {
from: DateInput; // Start date (required when using dates)
to?: DateInput; // End date (defaults to current time)
}DateInput accepts:
Dateobject:new Date('2025-01-01')- ISO string:
'2025-01-01T00:00:00Z' - Unix timestamp (ms):
1704067200000
Important: If dates is not provided, the function defaults to fetching the last N items (default: 10).
Return Types
Array Format
OHLC Candles (ArrayItem)
type ArrayItem = [Timestamp, OpenPrice, HighPrice, LowPrice, ClosePrice, Volume?]
// Example:
[1704067200000, 1.0945, 1.0950, 1.0940, 1.0948, 123.45]Tick Data (ArrayTickItem)
type ArrayTickItem = [Timestamp, AskPrice, BidPrice, AskVolume?, BidVolume?]
// Example:
[1704067200000, 1.0945, 1.0943, 10.5, 12.3]JSON Format
OHLC Candles (JsonItem)
interface JsonItem {
timestamp: number; // UNIX timestamp (ms)
open: number;
high: number;
low: number;
close: number;
volume?: number; // Optional based on 'volumes' config
}Tick Data (JsonItemTick)
interface JsonItemTick {
timestamp: number; // UNIX timestamp (ms)
askPrice: number;
bidPrice: number;
askVolume?: number; // Optional based on 'volumes' config
bidVolume?: number; // Optional based on 'volumes' config
}CSV Format
Returns a CSV-formatted string with headers:
timestamp,open,high,low,close,volume
1704067200000,1.0945,1.0950,1.0940,1.0948,123.45