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