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

主宰稳场 提交于 2020-12-13 03:37:49

问题


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.

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.

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)

My questions are:

  1. Is there a way to send more than one aggregation (like max, last...etc.) in one rule, instead of creating multiple source and destination buckets for each stock?
  2. Is Redis TimeSeries an appropriate choice for this task? Or will it be easier to use a another solution (such as Redis streams for example)?

回答1:


  1. There is no option to send more than one aggregation to a downsample series since each timestamp can hold a single. You can utilize labels to query all series at once.
  2. RedisTimeSeries would be a good solution as it will downsample your data at insertion so querying it would be super fast. It also uses double-delta compression which means your data will require lesser memory than some other solutions. You can even use retention to retire the source data if all you care about is the candlesticks.
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)



回答2:


f4, thanks for trying RedisTimeSeries.

You can configure the module to create rules automatically acorrding to predefined rules. It's described in the documentation: https://oss.redislabs.com/redistimeseries/configuration/#compaction_policy-policy.

I Hope that will solve your issue.



来源:https://stackoverflow.com/questions/62530654/is-redis-timeseries-the-right-tool-to-capture-candle-sticks-in-stock-prices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!