From e248a6ac8c7e9498701907b7dee86905211f338e Mon Sep 17 00:00:00 2001 From: chraberturas Date: Thu, 22 Feb 2024 15:01:04 +0100 Subject: [PATCH 1/3] Initial ideas for migrating to the new 4.1 version. Additionally, I've made some minor changes resulting in code that is more concise. --- tick.q | 2 +- tick/r.q | 2 +- tick/u.q | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tick.q b/tick.q index 0680992..da3d438 100644 --- a/tick.q +++ b/tick.q @@ -27,7 +27,7 @@ if[not system"p";system"p 5010"] \l tick/u.q \d .u ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length ",(string last i)," and restart";exit 1];hopen L}; -tick:{init[];if[not min(`time`sym~2#key flip value@)each t;'`timesym];@[;`sym;`g#]each t;d::.z.D;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]}; +tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;(L;l):(`$":",y,"/",x,10#".";ld d)]}; endofday:{end d;d+:1;if[l;hclose l;l::0(`.u.ld;d)]}; ts:{if[di:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)];(x;$[99=type v:value x;sel[v]y;@[0#v;`sym;`g#]])} -sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]} +sub:{[x:{$[not x in t,`;'x;x]};y]if[x~`;:sub[;y]each t];del[x].z.w;add[x;y]} end:{(neg union/[w[;;0]])@\:(`.u.end;x)} From 8062945d5523df9ca34b0fa78fd128509c1d1311 Mon Sep 17 00:00:00 2001 From: chraberturas Date: Tue, 27 Feb 2024 13:43:08 +0100 Subject: [PATCH 2/3] Encapsulated common code in tickerplant code and revert some changes as discussed in PR --- tick.q | 11 ++++------- tick/r.q | 2 +- tick/sym.q | 2 ++ tick/u.q | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 tick/sym.q diff --git a/tick.q b/tick.q index da3d438..621a57a 100644 --- a/tick.q +++ b/tick.q @@ -27,22 +27,19 @@ if[not system"p";system"p 5010"] \l tick/u.q \d .u ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length ",(string last i)," and restart";exit 1];hopen L}; -tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;(L;l):(`$":",y,"/",x,10#".";ld d)]}; +tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]}; endofday:{end d;d+:1;if[l;hclose l;l::0(`.u.ld;d)]}; ts:{if[dtype first x;a,x;enlist[count[first x]#a],x]]]}; // Common function in both options (Batch; Real Time) if[system"t"; .z.ts:{pub'[t;value each t];@[`.;t;@[;`sym;`g#]0#];i::j;ts .z.D}; - upd:{[t;x] - if[not -16=type first first x;if[d<"d"$a:.z.P;.z.ts[]];a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]]; - t insert x;if[l;l enlist (`upd;t;x);j+:1];}]; + upd:{{[t;x]t insert x;if[l;l enlist (`upd;t;x);j+:1];}[x]updC y}]; if[not system"t";system"t 1000"; .z.ts:{ts .z.D}; - upd:{[t;x]ts"d"$a:.z.P; - if[not -16=type first first x;a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]]; - f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}]; + upd:{{[t;x]f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}[x] updC y}]; \d . .u.tick[src;.z.x 1]; diff --git a/tick/r.q b/tick/r.q index b6b74e1..6da4c4b 100644 --- a/tick/r.q +++ b/tick/r.q @@ -12,7 +12,7 @@ upd:insert; .u.end:{t:tables`.;t@:where `g=attr each t@\:`sym;.Q.hdpf[`$":",.u.x 1;`:.;x;`sym];@[;`sym;`g#] each t;}; / init schema and sync up from log file;cd to hdb(so client save can run) -.u.rep:{(set) .' x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y}; +.u.rep:{(.[;();:;].)each x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y}; / HARDCODE \cd if other than logdir/db / connect to ticker plant for (schema;(logcount;log)) diff --git a/tick/sym.q b/tick/sym.q new file mode 100644 index 0000000..500191a --- /dev/null +++ b/tick/sym.q @@ -0,0 +1,2 @@ +// trade table schema +trade:([]time:`timespan$();sym:`g#`symbol$();bid:`float$();ask:`float$()); \ No newline at end of file diff --git a/tick/u.q b/tick/u.q index 5e48f29..aee4356 100644 --- a/tick/u.q +++ b/tick/u.q @@ -3,9 +3,9 @@ /2006.05.08 add \d .u -init:{(w;t)::(t!();tables`.)} +init:{w::(t::tables`.)!()} -(del;.z.pc):({w[x]_:w[x;;0]?y};{del[;x]each t}) +del:{w[x]_:w[x;;0]?y};.z.pc:{del[;x]each t}; sel:{(select from x where sym in y;x)`~y} From b88ea312543e9603c482d1a80710f2c165a58f68 Mon Sep 17 00:00:00 2001 From: chraberturas Date: Tue, 27 Feb 2024 13:43:08 +0100 Subject: [PATCH 3/3] Encapsulated common code in tickerplant code and revert some changes as discussed in PR --- tick.q | 11 ++++------- tick/r.q | 2 +- tick/u.q | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tick.q b/tick.q index da3d438..621a57a 100644 --- a/tick.q +++ b/tick.q @@ -27,22 +27,19 @@ if[not system"p";system"p 5010"] \l tick/u.q \d .u ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::-11!(-2;L);if[0<=type i;-2 (string L)," is a corrupt log. Truncate to length ",(string last i)," and restart";exit 1];hopen L}; -tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;(L;l):(`$":",y,"/",x,10#".";ld d)]}; +tick:{[x:{init[];$[not min(`time`sym~2#key flip value@)each t;'`timesym;x]};y]@[;`sym;`g#]each t;d::.z.D;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]}; endofday:{end d;d+:1;if[l;hclose l;l::0(`.u.ld;d)]}; ts:{if[dtype first x;a,x;enlist[count[first x]#a],x]]]}; // Common function in both options (Batch; Real Time) if[system"t"; .z.ts:{pub'[t;value each t];@[`.;t;@[;`sym;`g#]0#];i::j;ts .z.D}; - upd:{[t;x] - if[not -16=type first first x;if[d<"d"$a:.z.P;.z.ts[]];a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]]; - t insert x;if[l;l enlist (`upd;t;x);j+:1];}]; + upd:{{[t;x]t insert x;if[l;l enlist (`upd;t;x);j+:1];}[x]updC y}]; if[not system"t";system"t 1000"; .z.ts:{ts .z.D}; - upd:{[t;x]ts"d"$a:.z.P; - if[not -16=type first first x;a:"n"$a;x:$[0>type first x;a,x;(enlist(count first x)#a),x]]; - f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}]; + upd:{{[t;x]f:key flip value t;pub[t;$[0>type first x;enlist f!x;flip f!x]];if[l;l enlist (`upd;t;x);i+:1];}[x] updC y}]; \d . .u.tick[src;.z.x 1]; diff --git a/tick/r.q b/tick/r.q index b6b74e1..6da4c4b 100644 --- a/tick/r.q +++ b/tick/r.q @@ -12,7 +12,7 @@ upd:insert; .u.end:{t:tables`.;t@:where `g=attr each t@\:`sym;.Q.hdpf[`$":",.u.x 1;`:.;x;`sym];@[;`sym;`g#] each t;}; / init schema and sync up from log file;cd to hdb(so client save can run) -.u.rep:{(set) .' x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y}; +.u.rep:{(.[;();:;].)each x;if[null first y;:()];-11!y;system "cd ",1_-10_string first reverse y}; / HARDCODE \cd if other than logdir/db / connect to ticker plant for (schema;(logcount;log)) diff --git a/tick/u.q b/tick/u.q index 5e48f29..aee4356 100644 --- a/tick/u.q +++ b/tick/u.q @@ -3,9 +3,9 @@ /2006.05.08 add \d .u -init:{(w;t)::(t!();tables`.)} +init:{w::(t::tables`.)!()} -(del;.z.pc):({w[x]_:w[x;;0]?y};{del[;x]each t}) +del:{w[x]_:w[x;;0]?y};.z.pc:{del[;x]each t}; sel:{(select from x where sym in y;x)`~y}