GridDB下采样到以纳秒纪元int作为行键的OHLC条中

问题描述 投票:0回答:1

对于表结构,例如包含一个int密钥(反映以纪元为单位的时元精度)和价格。如何使用时间间隔将其降采样为开放的高低封闭行(ohlc条)组。分钟?

in-memory-database downsampling
1个回答
0
投票

我将通过使用多查询来解决问题,这比单独运行每个查询要快得多。您希望为其构建OHLC条的每个期间都会有四个查询。下面的伪代码给出了一个粗略的解决方案,其中省略了一些可以在GridDB的MultiQuery documentation中找到的细节。

对于期间:

queries.add("select min(price) where epoch > period.start and epoch < period.end")
  queries.add("select max(price) where epoch > period.start and epoch < period.end")
  queries.add("select * where epoch > period.start order by epoch asc limit 1")
  queries.add("select * where epoch < period.end order by epoch desc limit 1")

fetch_all(queries)

while i < len(queries)
  for metric in ['low', 'high', 'open', 'close']:
     query = queries[i]
     rs = query.get_rs()
     while rs.has_next():
          bars[period[p].start][metric] = rs.next()
     i=i+1
  p=p+1

**请注意,虽然尚不支持纳秒精度。

© www.soinside.com 2019 - 2024. All rights reserved.