public List<Lot> buy(String symbol, BigDecimal quantity, BigDecimal pricePaidPerShare) {
// Make sure placeOrder() can get a market price for the symbol
marketDataService.updateMarketPrice(
new MarketPrice(symbol, new Money("10"), new DateTime()));
// Place the order
OrderParams orderParams = new OrderParams(
OrderSide.Buy,
symbol,
quantity,
OrderType.Market,
null,
OrderTerm.GoodTilCanceled,
false);
Long orderId = this.brokerageAccountService.placeOrder(
USERNAME1, brokerageAccount1Id, orderParams);
Order order = this.brokerageAccountService.findOrder(orderId);
// Acknowledge the order
ExecutionReport executionReport = ExecutionReport.createNewType(order);
this.brokerageAccountService.processExecutionReport(executionReport);
// Execute the trade
executionReport = ExecutionReport.createTradeType(
order,
OrderStatus.Filled,
new DecimalQuantity(quantity),
new Money(pricePaidPerShare));
this.brokerageAccountService.processExecutionReport(executionReport);
List<Lot> lots =
this.brokerageAccountService.findActiveLots(brokerageAccount1Id);
Collections.sort(lots, new Lot.CreationTimeComparator());