0
        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>}

我做错什么了吗?

4

1 回答 1

0

我已经通过使用解决了argMin(last_price, toUnixTimestamp(datetime)) as open_price

于 2020-08-26T05:32:38.040 回答