Last active
December 11, 2015 00:58
-
-
Save prystupa/4519700 to your computer and use it in GitHub Desktop.
OrderBook with logic to reject pegged order when no best limit
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
class OrderBook(side: Side, orderTypes: (Order => OrderType)) | |
extends mutable.Publisher[OrderBookEvent] { | |
private case class OrdersAtLimit(limit: Double, orders: FastList[Order]) | |
private case class OrderLocation(list: FastList.Entry[OrdersAtLimit], entry: FastList.Entry[Order]) | |
private val marketBook: FastList[Order] = FastList() | |
private val limitBook = FastList[OrdersAtLimit]() | |
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse | |
private var pegs: FastList[OrderLocation] = FastList() | |
def add(order: Order) { | |
orderTypes(order).price match { | |
case MarketPrice => marketBook.append(order) | |
case LimitPrice(limit) => addLimit(limit, order) | |
case PegPrice => addPeg(order, isNewOrder = true) | |
} | |
} | |
private def addPeg(order: Order) { | |
bestLimit match { | |
case Some(limit) => ??? | |
case None => publish(RejectedOrder(order)) | |
} | |
} | |
// the rest of the implementation is omitted | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment