Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Esper (C.E.P.) query to calculate candlesticks every full minute

I am using Complex Event Processing (Esper) technology to provide a real-time candlestick calculations in my system. I am doing fine with calculating values, however I find it difficult to ensure that candle window starts at full minutes (for one minute candle) and ends before the next minute starts (i.e. candle 1[06:00.000 - 06:00.999], candle 2[06:01.000 - 06:01.999], etc... ).

Is there a pattern or command in Esper's query language that is able to provide such functionality?

I'd appreciate constructive comments and directions.

like image 733
Michal Avatar asked Oct 17 '25 12:10

Michal


2 Answers

In Esper you can use a pattern to fire every minute at the zero second, i.e.
insert into TriggerEvent select * from pattern[pattern[every timer:interval(1 min).] // named window to hold candle data, compute next candle on TriggerEvent select * from NamedWindowCandle .... // delete old data on TriggerEvent delete from NamedWindowCandle

-rg

like image 111
Rainer Guessner Avatar answered Oct 19 '25 12:10

Rainer Guessner


Local time is often different from exchange time, also there is latency in delivering tick data. Minute bars are often computed using exchange timestamp. The exchange timestamp value must be extracted from tick events. New minute bar event is sent when the tick timestamps enter new minute.

like image 25
lsac Avatar answered Oct 19 '25 13:10

lsac