如何解决通过clickhouse时间函数重新采样数据时open_price等于close_price的错误?
Posted
技术标签:
【中文标题】如何解决通过clickhouse时间函数重新采样数据时open_price等于close_price的错误?【英文标题】:how can fix the error that open_price equal to close_price when resample data by clickhouse time function? 【发布时间】:2020-08-26 05:28:35 【问题描述】: query_sql = f"""
WITH
toDateTime('start.date() 21:00:00') AS StartTimestamp,
toDateTime('end_date 15:00:00') AS EndTimestamp
SELECT
local_symbol,
max(last_price) AS high_price,
min(last_price) AS low_price,
argMax(last_price, toUnixTimestamp(fast)) as close_price ,
argMin(last_price, toUnixTimestamp(fast)) as open_price,
sum(volume) AS volume,
sum(amount) AS amount
FROM tick
WHERE (datetime >= StartTimestamp) AND (datetime <= EndTimestamp) AND local_symbol='symbol'
-- GROUP BY toStartOfInterval(datetime, INTERVAL n minute ) as fast,local_symbol
GROUP BY toStartOfMinute(datetime) as fast,local_symbol
ORDER BY fast ASC
"""
这是我的 SQL 代码,我想获取 open_price、high_price、low_price、close_price,但我的 SQL 结果不符合预期
open_price 始终等于 close_price,其他正确。
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3826.0, 'close_price': 3827.0, 'open_price': 3827.0, 'volume': 409, 'amount': 15653230.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3826.0, 'close_price': 3827.0, 'open_price': 3827.0, 'volume': 357, 'amount': 13663860.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3825.0, 'close_price': 3827.0, 'open_price': 3827.0, 'volume': 1058, 'amount': 40483280.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3825.0, 'close_price': 3826.0, 'open_price': 3826.0, 'volume': 972, 'amount': 37193310.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3826.0, 'close_price': 3828.0, 'open_price': 3828.0, 'volume': 643, 'amount': 24608060.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3826.0, 'close_price': 3827.0, 'open_price': 3827.0, 'volume': 739, 'amount': 28276760.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3827.0, 'close_price': 3828.0, 'open_price': 3828.0, 'volume': 118, 'amount': 4516640.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3828.0, 'low_price': 3826.0, 'close_price': 3828.0, 'open_price': 3828.0, 'volume': 678, 'amount': 25949650.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3829.0, 'low_price': 3827.0, 'close_price': 3827.0, 'open_price': 3827.0, 'volume': 1009, 'amount': 38630160.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3831.0, 'low_price': 3829.0, 'close_price': 3830.0, 'open_price': 3830.0, 'volume': 1798, 'amount': 68865630.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
'local_symbol': 'rb2010.CTP', 'high_price': 3831.0, 'low_price': 3829.0, 'close_price': 3830.0, 'open_price': 3830.0, 'volume': 1039, 'amount': 39797350.0, '_database': <infi.clickhouse_orm.database.Database object at 0x0000022EF5C95408>
我是不是做错了什么?
【问题讨论】:
【参考方案1】:我已经使用argMin(last_price, toUnixTimestamp(datetime)) as open_price
解决了,
【讨论】:
以上是关于如何解决通过clickhouse时间函数重新采样数据时open_price等于close_price的错误?的主要内容,如果未能解决你的问题,请参考以下文章
如何解决GD32F103在重新上电AD采样时偶尔有6个码的跳动