betcode-org / flumine

flūmine - Betting trading framework
MIT License
171 stars 60 forks source link

Multiple orders for single trade simulation #354

Open joeledwardson opened 3 years ago

joeledwardson commented 3 years ago

I have come across an unusual bug: When backtesting, if a situation is created for a historical event where:

  1. Trade created, back Order created with trade
  2. back Order reaches EXECUTION_COMPLETE
  3. New Trade created, lay Order created with new trade
  4. lay Order reaches EXECUTION_COMPLETE

However, if this is exact same execution is modified so that in step 3. the lay Order is created with the same Trade used in step 1. for the back Order, then the lay Order never reaches EXECUTION_COMPLETE?

joeledwardson commented 3 years ago

I think I have found the bug: in FlumineBacktest._process_backtest_orders(), it has

            if order.trade.status.value == "Complete":
                blotter.complete_order(order)

However, if a Trade has one complete Order then its status will go to Complete, and only after a new Order has been placed will the Trade status go back to LIVE, at which point the blotter has already deemed the Order as Complete