kdb+ tick (RT)

This example demonstrates reading trade data from a tickerplant and writing a windowed aggregation back to the same tickerplant all using the RT reader and writer.


This example requires configuring the RT client library appropriately to set the implementation of the RT .rt.sub and .rt.pub APIs.

See the configuration documentation for more information about setting up the RT implementation.

// Read from a tickerplant using the RT API
stream: .qsp.read.fromRT[":tp:5000"]
    // Filter for only the trade table
    .qsp.filter[{`trade ~ first x}]
    // Map messages to their table batch component
    .qsp.map[{x 1}]
    // Collect batches into 1-second event-time intervals
    .qsp.window.tumbling[00:00:01; {.z.d+y`time}]
    // Calculate the average price and size of the window for each symbol
    .qsp.map[{ select min time, a: avg price, c: count i by sym from x }]
    // Convert to (name; (col1; col2; col3)) format expected by RT
    .qsp.map[{ (`windowedAverage; value flip x) }]
    // Write back to the same tickerplant

.qsp.run stream;