private OrderDataBean getOrderDataFromResultSet(ResultSet rs) throws Exception { OrderDataBean orderData = null; orderData = new OrderDataBean(new Integer(rs.getInt("orderID")), rs.getString("orderType"), rs.getString("orderStatus"), rs.getTimestamp("openDate"), rs.getTimestamp("completionDate"), rs .getDouble("quantity"), rs.getBigDecimal("price"), rs.getBigDecimal("orderFee"), rs .getString("quote_symbol")); return orderData; }
public String toHTML() { return "<BR>Order <B>" + getOrderID() + "</B>" + "<LI> orderType: " + getOrderType() + "</LI>" + "<LI> orderStatus: " + getOrderStatus() + "</LI>" + "<LI> openDate: " + getOpenDate() + "</LI>" + "<LI> completionDate: " + getCompletionDate() + "</LI>" + "<LI> quantity: " + getQuantity() + "</LI>" + "<LI> price: " + getPrice() + "</LI>" + "<LI> orderFee: " + getOrderFee() + "</LI>" + "<LI> symbol: " + getSymbol() + "</LI>" ; }
public OrderDataBean(String orderType, String orderStatus, Date openDate, Date completionDate, double quantity, BigDecimal price, BigDecimal orderFee, AccountDataBean account, QuoteDataBean quote, HoldingDataBean holding) { setOrderType(orderType); setOrderStatus(orderStatus); setOpenDate(openDate); setCompletionDate(completionDate); setQuantity(quantity); setPrice(price); setOrderFee(orderFee); setAccount(account); setQuote(quote); setHolding(holding); }
public OrderDataBean(Integer orderID, String orderType, String orderStatus, Date openDate, Date completionDate, double quantity, BigDecimal price, BigDecimal orderFee, String symbol ) { setOrderID(orderID); setOrderType(orderType); setOrderStatus(orderStatus); setOpenDate(openDate); setCompletionDate(completionDate); setQuantity(quantity); setPrice(price); setOrderFee(orderFee); setSymbol(symbol); }
order.getQuote(); if (order.isCompleted()) { throw new RuntimeException("Error: attempt to complete Order that is already completed\n" + order); AccountDataBean account = order.getAccount(); QuoteDataBean quote = order.getQuote(); HoldingDataBean holding = order.getHolding(); BigDecimal price = order.getPrice(); double quantity = order.getQuantity(); + order.getOrderID() + "\n\t Order info: " + order + "\n\t Account info: " + account + "\n\t Quote info: " + quote + "\n\t Holding info: " + holding); if (order.isBuy()) { order.setHolding(newHolding); if (order.isSell()) { Log.error("TradeJPADirect:completeOrder -- Unable to sell order " + order.getOrderID() + " holding already sold"); order.cancel(); entityManager.getTransaction().commit(); return order; order.setHolding(null); order.setOrderStatus("closed");
+ " which has already been sold"); OrderDataBean orderData = new OrderDataBean(); orderData.setOrderStatus("cancelled"); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee); completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); order.cancel(); if (!(order.getOrderStatus().equalsIgnoreCase("cancelled"))) updateQuotePriceVolume(order.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), order.getQuantity());
String orderType = orderData.getOrderType(); String orderStatus = orderData.getOrderStatus(); int holdingID = rs.getInt("holding_holdingID"); BigDecimal price = orderData.getPrice(); double quantity = orderData.getQuantity(); BigDecimal orderFee = orderData.getOrderFee(); Log.trace("TradeDirect:completeOrder--> Completing Order " + orderData.getOrderID() + "\n\t Order info: " + orderData + "\n\t Account info: " + accountID + "\n\t Quote info: " + quoteID); updateOrderStatus(conn, orderData.getOrderID(), "closed"); Log.trace("TradeDirect:completeOrder--> Completed Order " + orderData.getOrderID() + "\n\t Order info: " + orderData + "\n\t Account info: " + accountID + "\n\t Quote info: " + quoteID + "\n\t Holding info: " + holdingData);
public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) { OrderDataBean order; BigDecimal total; try { if (Log.doTrace()) Log.trace("TradeSLSBBean:buy", userID, symbol, quantity, orderProcessingMode); AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); AccountDataBean account = profile.getAccount(); QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol); HoldingDataBean holding = null; // The holding will be created by this buy order order = createOrder(account, quote, holding, "buy", quantity); // UPDATE - account should be credited during completeOrder BigDecimal price = quote.getPrice(); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); account.setBalance(balance.subtract(total)); if (orderProcessingMode == TradeConfig.SYNCH) completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); } catch (Exception e) { Log.error("TradeSLSBBean:buy(" + userID + "," + symbol + "," + quantity + ") --> failed", e); /* On exception - cancel the order */ // TODO figure out how to do this with JPA // if (order != null) order.cancel(); throw new EJBException(e); } return order; }
Log.error("TradeSLSBBean:sell User " + userID + " attempted to sell holding " + holdingID + " which has already been sold"); OrderDataBean orderData = new OrderDataBean(); orderData.setOrderStatus("cancelled"); entityManager.persist(orderData); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee); completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true);
/** * @see TradeServices#getClosedOrders(String) */ public Collection getClosedOrders(String userID) throws Exception { Collection orderDataBeans = new ArrayList(); Connection conn = null; try { if (Log.doTrace()) Log.trace("TradeDirect:getClosedOrders - inSession(" + this.inSession + ")", userID); conn = getConn(); PreparedStatement stmt = getStatement(conn, getClosedOrdersSQL); stmt.setString(1, userID); ResultSet rs = stmt.executeQuery(); while (rs.next()) { OrderDataBean orderData = getOrderDataFromResultSet(rs); orderData.setOrderStatus("completed"); updateOrderStatus(conn, orderData.getOrderID(), orderData.getOrderStatus()); orderDataBeans.add(orderData); } stmt.close(); commit(conn); } catch (Exception e) { Log.error("TradeDirect:getOrders -- error getting user orders", e); rollBack(conn, e); } finally { releaseConn(conn); } return orderDataBeans; }
BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); order.cancel();
/** * Sell a stock holding and removed the holding for the given user. Given a * Holding, retrieve current quote, credit user's account, and reduce * holdings in user's portfolio. * * @param userID the customer requesting the sell * @param holdingID the users holding to be sold * @return OrderDataBean providing the status of the newly created sell * order */ public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode) throws Exception { if (Log.doActionTrace()) Log.trace("TradeAction:sell", userID, holdingID, new Integer(orderProcessingMode)); OrderDataBean orderData; orderData = trade.sell(userID, holdingID, orderProcessingMode); if (!(orderData.getOrderStatus().equalsIgnoreCase("cancelled"))) //after the purchase or sell of a stock, update the stocks volume // and price updateQuotePriceVolume(orderData.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), orderData.getQuantity()); return orderData; }
public boolean isCancelled() { String orderStatus = getOrderStatus(); if (orderStatus.compareToIgnoreCase("cancelled") == 0) return true; return false; }
public boolean isSell() { String orderType = getOrderType(); if ( orderType.compareToIgnoreCase("sell") == 0 ) return true; return false; }
order.getQuote(); if (order.isCompleted()) throw new EJBException("Error: attempt to complete Order that is already completed\n" + order); AccountDataBean account = order.getAccount(); QuoteDataBean quote = order.getQuote(); HoldingDataBean holding = order.getHolding(); BigDecimal price = order.getPrice(); double quantity = order.getQuantity(); Log.trace("TradeSLSBBeanInternal:completeOrder--> Completing Order " + order.getOrderID() + "\n\t Order info: " + order + "\n\t Account info: " + account if (order.isBuy()) { order.setHolding(newHolding); if (order.isSell()) { Log.error("TradeSLSBBean:completeOrder -- Unable to sell order " + order.getOrderID() + " holding already sold"); order.cancel(); return order; } else { entityManager.remove(holding); order.setHolding(null); order.setOrderStatus("closed");
+ " which has already been sold"); OrderDataBean orderData = new OrderDataBean(); orderData.setOrderStatus("cancelled"); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee); completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); order.cancel(); if (!(order.getOrderStatus().equalsIgnoreCase("cancelled"))) updateQuotePriceVolume(order.getSymbol(), TradeConfig.getRandomPriceChangeFactor(), order.getQuantity());
String orderType = orderData.getOrderType(); String orderStatus = orderData.getOrderStatus(); int holdingID = rs.getInt("holding_holdingID"); BigDecimal price = orderData.getPrice(); double quantity = orderData.getQuantity(); BigDecimal orderFee = orderData.getOrderFee(); Log.trace("TradeJDBCDirect:completeOrder--> Completing Order " + orderData.getOrderID() + "\n\t Order info: " + orderData + "\n\t Account info: " + accountID + "\n\t Quote info: " + quoteID); updateOrderStatus(conn, orderData.getOrderID(), "closed"); Log.trace("TradeJDBCDirect:completeOrder--> Completed Order " + orderData.getOrderID() + "\n\t Order info: " + orderData + "\n\t Account info: " + accountID + "\n\t Quote info: " + quoteID + "\n\t Holding info: " + holdingData);
public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) { OrderDataBean order; BigDecimal total; try { if (Log.doTrace()) Log.trace("TradeSLSBBean:buy", userID, symbol, quantity, orderProcessingMode); AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); AccountDataBean account = profile.getAccount(); QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol); HoldingDataBean holding = null; // The holding will be created by this buy order order = createOrder(account, quote, holding, "buy", quantity); // UPDATE - account should be credited during completeOrder BigDecimal price = quote.getPrice(); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); account.setBalance(balance.subtract(total)); if (orderProcessingMode == TradeConfig.SYNCH) completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); } catch (Exception e) { Log.error("TradeSLSBBean:buy(" + userID + "," + symbol + "," + quantity + ") --> failed", e); /* On exception - cancel the order */ // TODO figure out how to do this with JPA // if (order != null) order.cancel(); throw new EJBException(e); } return order; }
Log.error("TradeSLSBBean:sell User " + userID + " attempted to sell holding " + holdingID + " which has already been sold"); OrderDataBean orderData = new OrderDataBean(); orderData.setOrderStatus("cancelled"); entityManager.persist(orderData); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee); completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true);
/** * @see TradeServices#getClosedOrders(String) */ public Collection getClosedOrders(String userID) throws Exception { Collection orderDataBeans = new ArrayList(); Connection conn = null; try { if (Log.doTrace()) Log.trace("TradeJDBCDirect:getClosedOrders - inSession(" + this.inSession + ")", userID); conn = getConn(); PreparedStatement stmt = getStatement(conn, getClosedOrdersSQL); stmt.setString(1, userID); ResultSet rs = stmt.executeQuery(); while (rs.next()) { OrderDataBean orderData = getOrderDataFromResultSet(rs); orderData.setOrderStatus("completed"); updateOrderStatus(conn, orderData.getOrderID(), orderData.getOrderStatus()); orderDataBeans.add(orderData); } stmt.close(); commit(conn); } catch (Exception e) { Log.error("TradeJDBCDirect:getOrders -- error getting user orders", e); rollBack(conn, e); } finally { releaseConn(conn); } return orderDataBeans; }