timescale / docs

Timescale product documentation 📖
https://docs.timescale.com/
50 stars 96 forks source link

[Feedback] Page: /api/latest/hyperfunctions/time_bucket/ #2793

Open lyncodes opened 11 months ago

lyncodes commented 11 months ago

Is it easy to find the information you need?

Yes

Are the instructions clear?

Yes

How could we improve the Timescale documentation site?

the time_bucket fuction lost precision when the timestamp not reach 3rd second yet.

the DDL is followed as create table delta ( id bigint default nextval('delta_id_seq'::regclass), symbol varchar(16), delta_value numeric(18, 5), delta_ratio numeric(5, 3), open_price numeric(18, 5), high_price numeric(18, 5), close_price numeric(18, 5), low_price numeric(18, 5), amount numeric(18, 5), trading_date_time timestamp not null, volume numeric(18, 6), seconds integer, ask_amount numeric(18, 5), bid_amount numeric(18, 5) );

SELECT time_bucket('${timeFrame}', trading_date_time) AS bucket, symbol as symbol, FIRST(open_price, trading_date_time) AS openPrice, MAX(high_price) AS highPrice, MIN(low_price) AS lowPrice, LAST(close_price, trading_date_time) AS closePrice, SUM(volume) AS volume, '${timeFrame}' as timeFrame FROM delta where trading_date_time between #{start} and #{end} and symbol = #{symbol} GROUP BY bucket, symbol order by bucket

case is here:

  1. if the timestamp is after the 3rd second of each minute, the time_bucket can return the latest candle aggregation result like this image

  2. on the contrary. image

hope for response.

github-actions[bot] commented 11 months ago

Thank you for the report. We welcome documentation contributions!

jamessewell commented 10 months ago

Hello @lyncodes! Could you please provide some raw data which triggers this issue?

I had a play but can't seem to produce your output.

One possible reason could be that your timestamps for the 14:33 bucket start at 14:33:04 (and so are excluded by your WHERE), but I'm guessing you've checked this?

lyncodes commented 10 months ago

sorry for late respose. yes, the problem is still there. here is the sample data tsdb_public_delta.zip

============== my expectation is this: if timestamp reach 14:10:59, the bucket should only reach 14:10. only if the timestamp crossed 14:11:00, means this minute is over, then the bucket can reach 14:11 but current senerior is weird. pass the 3rd second will return the new bucket. 😂😂😂

thanks.