Created
April 29, 2012 17:42
-
-
Save michaeldiamant/2552179 to your computer and use it in GitHub Desktop.
Java style order resolution
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 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