Redis TimeSeries 是捕捉股票价格烛台的正确工具吗 [英] Is Redis TimeSeries the right tool to capture candle sticks in stock prices

查看:86
本文介绍了Redis TimeSeries 是捕捉股票价格烛台的正确工具吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently trying to do a simple implementation for stock price candle sticks. Let's say we have a stock called XYZ. This stock receives a stream of prices (in no particular frequency), which (for example) looks like: XYZ: [10.2, 10.7, 12, 11 ....].

目标是记录每分钟过去的一些指标,以反映该股票的状态.烛台 具有收盘价(一分钟内的最后已知价格)等指标, 高价(一分钟内最高价)...等

The objective is to record some metrics for every minute that passes to reflect the state of that stock. A candle stick has metrics like Closing price (last known price within a minute), High Price (maximum price within a minute)...etc.

我认为可以实现的一种方法是使用 Redis TimeSeries.我考虑了这个解决方案,因为我可以在价格流上创建规则,并且每个60 秒它会将一些聚合(如:max、min、first..等)刷新到目标存储桶.

One way I thought I can implement this is by using Redis TimeSeries. I considered this solution because I can create rules on the stream of prices, and every 60 seconds it would flush some aggregations (like: max, min, first..etc.) to a destination bucket.

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

My current implementation using Redis TimeSeries (in Python) for candle sticks for each stock price looks something like this (using stock XYZ as example again) and no labels for simplicity:

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. 有没有一种方法可以在一个规则中发送多个聚合(如 max、last...等),而不是为每只股票创建多个源和目标存储桶?
  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)

这篇关于Redis TimeSeries 是捕捉股票价格烛台的正确工具吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆