Last active
December 10, 2015 03:18
-
-
Save prystupa/4373952 to your computer and use it in GitHub Desktop.
Order trait with crossesAt and decreasedBy interface and implementation in LimitOrder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait OrderType { | |
def bookDisplay: String | |
def price: PriceLevel | |
def crossesAt(price: Double): Boolean | |
def decreasedBy(qty: Double): Order | |
} | |
object OrderType { | |
def all(): PartialFunction[Order, OrderType] = { | |
case self@LimitOrder(_, side, _, limit) => new OrderType { | |
def bookDisplay: String = limit.toString | |
def price: PriceLevel = LimitPrice(limit) | |
def crossesAt(price: Double): Boolean = side match { | |
case Buy => price <= limit | |
case Sell => price >= limit | |
} | |
def decreasedBy(qty: Double): LimitOrder = | |
self.copy(qty = self.qty - qty) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment