mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
backtest: copy the order object for updating status
This commit is contained in:
parent
f65b343ea6
commit
cb4c879942
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -43,3 +43,4 @@ otp*png
|
||||||
/.deploy
|
/.deploy
|
||||||
|
|
||||||
*.swp
|
*.swp
|
||||||
|
/pkg/backtest/assets.go
|
||||||
|
|
|
@ -148,17 +148,21 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (closedOrders *typ
|
||||||
if o.Type == types.OrderTypeMarket {
|
if o.Type == types.OrderTypeMarket {
|
||||||
m.EmitOrderUpdate(order)
|
m.EmitOrderUpdate(order)
|
||||||
|
|
||||||
|
// copy the order object to avoid side effect (for different callbacks)
|
||||||
|
var order2 = order
|
||||||
|
|
||||||
// emit trade before we publish order
|
// emit trade before we publish order
|
||||||
trade := m.newTradeFromOrder(&order, false)
|
trade := m.newTradeFromOrder(&order2, false)
|
||||||
m.executeTrade(trade)
|
m.executeTrade(trade)
|
||||||
|
|
||||||
// update the order status
|
// update the order status
|
||||||
order.Status = types.OrderStatusFilled
|
order2.Status = types.OrderStatusFilled
|
||||||
order.ExecutedQuantity = order.Quantity
|
order2.ExecutedQuantity = order2.Quantity
|
||||||
order.Price = price
|
order2.Price = price
|
||||||
order.IsWorking = false
|
order2.IsWorking = false
|
||||||
m.EmitOrderUpdate(order)
|
m.EmitOrderUpdate(order2)
|
||||||
return &order, &trade, nil
|
|
||||||
|
return &order2, &trade, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// for limit maker orders
|
// for limit maker orders
|
||||||
|
|
Loading…
Reference in New Issue
Block a user