docs icon indicating copy to clipboard operation
docs copied to clipboard

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

Open lyncodes opened this issue 1 year ago • 3 comments

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.

lyncodes avatar Nov 04 '23 06:11 lyncodes

Thank you for the report. We welcome documentation contributions!

  • For information about how to propose a change, see the contributing guide in our GitHub repository.
  • For information on style and word usage, see the style guide

github-actions[bot] avatar Nov 04 '23 06:11 github-actions[bot]

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?

jamessewell avatar Nov 24 '23 01:11 jamessewell

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.

lyncodes avatar Dec 16 '23 08:12 lyncodes