【问题标题】:GridDB downsample into OHLC bars with nanosecond epoch int as row keyGridDB 下采样到 OHLC 条,以纳秒纪元 int 作为行键
【发布时间】:2019-09-09 02:37:34
【问题描述】:

对于表结构,例如包含一个 int 键(反映所需的纳秒精度的纪元)和价格。如何将其下采样为具有时间间隔的开高低收行(ohlc 条)组,例如分钟?

【问题讨论】:

    标签: in-memory-database downsampling griddb


    【解决方案1】:

    我会通过使用多查询来解决这个问题,这比单独运行每个查询要快得多。对于您希望为其构建 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
    

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

    【讨论】:

      猜你喜欢
      • 2020-01-02
      • 2018-12-14
      • 2019-11-25
      • 2017-06-28
      • 2019-03-01
      • 2017-01-19
      • 2017-12-06
      • 1970-01-01
      相关资源
      最近更新 更多