'Select last n rows of data from keyedTable and append to reactiveStateEngine

I made a system as follows: Realtime Tick Data coming from python --> Realtime OHLC is updated with every Tick using reactiveStateEngine(I cannot use timeSeriesEngine as it will not update data with every tick and I found its aggregation a bit weird) --> stored in KeyedTable to remove duplicates (as I need last data I cannot use keyedStreamTable) --> I am stuck here calculation engine (reactiveStateEngine)

How can I select the last n rows of data from keyedTable and append them to calculation engine automatically with every tick?

Would appreciate it if someone can help :)



Solution 1:[1]

I think using keyedTable and append to ENgine will be hard since every update needs to be appended to Engine. You can write a for loop to do that. You can try the following, which will keep the last data as well.

share streamTable(10:0,`symbol`ts`ts_m5`om5`hm5`lm5`cm5`vm5,[SYMBOL,TIMESTAMP,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE]) as trades1
tempTable = table(1:0, `ts_m5`symbol`ts`om5`hm5`lm5`cm5`vm5, [TIMESTAMP,SYMBOL,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE])
outputTable = table(1:0, `symbol`ts_m5`ts`om5`hm5`lm5`cm5`vm5, [SYMBOL,TIMESTAMP,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE])
rsMavg = createReactiveStateEngine(name="calc_mavg", metrics=<[ts_m5, ts,mavg(om5,3), mavg(hm5,3),mavg(lm5,3),mavg(cm5,3),mavg(vm5,3)]>, dummyTable=tempTable, outputTable=outputTable, keyColumn=`symbol)
csEngine1=createCrossSectionalEngine(name="csEngineDemo1", metrics=<[last(ts), last(om5), last(hm5), last(lm5), last(cm5), last(vm5)]>, dummyTable=trades1, outputTable=rsMavg, keyColumn=`symbol`ts_m5, triggeringPattern="keyCount",triggeringInterval =(1500,200s), useSystemTime=false, timeColumn=`ts_m5,lastBatchOnly = true, contextByColumn=`symbol)
subscribeTable(tableName="trades1", actionName="tradesStats", handler=append!{csEngine1}, msgAsTable=true)
replay(inputTables=x,outputTables=trades1,dateColumn=`ts_m5,timeColumn=`ts_m5)
select * from outputTable;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FFF