I have two tables with order information, and am looking to find whether or not each order in one table has crossing potential with the other. Example tables:
t1:([]ric:`a`b`c;side:`buy`sell`buy;size:100 1000 400; startTime:09:31 09:40 09:40; endTime:09:33 09:45 09:41)
t2:([]ric:`a`b`c;side:`sell`buy`buy;size:90 1000 400; startTime:09:30 09:40 09:41; endTime:09:32 09:45 09:42)
I'm trying to find a way to iterate through each entry in t1 and query t2, and check if the side is opposite, and the time range overlaps, and if so then output the crossed size. Expected result for these table would be:
ric a can cross 90 shares, ric b can cross all 1000, and ric c cannot cross.
Is this better achieved with a window join using the time frames? What I was imagining as the most intuitive approach was to find a way to break t1 into a list of rows and pass each row into a function to query t2, but open to suggestions if that's inefficient.
EDIT: For more context, I'm essentially trying to come up with a faux-matching engine for these tables. Window join is starting to look like the better option than breaking one of the tables with an iterator, but I'm unfamiliar with using window join with 2 time ranges and filters for opposing buy/sell and size (although the filters could come after the fact if that data is retained after the join?)