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:
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)