public void sharesToPurchase(int aQuantityOfSharesAvailable) {
if (this.execution().quantityOfSharesOutstanding() > 0) {
if (aQuantityOfSharesAvailable > 0) {
int quantityToPurchase =
Math.min(
this.execution().quantityOfSharesOutstanding(),
aQuantityOfSharesAvailable);
if (quantityToPurchase > 0) {
DomainEventPublisher.instance().publish(
new BuyOrderSharePurchaseRequested(
this.accountId(),
this.orderId(),
this.quote(),
quantityToPurchase));
this.setExecution(
this.execution()
.withPurchasedSharesOf(quantityToPurchase));
if (this.isFilled()) {
DomainEventPublisher.instance().publish(
new BuyOrderFilled(
this.accountId(),
this.orderId(),
this.quote(),
this.execution().quantityOfSharesOrdered(),
this.holdingOfFilledOrder()));
}
}
}
}
}