backtest: delay the order update after the balance unlock

This commit is contained in:
c9s 2022-08-18 15:43:09 +08:00
parent 3a24a48cde
commit bd8b362274
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -192,13 +192,6 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (*types.Order, *ty
trade := m.newTradeFromOrder(&order2, false, m.LastPrice)
m.executeTrade(trade)
// update the order status
order2.Status = types.OrderStatusFilled
order2.ExecutedQuantity = order2.Quantity
order2.IsWorking = false
m.EmitOrderUpdate(order2)
// unlock the rest balances for limit taker
if order.Type == types.OrderTypeLimit {
if order.AveragePrice.IsZero() {
@ -226,6 +219,12 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (*types.Order, *ty
}
}
// update the order status
order2.Status = types.OrderStatusFilled
order2.ExecutedQuantity = order2.Quantity
order2.IsWorking = false
m.EmitOrderUpdate(order2)
// let the exchange emit the "FILLED" order update (we need the closed order)
// m.EmitOrderUpdate(order2)
return &order2, &trade, nil