mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +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
|
return orderForms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the order the the map
|
||||||
func (m OrderMap) Add(o Order) {
|
func (m OrderMap) Add(o Order) {
|
||||||
m[o.OrderID] = o
|
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) {
|
func (m OrderMap) Update(o Order) {
|
||||||
if _, ok := m[o.OrderID]; ok {
|
if _, ok := m[o.OrderID]; ok {
|
||||||
m[o.OrderID] = o
|
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) {
|
func (m OrderMap) Remove(orderID uint64) {
|
||||||
delete(m, orderID)
|
delete(m, orderID)
|
||||||
}
|
}
|
||||||
|
@ -153,6 +165,12 @@ func (m *SyncOrderMap) Exists(orderID uint64) (exists bool) {
|
||||||
return exists
|
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 {
|
func (m *SyncOrderMap) Len() int {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user