-
-
Notifications
You must be signed in to change notification settings - Fork 69
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));
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 { 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));
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));
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));
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));
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));