mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #484 from ankion/fix_backtest_orderbook
This commit is contained in:
commit
bc0429c0fd
|
@ -286,13 +286,6 @@ func (m *SimplePriceMatching) BuyToPrice(price fixedpoint.Value) (closedOrders [
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, false)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
|
|
||||||
case types.OrderTypeStopLimit:
|
case types.OrderTypeStopLimit:
|
||||||
// should we trigger the order?
|
// should we trigger the order?
|
||||||
if price.Compare(o.StopPrice) <= 0 {
|
if price.Compare(o.StopPrice) <= 0 {
|
||||||
|
@ -307,13 +300,6 @@ func (m *SimplePriceMatching) BuyToPrice(price fixedpoint.Value) (closedOrders [
|
||||||
o.ExecutedQuantity = o.Quantity
|
o.ExecutedQuantity = o.Quantity
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, false)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
} else {
|
} else {
|
||||||
// maker order
|
// maker order
|
||||||
askOrders = append(askOrders, o)
|
askOrders = append(askOrders, o)
|
||||||
|
@ -324,13 +310,6 @@ func (m *SimplePriceMatching) BuyToPrice(price fixedpoint.Value) (closedOrders [
|
||||||
o.ExecutedQuantity = o.Quantity
|
o.ExecutedQuantity = o.Quantity
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, true)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
} else {
|
} else {
|
||||||
askOrders = append(askOrders, o)
|
askOrders = append(askOrders, o)
|
||||||
}
|
}
|
||||||
|
@ -344,6 +323,15 @@ func (m *SimplePriceMatching) BuyToPrice(price fixedpoint.Value) (closedOrders [
|
||||||
m.askOrders = askOrders
|
m.askOrders = askOrders
|
||||||
m.LastPrice = price
|
m.LastPrice = price
|
||||||
|
|
||||||
|
for _, o := range closedOrders {
|
||||||
|
trade := m.newTradeFromOrder(o, true)
|
||||||
|
m.executeTrade(trade)
|
||||||
|
|
||||||
|
trades = append(trades, trade)
|
||||||
|
|
||||||
|
m.EmitOrderUpdate(o)
|
||||||
|
}
|
||||||
|
|
||||||
return closedOrders, trades
|
return closedOrders, trades
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,13 +348,6 @@ func (m *SimplePriceMatching) SellToPrice(price fixedpoint.Value) (closedOrders
|
||||||
o.Price = sellPrice
|
o.Price = sellPrice
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, false)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
} else {
|
} else {
|
||||||
bidOrders = append(bidOrders, o)
|
bidOrders = append(bidOrders, o)
|
||||||
}
|
}
|
||||||
|
@ -380,13 +361,6 @@ func (m *SimplePriceMatching) SellToPrice(price fixedpoint.Value) (closedOrders
|
||||||
o.ExecutedQuantity = o.Quantity
|
o.ExecutedQuantity = o.Quantity
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, false)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bidOrders = append(bidOrders, o)
|
bidOrders = append(bidOrders, o)
|
||||||
}
|
}
|
||||||
|
@ -399,13 +373,6 @@ func (m *SimplePriceMatching) SellToPrice(price fixedpoint.Value) (closedOrders
|
||||||
o.ExecutedQuantity = o.Quantity
|
o.ExecutedQuantity = o.Quantity
|
||||||
o.Status = types.OrderStatusFilled
|
o.Status = types.OrderStatusFilled
|
||||||
closedOrders = append(closedOrders, o)
|
closedOrders = append(closedOrders, o)
|
||||||
|
|
||||||
trade := m.newTradeFromOrder(o, true)
|
|
||||||
m.executeTrade(trade)
|
|
||||||
|
|
||||||
trades = append(trades, trade)
|
|
||||||
|
|
||||||
m.EmitOrderUpdate(o)
|
|
||||||
} else {
|
} else {
|
||||||
bidOrders = append(bidOrders, o)
|
bidOrders = append(bidOrders, o)
|
||||||
}
|
}
|
||||||
|
@ -418,6 +385,15 @@ func (m *SimplePriceMatching) SellToPrice(price fixedpoint.Value) (closedOrders
|
||||||
m.bidOrders = bidOrders
|
m.bidOrders = bidOrders
|
||||||
m.LastPrice = price
|
m.LastPrice = price
|
||||||
|
|
||||||
|
for _, o := range closedOrders {
|
||||||
|
trade := m.newTradeFromOrder(o, true)
|
||||||
|
m.executeTrade(trade)
|
||||||
|
|
||||||
|
trades = append(trades, trade)
|
||||||
|
|
||||||
|
m.EmitOrderUpdate(o)
|
||||||
|
}
|
||||||
|
|
||||||
return closedOrders, trades
|
return closedOrders, trades
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user