fixed 分钟线更新, 更新日线以上数据更新

This commit is contained in:
fasiondog 2024-09-01 23:25:10 +08:00
parent 8e119984ed
commit 45782ec073
2 changed files with 25 additions and 38 deletions

View File

@ -897,7 +897,16 @@ void Stock::realtimeUpdate(KRecord record, KQuery::KType inktype) {
// 如果传入的记录日期等于最后一条记录日期,则更新最后一条记录;否则,追加入缓存
if (tmp.datetime == record.datetime) {
tmp = record;
if (tmp.highPrice < record.highPrice) {
tmp.highPrice = record.highPrice;
}
if (tmp.lowPrice > record.lowPrice) {
tmp.lowPrice = record.lowPrice;
}
tmp.closePrice = record.closePrice;
tmp.transAmount = record.transAmount;
tmp.transCount = record.transCount;
} else if (tmp.datetime < record.datetime) {
m_data->pKData[ktype]->push_back(record);
} else {

View File

@ -76,46 +76,24 @@ static void updateStockDayUpData(const SpotRecord& spot, KQuery::KType ktype) {
if (KQuery::WEEK == ktype) {
spot_end_of_phase = spot_end_of_phase - TimeDelta(2); // 周五日期
}
size_t total = stk.getCount(ktype);
// 没有历史数据,则直接更新并返回
if (total == 0) {
stk.realtimeUpdate(KRecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close,
spot.amount, spot.volume),
ktype);
return;
// 重新计算交易金额、交易量
Datetime spot_start_of_phase = startOfPhase(&spot_day);
KRecordList klist =
stk.getKRecordList(KQuery(spot_start_of_phase, spot_end_of_phase + TimeDelta(1), ktype));
price_t sum_amount = 0.0, sum_volume = 0.0;
for (const auto& k : klist) {
sum_amount += k.transAmount;
sum_volume += k.transCount;
}
KRecord last_record = stk.getKRecord(total - 1, ktype);
HKU_IF_RETURN(!last_record.isValid(), void());
if (spot_end_of_phase > last_record.datetime) {
// 如果当前的日期大于最后记录的日期,则为新增数据,直接更新并返回
stk.realtimeUpdate(KRecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close,
spot.amount, spot.volume),
ktype);
} else if (spot_end_of_phase == last_record.datetime) {
// 如果当前日期等于最后记录的日期,则需要重新计算最高价、最低价、交易金额、交易量
Datetime spot_start_of_phase = startOfPhase(&spot_day);
KRecordList klist =
stk.getKRecordList(KQuery(spot_start_of_phase, spot_end_of_phase + TimeDelta(1), ktype));
price_t amount = 0.0, volume = 0.0;
for (const auto& k : klist) {
amount += k.transAmount;
volume += k.transCount;
}
stk.realtimeUpdate(
KRecord(spot_end_of_phase, last_record.openPrice,
spot.high > last_record.highPrice ? spot.high : last_record.highPrice,
spot.low < last_record.lowPrice ? spot.low : last_record.lowPrice, spot.close,
amount, volume),
ktype);
} else {
// 不应该出现的情况:当前日期小于最后记录的日期
HKU_WARN(
"Ignore, What should not happen, the current date is less than the last recorded date!");
}
price_t amount =
spot.amount > sum_amount ? spot.amount - sum_amount : (sum_amount == 0.0 ? spot.amount : 0.0);
price_t spot_volume = spot.volume;
price_t volume =
spot_volume > sum_volume ? spot_volume - sum_volume : (sum_volume == 0.0 ? spot_volume : 0.0);
KRecord krecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close, amount, volume);
stk.realtimeUpdate(krecord, ktype);
}
static void updateStockMinData(const SpotRecord& spot, KQuery::KType ktype) {