-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathohlc_shrinker.cpp
More file actions
31 lines (26 loc) · 867 Bytes
/
ohlc_shrinker.cpp
File metadata and controls
31 lines (26 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "ohlc_shrinker.h"
OHLCShrinker::OHLCShrinker(OHLCProvider* source, QDateTime minimum, QDateTime maximum, CandlestickInterval* interval) {
this->source = source;
this->minimum = minimum;
this->maximum = maximum;
this->interval = interval;
}
QDateTime OHLCShrinker::getMinimum() { return minimum; }
QDateTime OHLCShrinker::getMaximum() { return maximum; }
CandlestickInterval* OHLCShrinker::getInterval() { return interval; }
bool OHLCShrinker::tryGetData(QDateTime start, OHLC& output) {
bool someCollected = false;
for (QDateTime now = interval->lastBefore(start); now < interval->firstAfter(start); now = source->getInterval()->firstAfter(now)) {
OHLC tick;
if (!source->tryGetData(now, tick)) {
continue;
}
if (!someCollected) {
output = tick;
someCollected = true;
} else {
output << tick;
}
}
return someCollected;
}