Skip to content

Instantly share code, notes, and snippets.

@michaeldiamant
Created April 29, 2012 17:42
Embed
What would you like to do?
Java style order resolution
trait JavaStyleNewOrderResolver extends NewOrderResolutionErrors {
val symbolDao: SymbolDao
val marketTakerDao: MarketTakerDao
val marketMakerDao: MarketMakerDao
def resolve(order: NewOrder): Either[String, ResolvedNewOrder] = {
val symbol = symbolDao.findByName(order.symbolName)
if (symbol.isEmpty) {
return Left(UnknownSymbol)
}
val marketTaker = marketTakerDao.findByExternalId(order.marketTakerId)
if (marketTaker.isEmpty) {
return Left(UnknownMarketTakerId)
}
val account = marketTaker.get.accounts.find(_.id == order.accountId)
if (account.isEmpty) {
return Left(UnauthorizedAccount)
}
val marketMaker = marketMakerDao.findByExternalId(order.marketMakerId)
if (marketMaker.isEmpty) {
return Left(UnknownMarketMakerId)
}
if (!marketTaker.get.symbols.exists(_ == symbol.get)) {
return Left(UnauthorizedSymbol)
}
if (order.quantity <= 0) {
return Left(InvalidQuantity)
}
if (order.price <= 0) {
return Left(InvalidPrice)
}
Right(
ResolvedNewOrder(
account = account.get,
symbol = symbol.get,
marketMaker = marketMaker.get,
price = order.price,
quantity = order.quantity,
side = order.side
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment