mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 03:48:19 +08:00
fixed 分钟线更新, 更新日线以上数据更新
This commit is contained in:
parent
8e119984ed
commit
45782ec073
@ -897,7 +897,16 @@ void Stock::realtimeUpdate(KRecord record, KQuery::KType inktype) {
|
|||||||
|
|
||||||
// 如果传入的记录日期等于最后一条记录日期,则更新最后一条记录;否则,追加入缓存
|
// 如果传入的记录日期等于最后一条记录日期,则更新最后一条记录;否则,追加入缓存
|
||||||
if (tmp.datetime == record.datetime) {
|
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) {
|
} else if (tmp.datetime < record.datetime) {
|
||||||
m_data->pKData[ktype]->push_back(record);
|
m_data->pKData[ktype]->push_back(record);
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,46 +76,24 @@ static void updateStockDayUpData(const SpotRecord& spot, KQuery::KType ktype) {
|
|||||||
if (KQuery::WEEK == ktype) {
|
if (KQuery::WEEK == ktype) {
|
||||||
spot_end_of_phase = spot_end_of_phase - TimeDelta(2); // 周五日期
|
spot_end_of_phase = spot_end_of_phase - TimeDelta(2); // 周五日期
|
||||||
}
|
}
|
||||||
size_t total = stk.getCount(ktype);
|
|
||||||
|
|
||||||
// 没有历史数据,则直接更新并返回
|
// 重新计算交易金额、交易量
|
||||||
if (total == 0) {
|
Datetime spot_start_of_phase = startOfPhase(&spot_day);
|
||||||
stk.realtimeUpdate(KRecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close,
|
KRecordList klist =
|
||||||
spot.amount, spot.volume),
|
stk.getKRecordList(KQuery(spot_start_of_phase, spot_end_of_phase + TimeDelta(1), ktype));
|
||||||
ktype);
|
price_t sum_amount = 0.0, sum_volume = 0.0;
|
||||||
return;
|
for (const auto& k : klist) {
|
||||||
|
sum_amount += k.transAmount;
|
||||||
|
sum_volume += k.transCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRecord last_record = stk.getKRecord(total - 1, ktype);
|
price_t amount =
|
||||||
HKU_IF_RETURN(!last_record.isValid(), void());
|
spot.amount > sum_amount ? spot.amount - sum_amount : (sum_amount == 0.0 ? spot.amount : 0.0);
|
||||||
|
price_t spot_volume = spot.volume;
|
||||||
if (spot_end_of_phase > last_record.datetime) {
|
price_t volume =
|
||||||
// 如果当前的日期大于最后记录的日期,则为新增数据,直接更新并返回
|
spot_volume > sum_volume ? spot_volume - sum_volume : (sum_volume == 0.0 ? spot_volume : 0.0);
|
||||||
stk.realtimeUpdate(KRecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close,
|
KRecord krecord(spot_end_of_phase, spot.open, spot.high, spot.low, spot.close, amount, volume);
|
||||||
spot.amount, spot.volume),
|
stk.realtimeUpdate(krecord, ktype);
|
||||||
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!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateStockMinData(const SpotRecord& spot, KQuery::KType ktype) {
|
static void updateStockMinData(const SpotRecord& spot, KQuery::KType ktype) {
|
||||||
|
Loading…
Reference in New Issue
Block a user