bbgo: fix pending order event trigger

This commit is contained in:
c9s 2023-02-23 21:46:57 +08:00
parent b666c8bf40
commit 7532c31631
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -12,8 +12,14 @@ import (
func TestActiveOrderBook_pendingOrders(t *testing.T) { func TestActiveOrderBook_pendingOrders(t *testing.T) {
now := time.Now() now := time.Now()
ob := NewActiveOrderBook("") ob := NewActiveOrderBook("")
filled := false
ob.OnFilled(func(o types.Order) {
filled = true
})
// if we received filled order first // if we received filled order first
// should be added to pending orders // should be added to pending orders
ob.orderUpdateHandler(types.Order{ ob.orderUpdateHandler(types.Order{
@ -34,6 +40,11 @@ func TestActiveOrderBook_pendingOrders(t *testing.T) {
assert.Len(t, ob.pendingOrderUpdates.Orders(), 1) assert.Len(t, ob.pendingOrderUpdates.Orders(), 1)
o99, ok := ob.pendingOrderUpdates.Get(99)
if assert.True(t, ok) {
assert.Equal(t, types.OrderStatusFilled, o99.Status)
}
// should be added to pending orders // should be added to pending orders
ob.Add(types.Order{ ob.Add(types.Order{
OrderID: 99, OrderID: 99,
@ -51,7 +62,6 @@ func TestActiveOrderBook_pendingOrders(t *testing.T) {
UpdateTime: types.Time(now.Add(-time.Second)), UpdateTime: types.Time(now.Add(-time.Second)),
}) })
o99, ok := ob.Get(99) assert.True(t, filled, "filled event should be fired")
assert.True(t, ok)
assert.Equal(t, types.OrderStatusFilled, o99.Status)
} }