3 weeks ago
I am having issues finding what my error is with this code:
{[tab]
tab: update exQuality: $[side=`B & price <= ask; 1b; side=`S & price >= bid; 1b; 0b] from tab
}
I get a mismatched types error...but when I do a meta on the tab I get:
c | t f a
-----| -----
price | j
side | s
bid | j
ask | j
so I am not sure where that mistype is coming from. Any help would be greatly appreciated.
Thanks
3 weeks ago
First, remember that the operations are executed from right to left. For example side=`B & price <= ask is equivalent to side=(`B & (price <= ask)). So you are trying to do an AND between a boolean and a symbol which leads to a type error. You should use parentheses e.g. around side=`B if you want that to be executed first.
Second, the $ conditional takes a single value, not a vector. There is a vector conditional operation that works on vectors instead.
Third, you can take advantage of operators such as <= >= & being atomic. You shouldn't need to use any kind of conditional - in general the pattern $[x;1b;0b] (or the vector version ?[x;1b;0b]) can be replaced by just x, and the two branches that return true can be joined together with an or instead.
3 weeks ago
First, remember that the operations are executed from right to left. For example side=`B & price <= ask is equivalent to side=(`B & (price <= ask)). So you are trying to do an AND between a boolean and a symbol which leads to a type error. You should use parentheses e.g. around side=`B if you want that to be executed first.
Second, the $ conditional takes a single value, not a vector. There is a vector conditional operation that works on vectors instead.
Third, you can take advantage of operators such as <= >= & being atomic. You shouldn't need to use any kind of conditional - in general the pattern $[x;1b;0b] (or the vector version ?[x;1b;0b]) can be replaced by just x, and the two branches that return true can be joined together with an or instead.
3 weeks ago
Thanks!! That helped a tonne!!
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.