basic socket communications?

406 views
Skip to first unread message

bjh

unread,
Jan 4, 2010, 8:18:26 PM1/4/10
to Kdb+ Personal Developers
Sorry if this is overly noob of badly formed, but I'm a trader trying
to evaluate kdb+ for a HFT infrastructure, and my developer skills are
weak.

I can't find an example anywhere of opening a client socket connection
and writing a string to it (some trivial login message maybe), or
something similar to a while(true) do {} loop with a listener.

Can someone paste some trivial code or give me a pointer to a
resource? All I can find is mentions of IPC for Q processes.

Thanks in advance.

Attila Vrabecz

unread,
Jan 5, 2010, 4:49:53 AM1/5/10
to personal...@googlegroups.com
you would have to do it yourself by extending with C/C++ or through Java/C# etc
note that reading from sockets can be put on kdb+'s select loop (look for sd0 and s1 for example in https://code.kx.com/trac/wiki/Cookbook/InterfacingWithC)

Regards,
Attila

> --
>
> You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
> To post to this group, send email to personal...@googlegroups.com.
> To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
>
>

bjh

unread,
Jan 5, 2010, 10:35:39 AM1/5/10
to Kdb+ Personal Developers
OK, perhaps this leads to a better question. Let's say my use case is
that I want to do real-time metrics on the NYSE ARCABook feed. VWAPs,
correlations, etc.

Is the "proper" approach to actually write the market data gateway in
C/C++/Java, and then interface kdb+ to that? I was hoping to actually
write the market data listener directly in Q.

At this level of cost/capability, crossing process boundaries, even
using Unix Domain Sockets, is really worth avoiding, if possible.

Thanks!

Charles Skelton

unread,
Jan 5, 2010, 10:46:55 AM1/5/10
to personal...@googlegroups.com
Attila has given you the link for info on writing a client app that
sends data to a kdb+, but you would likely benefit from loading a
shared library into kdb+ that did the comms with the NYSE ARCABook
feed and called back into Q with the data. Attila did mention that you
can hook into the kdb+ main loop with sd1/sd0 which would then
callback to your code from the main thread when data has arrived on
that socket, allowing you to read the socket, create some k objects
and push them up for processing in Q. The info for interfacing and
extending with c can be found here

https://code.kx.com/trac/wiki/Cookbook/InterfacingWithC
https://code.kx.com/trac/wiki/Cookbook/ExtendingWithC

And Arthur's notes

http://kx.com/q/c/c/a.c
http://kx.com/q/c/c/a.q
http://kx.com/q/c/c/readme.txt

And for reference how it is done with the Reuters SSL api

http://kx.com/q/c/feed/ssl.c
http://kx.com/q/tick/ssl.q

Felix Lungu

unread,
Jan 5, 2010, 11:00:16 AM1/5/10
to personal...@googlegroups.com
attached is generic socket interface.
it compiles on unices (linux and osx) and it should not be hard to
port it to windows.
get k.h from http://kx.com/q/c/c/k.h. place the skt.so in appropriate
directory for q shared libs
(usualy ~/q/l32/ for 32bit linux).

felix

skt.c
skt.q

bjh

unread,
Jan 5, 2010, 11:45:00 AM1/5/10
to Kdb+ Personal Developers
Thanks very much guys. Sorry to ask questions over my head, but I'm
already learning a lot.
Reply all
Reply to author
Forward
0 new messages