agnostic-orderbook
agnostic-orderbook copied to clipboard
Add prune order function
~Still a work in progress, needs a test + some clean up. But the core logic is here.~
Let's say you have an order book you want to shut down. One option is to find all of the open order accounts, and then cancel all the open orders on that account. This requires writing a whole other crank, separate to whatever existing consume_events
crank someone already has. Instead the process can be simplified by removing all the orders from the order book and placing them as out_events
/cancelled orders on the event queue. This means it fits in with the existing consume_events
cranks someone might have.
prune_orders
args:
- number of orders to prune
function:
- iterates over all open orders on both sides of the order book
- removes the order
- adds an
out_event
for the cancelled order to the event queue
- has some checks so that it doesn't add more events to the event queue than it can fit
~@ellttBen Aside from adding pub mod prune_orders
to the process.rs
file, is there other structural code that's needed for a new function? e.g. does it need to have an entry added to process_instruction
in the same process.rs
file or is that just left over code from when the AOB processed instructions like a regular program?~ Looks like it is required for importing the functions to another program.
I've done some tests locally and it appears to work well. It will depend on each implementation's own use case at to what the number_of_orders_to_prune
argument should be set at. Presumably there will be a limit to the number of orders that can be processed in one block based on the compute unit usage but again this will vary. It should be very possible to prune a couple of hundred orders in 200k and even more if the extra compute is enabled and the limit goes up to 1.4m units.