types: add bestBidAndAsk method

This commit is contained in:
c9s 2021-06-07 01:01:14 +08:00
parent e8205556ff
commit f20e809940

View File

@ -59,6 +59,16 @@ func (b *MutexOrderBook) IsValid() (ok bool, err error) {
return ok, err return ok, err
} }
func (b *MutexOrderBook) BestBidAndAsk() (bid, ask PriceVolume, ok bool) {
var ok1, ok2 bool
b.Lock()
bid, ok1 = b.OrderBook.BestBid()
ask, ok2 = b.OrderBook.BestAsk()
ok = ok1 && ok2
b.Unlock()
return bid, ask, ok
}
func (b *MutexOrderBook) BestBid() (pv PriceVolume, ok bool) { func (b *MutexOrderBook) BestBid() (pv PriceVolume, ok bool) {
b.Lock() b.Lock()
pv, ok = b.OrderBook.BestBid() pv, ok = b.OrderBook.BestBid()