Parser for the MetaTrader History (.hst) File Format in Node.js
npm install hst-parser --save
# or
yarn add hst-parser
# or
bower install hst-parser --save
const HSTParser = require('hst-parser');
const tradeHistory = new HSTParser('./data/USDGBP.hst'); // your .hst file
the HSTParser class exposes some variables for you to use
console.log(tradeHistory.version); // file version from headers
// example output: 400
console.log(tradeHistory.symbol); // the symbol / ticker / currency pair from the file
// example output: "USDGBP"
console.log(tradeHistory.period); // the interval (in minutes) of the data
// example output: 1
console.log(tradeHistory.start); // the JS Date of the first candle
// example output: Tue Nov 05 1985 00:52:00 GMT+0000 (GMT)
console.log(tradeHistory.candleNumber); // the number of the last read candle
// example output: 12345
console.log(tradeHistory.endOfFile); // true or false, has the parser hit the end of the file?
// example output: false
Candles are a section of data at any given interval.
Example:
{
"close": 90.26,
"high": 90.27,
"low": 90.25,
"open": 90.27,
"realVolume": 0,
"spread": 0,
"timestamp": "2010-01-26T00:00:00.000Z",
"volume": 9
}
Checks if file can be parsed by HSTParser. (currently supports versions 400 and 401 of .hst files)
if(tradeHistory.isValidFormat()) {
// do stuff
} else {
// error?
}
Returns candle data at specified position
console.log(tradeHistory.getCandleNumber(200));
// output: {Candle}
Returns promise that resolves to candle data at specified position
tradeHistory.getCandleNumber(200).then(candle => {
console.log(candle);
}).catch(err => {
console.log(err);
})
// output: {Candle}
Returns next set of candle data
console.log(tradeHistory.getNextCandle());
// output: {Candle}
Returns promise that resolves to next set of candle data
tradeHistory.getNextCandleAsync().then(candle => {
console.log(candle);
}).catch(err => {
console.log(err);
})
// output: {Candle}
Returns previous set of candle data
console.log(tradeHistory.getPrevCandle());
// output: {Candle}
Returns promise that resolves to previous set of candle data
tradeHistory.getPrevCandleAsync().then(candle => {
console.log(candle);
}).catch(err => {
console.log(err);
})
// output: {Candle}
Returns set of candle data at specified date and time
const myBirthday = new Date(1996, 0, 26);
console.log(tradeHistory.getCandleAt(myBirthday));
// output: {Candle}
Returns promise that resolves to set of candle data at specified date and time
const myBirthday = new Date(1996, 0, 26);
tradeHistory.getCandleAt(myBirthday).then(candle => {
console.log(candle);
}).catch(err => {
console.log(err);
})
// output: {Candle}
Kyron Taylor (gitbugr)
Simon Gniadkowski: HTS File Specification
MIT