Subscribe to publisher/TickerPlant

Hi all, 

I want to subscribe to publisher, which means I want publisher publish data to my subscriber for like… every per second.

Below is my idea,

publisher/server side:

\p 5000

n:100

trade:([]sym:n?```3``;size:n?``100``;price:n?1f)

\t 1000

.u.sub:{ .z.ts:{ h(upd;trade;1?trade) }}

subscriber/client side:

h:hopen 5000

trade:( sym:() ;size:() ; price:() )

upd:{ [t;x] t upsert x }

h(`.u.sub)

what I missing, and what went wrong ?

Thank you all, 

Cheers 

Hi Jimmy,

I made a few changes to get your example.

namely opening a server on port 5004 and client on 5004 and how to run .u.sub.


In order to run .u.sub on the server from the client side you need to use the command: h(.u.sub). The second backtick tells q to run the function with an empty set of parameters, which is what you wish to do. Using h(`.u.sub) just returns the function definition as no parameters are applied.


In addition, if a connection to the client (5004) from the server (5005) is not made then running h(.u.sub) will result in an error as h is not set.


More information on feed set ups can be found at http://code.kx.com/wiki/Startingkdbplus/tick.


SERVER

\p 5005

n:100

trade:(sym:n?`3;size:n?100;price:n?1f)

h:hopen 5004

.u.sub:{ .z.ts:{ h(upd;trade;1?trade) }}

\t 1000

CLIENT
\p 5004

h:hopen 5005

upd:{ [t;x] t upsert x }

h(.u.sub)

Hope this information helps.

Regards,

Thomas Smyth

AquaQ Analytics

Hi Thomas,

Thank you for your reply. 

The way you suggest probably won’t work, cause the server side doesn’t allow me to make a connection, but I will try the way you suggest later, maybe I am wrong.

Btw, I try another way at the meantime,

server side:

\p 5000

.u.subscribers:()

trade:([]sym:n?```3``;size:n?``100``;price:n?1f)

.u.sub:{ .u.subscribers:.u.subscribers,:.z.w }

\t 1000

.z.ts:{ neg.u.subscribers }

client side:

trade:( sym:() ; size:() ; price:() )

h:hopen 5000

upd:{ [t;x] t upsert x }

h(`.u.sub)

Same here, I want the server to publish data every per second to the trade table on the client side.

Still something wrong here … 

Cheers mate,

Jimmy

thomas...@aquaq.co.uk? 2016?3?14??? UTC??5?29?39???

Hi Jimmy,

I made a few changes to get your example.

namely opening a server on port 5004 and client on 5004 and how to run .u.sub.


In order to run .u.sub on the server from the client side you need to use the command: h(.u.sub). The second backtick tells q to run the function with an empty set of parameters, which is what you wish to do. Using h(`.u.sub) just returns the function definition as no parameters are applied.


In addition, if a connection to the client (5004) from the server (5005) is not made then running h(.u.sub) will result in an error as h is not set.


More information on feed set ups can be found at http://code.kx.com/wiki/Startingkdbplus/tick.


SERVER

\p 5005

n:100

trade:(sym:n?`3;size:n?100;price:n?1f)

h:hopen 5004

.u.sub:{ .z.ts:{ h(upd;trade;1?trade) }}

\t 1000

CLIENT
\p 5004

h:hopen 5005

upd:{ [t;x] t upsert x }

h(.u.sub)

Hope this information helps.

Regards,

Thomas Smyth

AquaQ Analytics

The official kdb tickerplant code allows for 1-second publishing out of the box, just have to start the tickerplant with “-t 1000” on the command line.

You might still have to manufacture dummy data in the trade table but you could do that within the .z.ts function on the publisher side

Terry