private boolean trySharesToPurchase( BuyOrder aBuyOrder, int aTotalQuantityAvailable) { try { aBuyOrder.sharesToPurchase(aTotalQuantityAvailable); this.buyOrderRepository().save(aBuyOrder); return true; } catch (Exception e) { return false; } }
@Override public String toString() { return "PurchaseExecution [openDate=" + this.openDate() + ", filledDate=" + this.filledDate() + ", quantityOfSharesOrdered=" + this.quantityOfSharesOrdered() + ", quantityOfSharesOutstanding=" + this.quantityOfSharesOutstanding() + "]"; }
public int quantityOfSharesOrdered() { return this.execution().quantityOfSharesOrdered(); }
public void testSaveWithOverwrite() throws Exception { BuyOrder buyOrder = this.buyOrderFixture1(); this.repository.save(buyOrder); assertTrue(buyOrder.isOpen()); assertFalse(buyOrder.isFilled()); BuyOrder changedBuyOrder = this.repository.orderOf(buyOrder.orderId()); changedBuyOrder.sharesToPurchase(changedBuyOrder.execution().quantityOfSharesOrdered()); this.repository.save(changedBuyOrder); changedBuyOrder = this.repository.orderOf(buyOrder.orderId()); assertNotNull(changedBuyOrder.holdingOfFilledOrder()); assertFalse(buyOrder.isOpen()); assertTrue(buyOrder.isFilled()); }
public void testOpenExecution() throws Exception { PurchaseExecution purchaseExecution = new PurchaseExecution(20); assertEquals(20, purchaseExecution.quantityOfSharesOrdered()); assertEquals(20, purchaseExecution.quantityOfSharesOutstanding()); assertNull(purchaseExecution.filledDate()); assertNotNull(purchaseExecution.openDate()); Calendar openDate = Calendar.getInstance(); openDate.setTime(purchaseExecution.openDate()); assertEquals(Calendar.getInstance().get(Calendar.MONTH), openDate.get(Calendar.MONTH)); assertEquals(Calendar.getInstance().get(Calendar.DATE), openDate.get(Calendar.DATE)); assertEquals(Calendar.getInstance().get(Calendar.YEAR), openDate.get(Calendar.YEAR)); }
public void testRemove() throws Exception { BuyOrder buyOrder = this.buyOrderFixture1(); this.repository.save(buyOrder); BuyOrder foundOrder = this.repository.orderOf(buyOrder.orderId()); assertEquals(buyOrder, foundOrder); this.repository.remove(buyOrder); foundOrder = this.repository.orderOf(buyOrder.orderId()); assertNull(foundOrder); }
@Override public boolean equals(Object anObject) { boolean equalObjects = false; if (anObject != null && this.getClass() == anObject.getClass()) { BuyOrder typedObject = (BuyOrder) anObject; equalObjects = this.accountId().equals(typedObject.accountId()) && this.orderId().equals(typedObject.orderId()); } return equalObjects; }
public void testNoNegativeQuantities() throws Exception { try { new PurchaseExecution(-20); fail("Should not allow negative order quantity."); } catch (Exception e) { // success } try { PurchaseExecution purchaseExecution = new PurchaseExecution(10); purchaseExecution.withPurchasedSharesOf(11); fail("Should not allow overrun purchase execution."); } catch (Exception e) { // success } }
public int quantityOfOutstandingShares() { return this.execution().quantityOfSharesOutstanding(); }
@Override public void handleEvent(BuyOrderSharePurchaseRequested aDomainEvent) { buyOrderSharesToPurchase = aDomainEvent; quantityOfSharesToPurchase += aDomainEvent.quantityOfShares(); }
public boolean wouldOverrunExecutionWith(int aQuantityOfShares) { int adjustedQuantity = this.quantityOfSharesOutstanding() - aQuantityOfShares; return adjustedQuantity < 0; }
public OrderId(String anId) { super(); this.setId(anId); }
public boolean isFilled() { return this.filledDate() != null; }
public boolean isOpen() { return !this.isFilled(); }