Skip to content

Usage with typescript

Leonid Pyrlia edited this page May 13, 2022 · 3 revisions

dukascopy-node is built with Typescript and is shipped with all the interfaces and enums for easier development experience.

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.d1,
  format: Format.json,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

Config awareness

Through the power of overloads in Typescript, dukascopy-node knows the precise shape of the output.

JsonItem

When json is requested as format for non-tick timeframe

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.d1,
  format: Format.json,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

JsonItem


ArrayItem

When array is requested as format for non-tick timeframe

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.d1,
  format: Format.array,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

ArrayItem


JsonItemTick

When json is requested as format for tick timeframe

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.tick,
  format: Format.json,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

JsonItemTick


ArrayTickItem

When array is requested as format for tick timeframe

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.tick,
  format: Format.array,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

ArrayTickItem


string

When csv is requested as format

import { getHistoricalRates, Config, Instrument, Timeframe, Format } from 'dukascopy-node';

const config: Config = {
  instrument: Instrument.eurusd,
  dates: {
    from: new Date('2021-03-30'),
    to: new Date('2021-03-31')
  },
  timeframe: Timeframe.d1,
  format: Format.csv,
  priceType: Price.bid
};

getHistoricalRates(config).then(data => console.log(data));

string