diff --git a/.gitignore b/.gitignore index 34051dcda..1b3b385e6 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ otp*png /.deploy *.swp +/pkg/backtest/assets.go diff --git a/pkg/backtest/matching.go b/pkg/backtest/matching.go index 54bf9c86c..e31112245 100644 --- a/pkg/backtest/matching.go +++ b/pkg/backtest/matching.go @@ -148,17 +148,21 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (closedOrders *typ if o.Type == types.OrderTypeMarket { m.EmitOrderUpdate(order) + // copy the order object to avoid side effect (for different callbacks) + var order2 = order + // emit trade before we publish order - trade := m.newTradeFromOrder(&order, false) + trade := m.newTradeFromOrder(&order2, false) m.executeTrade(trade) // update the order status - order.Status = types.OrderStatusFilled - order.ExecutedQuantity = order.Quantity - order.Price = price - order.IsWorking = false - m.EmitOrderUpdate(order) - return &order, &trade, nil + order2.Status = types.OrderStatusFilled + order2.ExecutedQuantity = order2.Quantity + order2.Price = price + order2.IsWorking = false + m.EmitOrderUpdate(order2) + + return &order2, &trade, nil } // for limit maker orders