mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add pending order test cases
This commit is contained in:
parent
10eba876c4
commit
4dc4f73834
|
@ -312,6 +312,8 @@ func (b *ActiveOrderBook) add(order types.Order) {
|
|||
} else {
|
||||
b.orders.Add(order)
|
||||
}
|
||||
|
||||
b.pendingOrderUpdates.Remove(order.OrderID)
|
||||
} else {
|
||||
b.orders.Add(order)
|
||||
}
|
||||
|
@ -321,6 +323,10 @@ func (b *ActiveOrderBook) Exists(order types.Order) bool {
|
|||
return b.orders.Exists(order.OrderID)
|
||||
}
|
||||
|
||||
func (b *ActiveOrderBook) Get(orderID uint64) (types.Order, bool) {
|
||||
return b.orders.Get(orderID)
|
||||
}
|
||||
|
||||
func (b *ActiveOrderBook) Remove(order types.Order) bool {
|
||||
return b.orders.Remove(order.OrderID)
|
||||
}
|
||||
|
|
57
pkg/bbgo/activeorderbook_test.go
Normal file
57
pkg/bbgo/activeorderbook_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package bbgo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func TestActiveOrderBook_pendingOrders(t *testing.T) {
|
||||
now := time.Now()
|
||||
ob := NewActiveOrderBook("")
|
||||
|
||||
// if we received filled order first
|
||||
// should be added to pending orders
|
||||
ob.orderUpdateHandler(types.Order{
|
||||
OrderID: 99,
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
Type: types.OrderTypeLimit,
|
||||
Quantity: number(0.01),
|
||||
Price: number(19000.0),
|
||||
AveragePrice: fixedpoint.Zero,
|
||||
StopPrice: fixedpoint.Zero,
|
||||
},
|
||||
Status: types.OrderStatusFilled,
|
||||
CreationTime: types.Time(now),
|
||||
UpdateTime: types.Time(now),
|
||||
})
|
||||
|
||||
assert.Len(t, ob.pendingOrderUpdates.Orders(), 1)
|
||||
|
||||
// should be added to pending orders
|
||||
ob.Add(types.Order{
|
||||
OrderID: 99,
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
Type: types.OrderTypeLimit,
|
||||
Quantity: number(0.01),
|
||||
Price: number(19000.0),
|
||||
AveragePrice: fixedpoint.Zero,
|
||||
StopPrice: fixedpoint.Zero,
|
||||
},
|
||||
Status: types.OrderStatusNew,
|
||||
CreationTime: types.Time(now),
|
||||
UpdateTime: types.Time(now.Add(-time.Second)),
|
||||
})
|
||||
|
||||
o99, ok := ob.Get(99)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, types.OrderStatusFilled, o99.Status)
|
||||
}
|
Loading…
Reference in New Issue
Block a user