Redis TimeSeries 是捕捉股票价格蜡烛图的正确工具吗

Is Redis TimeSeries the right tool to capture candle sticks in stock prices

我目前正在尝试为股票价格蜡烛棒做一个简单的实现。假设我们有一只名为 XYZ 的股票。这只股票收到一系列价格(没有特定频率),(例如)看起来像:XYZ:[10.2, 10.7, 12, 11 ....].

objective 是为过去的每一分钟记录一些指标,以反映该股票的状态。 candle stick 具有收盘价(一分钟内最后已知价格)、最高价(一分钟内最高价)等指标。

我认为我可以实现这一点的一种方法是在价格流上使用 Redis TimeSeries. I considered this solution because I can create rules,每 60 秒它会刷新一些聚合(如:最大、最小、第一等)以目标存储桶。

我当前使用 Redis TimeSeries(在 Python 中)实现 每个 股票价格的烛台看起来像这样(再次使用股票 XYZ 作为示例)并且没有为简单起见的标签:

from redistimeseries.client import Client
r = Client()
r.flushdb()

# Create source & destination buckets
r.create('XYZ_PRICES')  # source
r.create(closing_price)
r.create(highest_price)
# Create rules to send data from src -> closing_price & highest_price buckets
r.createrule(src, 'closing_price', 'last', bucket_size_msec=60000)
r.createrule(src, 'highest_price', 'max', bucket_size_msec=60000)

我的问题是:

  1. 有没有一种方法可以在一个规则中发送多个聚合(如最大、最后...等),而不是为每只股票创建多个源和目标存储桶?
  2. Redis TimeSeries 是否适合此任务?或者使用其他解决方案(例如 Redis 流)会更容易吗?
  1. 没有选项可以将多个聚合发送到下采样系列,因为每个时间戳可以包含一个。您可以利用标签一次查询所有系列。
  2. RedisTimeSeries 将是一个很好的解决方案,因为它会在插入时对数据进行下采样,因此查询速度会非常快。它还使用双增量压缩,这意味着您的数据将需要比其他一些解决方案更少的内存。如果您只关心烛台,您甚至可以使用保留来淘汰源数据。
r.create('XYZ_PRICES', retention_msecs=300000, labels={'name':'xyz', 'type:src'})
 
r.create(opeing_price, labels={'name':'xyz', 'type:opening'})
r.create(closing_price, labels={'name':'xyz', 'type:closing'})
r.create(highest_price, labels={'name':'xyz', 'type:highest'})
r.create(lowest_price, labels={'name':'xyz', 'type:lowest'})

r.createrule(src, 'opening_price', 'first', bucket_size_msec=60000)
r.createrule(src, 'closing_price', 'last', bucket_size_msec=60000)
r.createrule(src, 'lowest_price', 'min', bucket_size_msec=60000)
r.createrule(src, 'highest_price', 'max', bucket_size_msec=60000)

f4,感谢您试用 RedisTimeSeries。

您可以将模块配置为根据预定义的规则自动创建规则。 它在文档中有描述:https://oss.redislabs.com/redistimeseries/configuration/#compaction_policy-policy.

希望能解决您的问题。