It doesn't have to be arbitrary machine code. eBPF / WASM coupled with a standard library supplied by the exchange. (Plus the exchange can run it in a VM.)
> Also if two people want to make the same trade, who gets it?
Whoever pays more currently, right? So it can be uniform random and folks can pay for better than random chance, etc.