-
-
Notifications
You must be signed in to change notification settings - Fork 87
Usage with typescript
Leonid Pyrlia edited this page Aug 15, 2021
·
3 revisions
dukascopy-node is built with Typescript and is shipped with all the interfaces and enums for easier development experience.
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));Through the power of overloads in Typescript, dukascopy-node knows the precise shape of the output.
When json is requested as format for non-tick timeframe
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));
When array is requested as format for non-tick timeframe
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));
When json is requested as format for tick timeframe
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));
When array is requested as format for tick timeframe
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));
When csv is requested as format
import { getHistoricRates, 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
};
getHistoricRates(config).then(data => console.log(data));