cancel
Showing results for
Did you mean:

## fundamentals capstone 3.2

New Contributor

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

so I am not sure where that mistype is coming from. Any help would be greatly appreciated.

Thanks

1 ACCEPTED SOLUTION
Contributor

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.

2 REPLIES 2
Contributor

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.

New Contributor

Thanks!! That helped a tonne!!