Package org.apache.stonehenge.stocktrader

Examples of org.apache.stonehenge.stocktrader.CustomOrderBean


  public CustomOrderBean createOrder(String userID, String symbol, String orderType, double quantity, int holdingID) throws DAOException {
    int orderID = 0;
    Calendar minCalender = Calendar.getInstance();
    minCalender.setTimeInMillis(0);
    CustomOrderBean order = new CustomOrderBean(
                orderID,
                orderType,
        StockTraderUtility.ORDER_STATUS_OPEN,
                Calendar.getInstance(),
        minCalender,
                quantity,
                BigDecimal.valueOf(1),
        StockTraderUtility.getOrderFee(orderType),
                symbol);
    order.setHoldingId(holdingID);

    PreparedStatement getAccountId = null;
    try {
      getAccountId = sqlConnection.prepareStatement(SQL_GET_ACCOUNTID);
      getAccountId.setString(1, userID);
      ResultSet rs = getAccountId.executeQuery();
      if (rs.next()) {
        order.setAccountId(rs.getInt(1));
      }
    } catch (SQLException e) {

    } finally {
      if (getAccountId != null) {
        try {
          getAccountId.close();
        } catch (SQLException e) {
          logger.debug("", e);
        }
      }
    }

    PreparedStatement insertOrder = null;
    PreparedStatement selectOrderID = null;
    try {
      insertOrder = sqlConnection.prepareStatement(SQL_INSERT_ORDER);
      insertOrder.setBigDecimal(1, order.getOrderFee());
      insertOrder.setBigDecimal(2, order.getPrice());
      insertOrder.setString(3, order.getSymbol());
      insertOrder.setFloat(4, (float) order.getQuantity());
      insertOrder.setString(5, order.getOrderType());
      insertOrder.setInt(6, order.getAccountId());
      insertOrder.setInt(7, order.getHoldingId());
      insertOrder.executeUpdate();
     
      selectOrderID = sqlConnection.prepareStatement(SQL_SELECT_ORDER_ID);
      // ORDERFEE = ? AND PRICE = ? AND QUOTE_SYMBOL = ? AND QUANTITY = ?
      // ORDERTYPE = ? ORDERSTATUS = ? AND ACCOUNT_ACCOUNTID = ?
      // HOLDING_HOLDINGID = ?"
      selectOrderID.setBigDecimal(1, order.getOrderFee());
      selectOrderID.setBigDecimal(2, order.getPrice());
      selectOrderID.setString(3, order.getSymbol());
      selectOrderID.setDouble(4, order.getQuantity());
      selectOrderID.setString(5, order.getOrderType());
      selectOrderID.setString(6, "open");
      selectOrderID.setInt(7, order.getAccountId());
      selectOrderID.setInt(8, order.getHoldingId());
      ResultSet rs = selectOrderID.executeQuery();
      if (rs.next()) {
        try {
          order.setOrderID(rs.getInt(1));
        } finally {
          try {
            rs.close();
          } catch (SQLException e) {
            logger.debug("", e);
View Full Code Here


                        logger.debug("", e);
                        completionDate = Calendar.getInstance();
                        completionDate.setTimeInMillis(0);
                    }

                    CustomOrderBean orderBean = new CustomOrderBean(
                            orderId,
                            rs.getString(2),
                            rs.getString(3),
                            openDate,
                            completionDate,
View Full Code Here

                    } catch (SQLException e) {
                        logger.debug("", e);
                        completionDate = Calendar.getInstance();
                        completionDate.setTimeInMillis(0);
                    }
                    CustomOrderBean closedOrderBean = new CustomOrderBean(
                            orderId, rs.getString(2), rs.getString(3),
                            openDate, completionDate, rs.getDouble(6), rs
                                    .getBigDecimal(7), rs.getBigDecimal(8), rs
                                    .getString(9));
                    closedOrderBean.setOrderStatus(StockTraderUtility.ORDER_STATUS_CLOSED);
                    closedOrders.add(closedOrderBean);
                }
            } finally {
                try {
                    rs.close();
View Full Code Here

                        logger.debug("", e);
                        completionDate = Calendar.getInstance();
                        completionDate.setTimeInMillis(0);
                    }

                    CustomOrderBean orderBean = new CustomOrderBean(
                            orderId,
                            rs.getString(2),
                            rs.getString(3),
                            openDate,
                            completionDate,
View Full Code Here

                    } catch (SQLException e) {
                        logger.debug("", e);
                        completionDate = Calendar.getInstance();
                        completionDate.setTimeInMillis(0);
                    }
                    CustomOrderBean closedOrderBean = new CustomOrderBean(
                            orderId,
                            rs.getString(2),
                            rs.getString(3),
                            openDate,
                            completionDate,
                            rs.getDouble(6),
                            rs.getBigDecimal(7),
                            rs.getBigDecimal(8),
                            rs.getString(9));
                    closedOrderBean.setOrderStatus(StockTraderUtility.ORDER_STATUS_CLOSED);
                    closedOrders.add(closedOrderBean);
                }
            } finally {
                try {
                    rs.close();
View Full Code Here

  private static final Log logger = LogFactory.getLog(TradeServiceImpl.class);

  private final TraderServiceManager mgr = new TraderServiceManager();

  public BuyResponse buy(Buy buy) {
    CustomOrderBean order;
    try {
      order = mgr.buy(buy.getUserID(), buy.getSymbol(), buy.getQuantity());
    } catch (DAOException e) {
      logger.debug("", e);
      throw new RuntimeException(e);
View Full Code Here

    response.setRegisterReturn(param);
    return response;
  }

  public SellResponse sell(Sell sell) {
    CustomOrderBean param;
    try {
      param = mgr.sell(sell.getUserID(), sell.getHoldingID(), sell.getOrderProcessingMode());
    } catch (DAOException e) {
      logger.debug("", e);
      throw new RuntimeException(e);
View Full Code Here

    response.setSellReturn(param);
    return response;
  }

  public SellEnhancedResponse sellEnhanced(SellEnhanced sellEnhanced) {
    CustomOrderBean param;
    try {
      param = mgr.sellEnhanced(sellEnhanced.getUserID(), sellEnhanced.getHoldingID(), sellEnhanced.getQuantity());
    } catch (DAOException e) {
      logger.debug("", e);
      throw new RuntimeException(e);
View Full Code Here

  }

  public CustomOrderBean placeOrder(String orderType, String userID,
      int holdingID, String symbol, double quantity) throws DAOException {
    OrderDAO orderDAO = factory.getOrderDAO();
    CustomOrderBean order = null;
    CustomHoldingBean holding = new CustomHoldingBean();
    try {

      orderDAO.beginTransaction();
      order = createOrder(orderType, userID, holdingID, symbol, quantity,
View Full Code Here

  }

  private CustomOrderBean createOrder(String orderType, String userID,
      int holdingID, String symbol, double quantity,
      CustomHoldingBean holding) throws DAOException {
    CustomOrderBean order = null;
    OrderDAO orderDAO = factory.getOrderDAO();

    if (StockTraderUtility.ORDER_TYPE_SELL.equals(orderType)) {
      // CHECKME holding is the argument
      holding = orderDAO.getHolding(holdingID);
View Full Code Here

TOP

Related Classes of org.apache.stonehenge.stocktrader.CustomOrderBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.