KX Community

Find answers, ask questions, and connect with our KX Community around the world.

Home Forums KX Solutions c# API – Is it possible to build (dynamically) and run aggregate queries to receive real time streaming results using the c# API

  • c# API – Is it possible to build (dynamically) and run aggregate queries to receive real time streaming results using the c# API

    Posted by dg on June 12, 2023 at 12:00 am

    I’m dynamically building and executing aggregate queries vs kdb using the c# API. However I have to periodically poll/re execute the query for updates.

    I would like to build and  run aggregate queries from c# so that I receive real time aggregated results. Is this possible? If so please provide a brief explanation and references to particular docs.

    Thanks
    DG

    dg replied 1 month, 4 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • laura

    Administrator
    June 13, 2023 at 12:00 am

    Hi DG,

    Here are a few solutions depending on requirements/specifics:

    1. Depending on how dynamic the queries are, i.e. if it’s a mostly fixed list of aggregations, I would suggest using a Real Time Subscriber (RTS) and creating tables for the different aggregations, then subscribing to those aggregate tables from C# using .u.sub

    – Q Real Time Subscriber

    – C# KDB Q Subscriber Example

    2. If the aggregations are very dynamic, create on the C# side a polling query to Q. This would be similar to static queries (examples below) but wrapped in a looping statement within C#.

    AquaQ Documentation on C# Aggregations
    KX Example Simple Query

    Note this second solution wouldn’t be truly Real-Time, but you could reduce the polling time to an extent where it’s close enough to real-time for your purposes.

    3. If you’re truly looking for Real-Time responses you could subscribe via a Gateway Process and treat it as an aggregator, then define the aggregation that’s run on-update via remote queries from C#. Something along the lines of:

    connection.ks(“.my.agg:{select avg price from x}”)

    Where the string would be defined by C# dynamically and run on-change.

    The 3rd method is quite a bit more complicated than the other two and will have a few issues that need to be overcome. I have noted it to answer this question in it’s completion but would advise either approach 1 or 2. If a non-polling approach is definitely required I’ll be happy to go into more detail on the third solution and the gotchas.

    Regards,

    Sam B

Log in to reply.