Skip to content

Commit d7ce56e

Browse files
committed
~ bug fix
1 parent df85806 commit d7ce56e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
const hstReader = new HSTReader(path.join(__dirname, '../data/EURGBP.hst'));
55

66
console.log(hstReader.symbol);
7+
console.log(hstReader.getNextCandle()); // first candle
78
console.log(hstReader.getNextCandle());
89
console.log(hstReader.getNextCandle());
910
console.log(hstReader.getPrevCandle());

src/hst_reader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class HSTReader {
8181
}
8282
getPrevCandle(): Candle {
8383
if(this.byteOffset - this.candleByteSize >= 148) {
84-
this.byteOffset -= this.candleByteSize * 2;
84+
this.byteOffset -= this.candleByteSize;
8585
this.candleNumber -= 1;
8686
this.endOfFile = false;
8787
}
@@ -108,7 +108,7 @@ export default class HSTReader {
108108
throw new Error('Could not find candle');
109109
}
110110
}
111-
readCandle(): Candle {
111+
private readCandle(): Candle {
112112
if(this.byteOffset < 148) {
113113
this.byteOffset = 148;
114114
}
@@ -127,7 +127,7 @@ export default class HSTReader {
127127
fs.readSync(this.fd, close, 0, 8, this.byteOffset += 8);
128128
fs.readSync(this.fd, volume, 0, 8, this.byteOffset += 8);
129129

130-
this.byteOffset += 8;
130+
this.byteOffset -= this.candleByteSize - 8;
131131

132132
return {
133133
timestamp: new Date(timestamp.readInt32LE(0) * 1000),

0 commit comments

Comments
 (0)