我需要使用Redis时间序列模块创建价格时间序列的每分钟烛台聚合
我能够聚合大多数必需的列,如openPrice(使用第一个)、closePrice(使用最后一个)、highPrice(使用最大值)、lowPrice(使用最小值)
然而,我完全不知道如何有效地聚合openTimestamp和closeTimestamp
一般来说,我无法找到一种方法来访问时间序列的时间戳并为其创建规则
我可以使用规则执行它的唯一方法是,除了我的价格时间序列之外,还保存一个带有(timestamp,timestamp)的时间序列,我真的不想这样做
这是我的示例代码
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
目前没有回答
相关问题 更多 >
编程相关推荐