How to aggregate the timestamp using redis timeseries module?

910 Views Asked by At

I need to create a per minute candlesticks aggregation of the price time series using the Redis time series module.

I was able to aggregate most of the required columns like openPrice (using first), closePrice (using last), highPrice (using max), lowPrice (using min).

However I am absolutely clueless how to aggregate efficiently the openTimestamp and closeTimestamp.

In general I cannot find a way to access only the timestamp of the time series and create rules for it.

The only way that I can perform it using rules is to save in addition to my price time series a time series with (timestamp, timestamp) which I really don't want to do.

Here is my sample code.

from redistimeseries.client import Client
from datetime import datetime
from random import randint
rts = Client()


rts.create('price')
rts.create('openPrice')
rts.create('closePrice')
rts.create('lowPrice')
rts.create('highPrice')
rts.createrule('price', "openPrice", 'first', bucket_size_msec=60000)
rts.createrule('price', 'closePrice', 'last', bucket_size_msec=60000)
rts.createrule('price', 'lowPrice', 'min', bucket_size_msec=60000)
rts.createrule('price', 'highPrice', 'max', bucket_size_msec=60000)

# inserting test data
now = datetime.utcnow()
now_int = 1000 * int(now.timestamp())
prices = []
for i in range(5000):
    r_n = randint(1, 1000000)
    new_time = now_int + i*1000
    rts.add('price', new_time, r_n)

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

1

There are 1 best solutions below

1
On

Yes, redis timeseries is the right tool. With python, you can implement it in just a few lines of code using RedisTimeseriesManager