func (m *M) fillableBuy(b *pqueue.OrderNode, q *pqueue.MatchQueues) bool { for { s := q.PeekSell() if s == nil { return false } if b.Price() >= s.Price() { if b.Amount() > s.Amount() { amount := s.Amount() price := price(b.Price(), s.Price()) m.slab.Free(q.PopSell()) b.ReduceAmount(amount) completeTrade(m.Out, msg.PARTIAL, msg.FULL, b, s, price, amount) continue } if s.Amount() > b.Amount() { amount := b.Amount() price := price(b.Price(), s.Price()) s.ReduceAmount(amount) completeTrade(m.Out, msg.FULL, msg.PARTIAL, b, s, price, amount) m.slab.Free(b) return true // The buy has been used up } if s.Amount() == b.Amount() { amount := b.Amount() price := price(b.Price(), s.Price()) completeTrade(m.Out, msg.FULL, msg.FULL, b, s, price, amount) m.slab.Free(q.PopSell()) m.slab.Free(b) return true // The buy has been used up } } else { return false } } panic("Unreachable") }