Pulling nbbo data from KDB server -
i have table of tickers date, start time, end time need pull nbbo nbbo table on server. eg
date starttime endtime sym 2014.05.01 15:10:38.000 15:10:58.000 kt 2014.05.01 15:15:53.000 15:16:23.000 ibm 2014.05.01 15:37:39.000 15:37:59.000 aapl ideally, open handle server , pull data each row passing function:getnnbo , calling as: getnnbo[kt;2014.05.01;15:10:38.000; 15:10:58.000]` function defined as
getnbbo:{[sym;dt;starttime;endtime]:h1"select 0.5*(first bid + first ask) nbbo date=",string[dt],",sym =`",string[sym], ",linetime within (",string[starttime],",",string[endtime],")"} this function works when call getnnbo[kt;2014.05.01;15:10:38.000; 15:10:58.000]` not sure how each row in table have work handle server.
i suggest instead of making request each row on server, send full table (or part if it's huge) @ once , fetch data in 1 request server. should speed process because of less requests , server take less time in generating result doing calculation on list faster individual row.
so function should below (just example). can optimize/modify according need. assume ticker table has 1 entry each (date;sym) combination can serve primary key.
getdata:{[tbl] select 0.5*first[bid]+first[ask] (nbbo ij `date`sym xkey tbl) linetime within (st;et) } then run on server using server handle. 'tbl' input table tickers.
handle(getdata;tbl) edit after ma3266 comment:
i assuming following 2 conditions:
a) nbbo table partitioned on server
b) input tbl has date , symbol column names same in nbbo. otherwise can use 'xcol' rename them.
getdata:{tbl:0!tbl; tempnbbo:0!select nbbo date in tbl`date,sym in tbl`sym ; select 0.5*first[bid]+first[ask] (tempnbbo ij `date`sym xkey tbl) linetime within (starttime;endtime)} but can lead heavy memory usage if input table has data many dates. in case can use following function break input table date.
getdata:{tbl:0!`date xasc tbl; raze { tempnbbo:0!select nbbo date in x`date,sym in x`sym ; select 0.5*first[bid]+first[ask] (tempnbbo ij `date`sym xkey x) linetime within (starttime;endtime)} each (where differ tbl`date) cut tbl} in both function, first removing primary key attribute input table.
also, check column types of nbbo , input table. might giving type error. query working fine me.
Comments
Post a Comment