Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fill-in second aggregation gap #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/aggregator/ohlc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,31 @@ function getSecondOHLCfromTicks(
3600,
d => d.getUTCMinutes() * 60 + d.getUTCSeconds()
);
const ohlc = ticksBySecond.map((data, i) =>

// There can be gaps in the data, so we need to fill them in
// filling in gaps when there is no ticks for a particular "second" and get date from previous "second"
// if it is not available, then we just leave it empty

// TODO: consider cases when the first "second" is empty

const withGapsFilled: number[][][] = [];
for (let i = 0; i < ticksBySecond.length; i++) {
const data = ticksBySecond[i];
const hasGap = data.length === 0;
if (hasGap) {
const prevData = ticksBySecond[i - 1];
const hasPrevData = prevData && prevData.length > 0;
if (hasPrevData) {
withGapsFilled.push(prevData);
} else {
withGapsFilled.push([]);
}
} else {
withGapsFilled.push(data);
}
}

const ohlc = withGapsFilled.map((data, i) =>
data.length > 0
? ticksToOHLC({ ticks: data, priceType, startTs: startTs + i * 1000, volumes })
: []
Expand Down