mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
activeOrderBook: use orderMap instead of orderStore
This commit is contained in:
parent
d14527b5cf
commit
f03ac52ce5
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/core"
|
||||
"github.com/c9s/bbgo/pkg/sigchan"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
@ -218,11 +217,10 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
|
|||
continue
|
||||
}
|
||||
|
||||
openOrderStore := core.NewOrderStore(symbol)
|
||||
openOrderStore.Add(openOrders...)
|
||||
orderMap := types.NewOrderMap(openOrders...)
|
||||
for _, o := range orders {
|
||||
// if it's not on the order book (open orders), we should remove it from our local side
|
||||
if !openOrderStore.Exists(o.OrderID) {
|
||||
if !orderMap.Exists(o.OrderID) {
|
||||
b.Remove(o)
|
||||
} else {
|
||||
leftOrders = append(leftOrders, o)
|
||||
|
|
|
@ -8,6 +8,14 @@ import (
|
|||
// OrderMap is used for storing orders by their order id
|
||||
type OrderMap map[uint64]Order
|
||||
|
||||
func NewOrderMap(os ...Order) OrderMap {
|
||||
m := OrderMap{}
|
||||
if len(os) > 0 {
|
||||
m.Add(os...)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m OrderMap) Backup() (orderForms []SubmitOrder) {
|
||||
for _, order := range m {
|
||||
orderForms = append(orderForms, order.Backup())
|
||||
|
@ -17,8 +25,10 @@ func (m OrderMap) Backup() (orderForms []SubmitOrder) {
|
|||
}
|
||||
|
||||
// Add the order the the map
|
||||
func (m OrderMap) Add(o Order) {
|
||||
func (m OrderMap) Add(os ...Order) {
|
||||
for _, o := range os {
|
||||
m[o.OrderID] = o
|
||||
}
|
||||
}
|
||||
|
||||
// Update only updates the order when the order ID exists in the map
|
||||
|
|
Loading…
Reference in New Issue
Block a user