public void testOpenOrdersOf() throws Exception { this.repository.save(this.buyOrderFixture1()); this.repository.save(this.buyOrderFixture2()); this.repository.save(this.buyOrderFixture3()); Collection<BuyOrder> foundOrders = this.repository.openOrdersOf(this.googTickerFixture()); assertNotNull(foundOrders); assertFalse(foundOrders.isEmpty()); assertEquals(2, foundOrders.size()); }
public void testSave() throws Exception { List<OrderId> ids = new ArrayList<OrderId>(); for (int idx = 0; idx < 10; ++idx) { BuyOrder order = this.buyOrderFixture1(); this.repository.save(order); ids.add(order.orderId()); } for (int idx = 0; idx < 10; ++idx) { BuyOrder order = this.repository.orderOf(ids.get(idx)); assertNotNull(order); } }
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); }
private boolean trySharesToPurchase( BuyOrder aBuyOrder, int aTotalQuantityAvailable) { try { aBuyOrder.sharesToPurchase(aTotalQuantityAvailable); this.buyOrderRepository().save(aBuyOrder); return true; } catch (Exception e) { return false; } }
public void fillMarketOrdersUsing(QuoteBar aQuoteBar) { TickerSymbol tickerSymbol = new TickerSymbol(aQuoteBar.symbol()); int totalQuantityAvailable = aQuoteBar .totalQuantity() .toBigInteger() .intValue(); Collection<BuyOrder> openOrders = this.buyOrderRepository().openOrdersOf(tickerSymbol); this.marketFillService().fillMarketBuyOrders(openOrders, totalQuantityAvailable); }
public void fillMarketBuyOrders( Collection<BuyOrder> anOpenBuyOrders, int aTotalQuantityAvailable) { BuyOrderSharePurchaseRequestedSubscriber subscriber = new BuyOrderSharePurchaseRequestedSubscriber(); DomainEventPublisher.instance().subscribe(subscriber); Iterator<BuyOrder> iterator = anOpenBuyOrders.iterator(); while (iterator.hasNext() && aTotalQuantityAvailable > 0) { BuyOrder buyOrder = iterator.next(); boolean done = false; for (int tries = 0; !done && tries < 3; ++tries) { subscriber.clear(); if (this.trySharesToPurchase(buyOrder, aTotalQuantityAvailable)) { aTotalQuantityAvailable -= subscriber.orderSharesRequested(); done = true; } else { buyOrder = this.buyOrderRepository().orderOf(buyOrder.orderId()); } } } }
public void testUnmatchedFillMarketOrders() throws Exception { BuyOrder[] buyOrders = this.buyOrderFixture(); for (BuyOrder buyOrder : buyOrders) { this.buyOrderRepository.save(buyOrder); } QuoteBar quoteBar = this.quoteBarUnmatchedFixture(); TickerSymbol tickerSymbol = new TickerSymbol(quoteBar.symbol()); int totalQuantityAvailable = quoteBar .totalQuantity() .toBigInteger() .intValue(); Collection<BuyOrder> openOrders = this.buyOrderRepository.openOrdersOf(tickerSymbol); MarketFillService marketFillService = new MarketFillService(this.buyOrderRepository); marketFillService.fillMarketBuyOrders(openOrders, totalQuantityAvailable); int stillOpenCount = 0; for (BuyOrder previouslyOpenOrder : buyOrders) { assertFalse(previouslyOpenOrder.isFilled()); assertTrue(previouslyOpenOrder.isOpen()); ++stillOpenCount; } assertEquals(buyOrders.length, stillOpenCount); }
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()); }
this.buyOrderRepository.save(buyOrder); this.buyOrderRepository.openOrdersOf(tickerSymbol);