Hello
I’ve been wondering how to go about aggregate real-time stock data from the New York Stock Exchange. This is an example of the ticks
feed:
{"timestamp": "1587861684083", "stock": "AAPL", "price": 234.56, "size": 800}
{"timestamp": "1587861684083", "stock": "AAPL", "price": 234.57, "size": 200}
{"timestamp": "1587861684083", "stock": "AAPL", "price": 234.58, "size": 600}
{"timestamp": "1587861684087", "stock": "AAPL", "price": 234.50, "size": 400}
{"timestamp": "1587861684093", "stock": "MSFT", "price": 1234.56, "size": 10000}
Aggregating it to an OHLCV with a time bucket of 1 second and grouped by stock as an example:
O = first( price ) // first tick inside this time bucket
h = max( price ) // higiest tick inside this time bucket
L = min( price ) // lowest tick inside this time bucket
C = last( price ) // last tick inside this time bucket
V = sum( size ) // totall volume of shares traded tick inside this time bucket
we get the time bucket by:
1587861684083- 1587861684083 % 1000 -> 1587861684000
(it’s not really important whether the time bucket timestamp is “floored” or “ceiled”)
for AAPL:
{“timestamp”: “1587861684000”, “O”: 234.56, “H”: 234.58, “L”: 234.50, “C”: 234.50, “V”: 2000}
for MSFT:
{“timestamp”: “1587861684000”, “O”: 1234.56, “H”: 1234.56, “L”: 1234.56, “C”: 1234.56, “V”: 10000}
The end goal is to fire an even in pub/sub and store the produced aggregation in Redis Timeseries upon every final aggregation ( in this case every ). It’s also important not to produce aggregations for time buckets when there were no ticks. But it’s clear to me how to do that after I create the aggregate. What I need help with is the actual aggregation event.
Let me know if anything is unclear,
Cheers