-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcx.q
69 lines (56 loc) · 1.66 KB
/
cx.q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// cx.q
/// example clients
///
/// Try not to define tables.
x:.z.x 0 / client type
s:`; / default all symbols
d:`GOOG`IBM`MSFT / symbol selection
// Switch to the sub-set if something else on the command-line.
if[ count .z.x 1; s:d]
t:`trade`quote / default tables
h:hopen `::5010 / connect to tickerplant
/// rdb
/// No knowledge of the schema of the underlying tables.
if[x~"rdb";
upd:insert]
/ high low close volume
if[x~"hlcv";
t:`trade;
hlcv:([sym:()]high:();low:();price:();size:());
upd:{[t;x]hlcv::select max high,min low,last price,sum size by sym
from(0!hlcv),select sym,high:price,low:price,price,size from x}]
/ last
/ If last appears as first part of string
.t.x:()
if[any 0 = x ss "last";
upd:{[t;x]
if [ 0 = count .t.x; .t.x:x ];
.[t;();,;select by sym from x] } ]
/ show only - runs on the timer.
if[x~"show";
tabcount:()!();
/ count the incoming updates
upd:{[t;x] tabcount+::(enlist t)!enlist count x};
/ show the dictionary every t milliseconds
.z.ts:{if[0<count tabcount;
-1"current total received record counts at time ",string .z.T;
show tabcount;
-1"";]};
if[0=system"t"; system"t 5000"]]
/ all trades with then current quote
if[x~"tq";
upd:{[t;x]$[t~`trade;
@[{tq,:x lj q};x;""];
q,:select by sym from x]}]
if[x~"vwap";t:`trade;
upd:{[t;x]vwap+:select size wsum price,sum size by sym from x};
upds:{[t;x]vwap+:select size wsum price,sum size by sym from x;show x}]
{h(".u.sub";x;s)} each t;
/ Local Variables:
/ mode:q
/ q-prog-args: "last d -p 5016 -t 1000"
/ fill-column: 75
/ comment-column:50
/ comment-start: "/ "
/ comment-end: ""
/ End: