Jaromir Hamala
Jaromir Hamala

Reputation: 1910

How to generate a candle stick chart with QuestDB?

I have a table with market data. The table structure looks like this:

symbol side price amount timestamp
BTC-USD buy 35831.56 0.00051151 2023-11-15T10:42:11.754626Z

I need to aggregate prices for a given symbol by time intervals. In each time interval, I need to know: the opening price, closing price, maximum price and minimum price.

Upvotes: 2

Views: 162

Answers (1)

Equinox
Equinox

Reputation: 6758

Open would be first price, close would be last price, Use sample.

SELECT 
    TIMESTAMP,
    FIRST(PRICE) AS OPEN_PRICE,
    LAST(PRICE) AS CLOSE_PRICE,
    MAX(PRICE) AS MAX_PRICE,
    MIN(PRICE) AS MIN_PRICE,
FROM trades
SAMPLE BY 1h

Upvotes: 2

Related Questions