betcode-org/flumine

Simulation does not process fill or kill orders correctly

Closed this issue · 3 comments

mzaja commented

Simulation does not correctly process orders where time_in_force is specified (currently it can only be "FILL_OK_KILL") and treats them as regular orders. For example:

order = trade.create_order(side="BACK", order_type=LimitOrder(back_price, 1, time_in_force="FILL_OR_KILL", min_fill_size=2))

Implementing this should not be too difficult given that the simulation engine already supports order matching and order cancellation. The algorithm would work something like this:

if order_landed_in_market:
    if (side == "BACK") and (price_requested <= best_available_back_price) and (min_fill_size > size_available_at_price_requested_and_above):
        # Match the order
    elif (side == "LAY") and (price_requested >= best_available_lay_price) and (min_fill_size > size_available_at_price_requested_and_below):
        # Match the order
    else:
        # Cancel the order immediately

Since the cancellation is done on Betfair's side, it should be instantanoues and without delay.

This was tricky, did not enjoy it.

mzaja commented

This was tricky, did not enjoy it.

Wow, that was very quick, awesome work! Which part did you find difficult?

Keeping it simple, let me know if you encounter any issues but fairly confident in the implementation