mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
bbgo: fix order update compare method
This commit is contained in:
parent
a118eab15e
commit
86360a7595
|
@ -336,7 +336,7 @@ func (b *ActiveOrderBook) Update(order types.Order) {
|
||||||
// if we can't detect which is newer, isNewerOrderUpdate returns false
|
// if we can't detect which is newer, isNewerOrderUpdate returns false
|
||||||
// if you pass two same objects to isNewerOrderUpdate, it returns false
|
// if you pass two same objects to isNewerOrderUpdate, it returns false
|
||||||
if !isNewerOrderUpdate(order, previousOrder) {
|
if !isNewerOrderUpdate(order, previousOrder) {
|
||||||
log.Infof("[ActiveOrderBook] order #%d updateTime %s is out of date, skip it", order.OrderID, order.UpdateTime)
|
log.Infof("[ActiveOrderBook] order #%d (update time %s) is out of date, skip it", order.OrderID, order.UpdateTime)
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -393,26 +393,33 @@ func (b *ActiveOrderBook) Add(orders ...types.Order) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isNewerOrderUpdate checks if the order a is newer than the order b.
|
||||||
func isNewerOrderUpdate(a, b types.Order) bool {
|
func isNewerOrderUpdate(a, b types.Order) bool {
|
||||||
// compare state first
|
// compare state first
|
||||||
switch a.Status {
|
switch a.Status {
|
||||||
|
|
||||||
case types.OrderStatusCanceled, types.OrderStatusRejected: // canceled is a final state
|
case types.OrderStatusCanceled, types.OrderStatusRejected: // canceled is a final state
|
||||||
switch b.Status {
|
switch b.Status {
|
||||||
case types.OrderStatusNew, types.OrderStatusPartiallyFilled:
|
|
||||||
|
case types.OrderStatusCanceled, types.OrderStatusRejected, types.OrderStatusNew, types.OrderStatusPartiallyFilled:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
case types.OrderStatusPartiallyFilled:
|
case types.OrderStatusPartiallyFilled:
|
||||||
switch b.Status {
|
switch b.Status {
|
||||||
|
|
||||||
case types.OrderStatusNew:
|
case types.OrderStatusNew:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case types.OrderStatusPartiallyFilled:
|
case types.OrderStatusPartiallyFilled:
|
||||||
// unknown for equal
|
// unknown for equal
|
||||||
if a.ExecutedQuantity.Compare(b.ExecutedQuantity) > 0 {
|
if a.ExecutedQuantity.Compare(b.ExecutedQuantity) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.UpdateTime.After(b.UpdateTime.Time()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case types.OrderStatusFilled:
|
case types.OrderStatusFilled:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user