Created
June 8, 2012 00:56
-
-
Save michaeldiamant/2892756 to your computer and use it in GitHub Desktop.
Extensible trade execution processor
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 ExtensibleTradeExecutionProcessor extends TradeExecutionProcessor { | |
val requestedTradeRepository: RequestedTradeRepository | |
val priceMutators: Set[(RequestedTrade, BigDecimal) => BigDecimal] | |
def process(requestId: String, executionPrice: BigDecimal): Option[ExecutedTrade] = | |
for { | |
requestedTrade <- requestedTradeRepository.findById(requestId) | |
reportedPrice <- priceMutators.foldLeft(executionPrice)((price, mutator) => mutator(requestedTrade, price)).some | |
} yield | |
ExecutedTrade( | |
requestId = requestedTrade.id, | |
executedPrice = executionPrice, | |
reportedPrice = reportedPrice | |
) | |
} | |
trait PriceMutators extends MarkupApplicator { | |
val markingUpSymbol: String | |
val symbolMarkup: BigDecimal | |
val markupVolumeThreshold: Long | |
val volumeMarkup: BigDecimal | |
def symbolBasedPriceMutator(trade: RequestedTrade, executionPrice: BigDecimal): BigDecimal = | |
(trade.symbol == markingUpSymbol) | |
.option(addMarkup(trade.side, executionPrice, symbolMarkup)) | |
.getOrElse(executionPrice) | |
def volumeThresholdPriceMutator(trade: RequestedTrade, executionPrice: BigDecimal): BigDecimal = | |
(trade.volume <= markupVolumeThreshold) | |
.option(addMarkup(trade.side, executionPrice, volumeMarkup)) | |
.getOrElse(executionPrice) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment