Skip to content

Instantly share code, notes, and snippets.

@prystupa
Last active December 11, 2015 00:39
Show Gist options
  • Save prystupa/4518408 to your computer and use it in GitHub Desktop.
Save prystupa/4518408 to your computer and use it in GitHub Desktop.
OrderType registry with pegged order partial function added
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