Last active
December 11, 2015 00:39
-
-
Save prystupa/4518408 to your computer and use it in GitHub Desktop.
OrderType registry with pegged order partial function added
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
object OrderType { | |
def all(buy: => OrderBook, sell: => OrderBook): PartialFunction[Order, OrderType] = { | |
// omitted [unmodified] order type definitions for limit and market orders | |
// ... | |
case self@PegOrder(_, side, _) => new OrderType { | |
private lazy val book = side match { | |
case Buy => buy | |
case Sell => sell | |
} | |
def bookDisplay: String = s"Peg($bestLimit)" | |
def price: PriceLevel = PegPrice | |
def crossesAt(price: Double): Boolean = side match { | |
case Buy => price <= bestLimit | |
case Sell => price >= bestLimit | |
} | |
def decreasedBy(qty: Double): Order = self.copy(qty = self.qty - qty) | |
private def bestLimit = | |
book.bestLimit.getOrElse(throw new IllegalStateException("Pegged orders are illegal in a book with no best limit defined")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment