mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
types: implement lookup method
This commit is contained in:
parent
bbe58f51cf
commit
130cf2468d
|
@ -16,17 +16,29 @@ func (m OrderMap) Backup() (orderForms []SubmitOrder) {
|
|||
return orderForms
|
||||
}
|
||||
|
||||
// Add the order the the map
|
||||
func (m OrderMap) Add(o Order) {
|
||||
m[o.OrderID] = o
|
||||
}
|
||||
|
||||
// Update only updates the order when the order exists in the map
|
||||
// Update only updates the order when the order ID exists in the map
|
||||
func (m OrderMap) Update(o Order) {
|
||||
if _, ok := m[o.OrderID]; ok {
|
||||
m[o.OrderID] = o
|
||||
}
|
||||
}
|
||||
|
||||
func (m OrderMap) Lookup(f func(o Order) bool) *Order {
|
||||
for _, order := range m {
|
||||
if f(order) {
|
||||
// copy and return
|
||||
o := order
|
||||
return &o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m OrderMap) Remove(orderID uint64) {
|
||||
delete(m, orderID)
|
||||
}
|
||||
|
@ -153,6 +165,12 @@ func (m *SyncOrderMap) Exists(orderID uint64) (exists bool) {
|
|||
return exists
|
||||
}
|
||||
|
||||
func (m *SyncOrderMap) Lookup(f func(o Order) bool) *Order {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
return m.orders.Lookup(f)
|
||||
}
|
||||
|
||||
func (m *SyncOrderMap) Len() int {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user