I have a class that mixes in a number of different traits the encode behavior for matching orders given various available order types. The class definition looks as follows...
class DoubleAuctionMarket(val security: Security) extends EventBus {
this: MatchingEngine =>
The relevant parts of the base MatchingEngine
trait look as follows...
trait MatchingEngine {
/** Implements crossing logic for various types of orders. */
def crosses(incoming: Order, top: Order): Boolean
/** Implements price formation rules for various types of orders. */
def formPrice(incoming: Order, top: Order): Double
}
I have another trait called LimitOrderOnlyMatchingEngine
that extends the base trait as follows...
trait LimitOrderOnlyMatchingEngine extends MatchingEngine {
def crosses(incoming: LimitOrder, top: LimitOrder): Boolean = {
(incoming, top) match {
case (incoming: LimitOrderAsk, top: LimitOrderBid) =>
incoming.limit <= top.limit
case (incoming: LimitOrderBid, top: LimitOrderAsk) =>
incoming.limit >= top.limit
}
}
def formPrice(incoming: LimitOrder, top: LimitOrder): Double = top.limit
}
Now, when I try to mix in the LimitOrderOnlyMatchingEngine
using
new DoubleAuctionMarket(security) with LimitOrderOnlyMatchingEngine
I am told that "object creation is impossible" because neither the crosses
method nor the formPrice
method have been implemented as required by the self type annotation I used.
Not sure what is going wrong. I suspect that either:
- I need to somehow override the relevant methods in the
LimitOrderOnlyMatchingEngine
or - I need to define the input types for those methods in the base class differently.
Thoughts?