public boolean hasTickerSymbol(TickerSymbol aTickerSymbol) { return this.quote().hasTickerSymbol(aTickerSymbol); }
public Money valueOfOrderedShares() { return this.quote().valueOfPricedShares(this.quantityOfSharesOrdered()); }
public Holding holdingOfFilledOrder() { if (!this.isFilled()) { throw new IllegalStateException("Order must be filled before Holding can be queried."); } Holding holding = this.holding; if (holding == null) { int sharesOrdered = this.execution().quantityOfSharesOrdered(); Money totalValue = this.quote().valueOfPricedShares(sharesOrdered); holding = new Holding( this.accountId(), this.orderId(), this.quote().tickerSymbol(), sharesOrdered, totalValue, this.execution().filledDate()); this.setHolding(holding); } return holding; }
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())); } } } } }
public BuyOrder( AccountId anAccountId, Quote aQuote, int aQuantityOfSharesOrdered, Money anOrderFee) { super(); this.setAccountId(anAccountId); this.setExecution(new PurchaseExecution(aQuantityOfSharesOrdered)); this.setOrderId(OrderId.unique()); this.setQuote(aQuote); DomainEventPublisher.instance().publish( new BuyOrderPlaced( this.accountId(), this.orderId(), this.quote(), this.execution().quantityOfSharesOrdered(), this.execution().openDate(), aQuote.price().multipliedBy(aQuantityOfSharesOrdered), anOrderFee)); }
public void testBuyOrderCreation() throws Exception { DomainEventPublisher.instance().subscribe(new DomainEventSubscriber<BuyOrderPlaced>() { @Override public void handleEvent(BuyOrderPlaced aDomainEvent) { buyOrderPlaced = aDomainEvent; } @Override public Class<BuyOrderPlaced> subscribedToEventType() { return BuyOrderPlaced.class; } }); BuyOrder buyOrder = this.buyOrderFixture(); assertNotNull(buyOrderPlaced); assertNotNull(buyOrder.accountId()); assertNotNull(buyOrder.execution()); assertFalse(buyOrder.isFilled()); assertTrue(buyOrder.isOpen()); assertEquals(NUMBER_OF_SHARES, buyOrder.quantityOfSharesOrdered()); assertNotNull(buyOrder.quote()); assertEquals(TICKER, buyOrder.quote().tickerSymbol().symbol()); assertEquals(PRICE, buyOrder.quote().price()); assertEquals(PRICE.multipliedBy(NUMBER_OF_SHARES), buyOrder.valueOfOrderedShares()); try { buyOrder.holdingOfFilledOrder(); fail("Holding must not have been created yet."); } catch (Exception e) { // success } }
public void testPlaceBuyOrder() throws Exception { Money money = new Money("10000.00"); Account account = this.profileFixture().openAccount(money); Money orderFee = new Money("9.99"); Money price = new Money("723.25"); int shares = 10; TickerSymbol tickerSymbol = new TickerSymbol("GOOG"); BuyOrder buyOrder = account.placeBuyOrder(tickerSymbol, price, shares, orderFee); assertEquals(account.accountId(), buyOrder.accountId()); assertEquals(tickerSymbol, buyOrder.quote().tickerSymbol()); assertEquals(price, buyOrder.quote().price()); assertEquals(shares, buyOrder.quantityOfSharesOrdered()); assertEquals(shares, buyOrder.execution().quantityOfSharesOrdered()); assertEquals(shares, buyOrder.execution().quantityOfSharesOutstanding()); }
public void testHoldingAfterFill() throws Exception { BuyOrder buyOrder = this.buyOrderFixture(); assertTrue(buyOrder.isOpen()); assertFalse(buyOrder.isFilled()); buyOrder.sharesToPurchase(buyOrder.execution().quantityOfSharesOrdered()); try { Holding holding = buyOrder.holdingOfFilledOrder(); assertNotNull(holding); assertEquals(buyOrder.accountId(), holding.accountId()); assertEquals(buyOrder.holdingOfFilledOrder().acquiredOn(), holding.acquiredOn()); assertEquals(buyOrder.orderId(), holding.orderId()); assertEquals(buyOrder.quantityOfSharesOrdered(), holding.numberOfShares()); assertEquals(buyOrder.quote().tickerSymbol(), holding.tickerSymbol()); assertEquals(buyOrder.quote().price().multipliedBy(buyOrder.quantityOfSharesOrdered()), holding.totalValue()); } catch (Exception e) { fail("Holding should be available with filled order."); } }
public void testFillBuyOrder() throws Exception { DomainEventPublisher.instance().subscribe(new DomainEventSubscriber<BuyOrderFilled>() { @Override public void handleEvent(BuyOrderFilled aDomainEvent) { buyOrderFilled = aDomainEvent; } @Override public Class<BuyOrderFilled> subscribedToEventType() { return BuyOrderFilled.class; } }); BuyOrder buyOrder = this.buyOrderFixture(); // event published here buyOrder.sharesToPurchase(NUMBER_OF_SHARES); assertNotNull(buyOrderFilled); assertTrue(buyOrder.isFilled()); assertFalse(buyOrder.isOpen()); Holding holding = null; try { holding = buyOrder.holdingOfFilledOrder(); assertEquals(buyOrder.accountId(), holding.accountId()); assertEquals(buyOrder.holdingOfFilledOrder().acquiredOn(), holding.acquiredOn()); assertEquals(buyOrder.orderId(), holding.orderId()); assertEquals(buyOrder.quantityOfSharesOrdered(), holding.numberOfShares()); assertEquals(buyOrder.quote().tickerSymbol(), holding.tickerSymbol()); assertEquals(buyOrder.quote().price().multipliedBy(buyOrder.quantityOfSharesOrdered()), holding.totalValue()); } catch (Exception e) { fail("Holding should be available with filled order."); } }
public void testPlaceBuyOrder() throws Exception { DomainEventPublisher.instance().subscribe(new DomainEventSubscriber<BuyOrderPlaced>() { @Override public void handleEvent(BuyOrderPlaced aDomainEvent) { buyOrderPlaced = aDomainEvent; } @Override public Class<BuyOrderPlaced> subscribedToEventType() { return BuyOrderPlaced.class; } }); BuyOrder buyOrder = this.buyOrderFixture(); // event published here assertNotNull(buyOrderPlaced); assertEquals(new Money("9.99"), buyOrderPlaced.orderFee()); assertEquals(NUMBER_OF_SHARES, buyOrderPlaced.quantityOfSharesOrdered()); assertEquals(PRICE, buyOrderPlaced.quote().price()); assertEquals(TICKER, buyOrderPlaced.quote().tickerSymbol().symbol()); assertEquals(PRICE.multipliedBy(NUMBER_OF_SHARES), buyOrder.valueOfOrderedShares()); assertEquals(buyOrder.accountId(), buyOrderPlaced.accountId()); assertEquals(buyOrder.orderId(), buyOrderPlaced.orderId()); assertEquals(buyOrder.quantityOfSharesOrdered(), buyOrderPlaced.quantityOfSharesOrdered()); assertEquals(buyOrder.quote(), buyOrderPlaced.quote()); }