Log.trace("TradeJdbc:sell - inSession(" + this.inSession + ")", userID, holdingID);
conn = getConn();
AccountDataBean accountData = getAccountData(conn, userID);
HoldingDataBean holdingData = getHoldingData(conn, holdingID.intValue());
QuoteDataBean quoteData = null;
if (holdingData != null)
quoteData = getQuoteData(conn, holdingData.getQuoteID());
if ((accountData == null) || (holdingData == null) || (quoteData == null)) {
String error =
"TradeJdbc:sell -- error selling stock -- unable to find: \n\taccount=" + accountData
+ "\n\tholding=" + holdingData + "\n\tquote=" + quoteData + "\nfor user: " + userID
+ " and holdingID: " + holdingID;
Log.error(error);
rollBack(conn, new Exception(error));
return orderData;
}
double quantity = holdingData.getQuantity();
orderData = createOrder(conn, accountData, quoteData, holdingData, "sell", quantity);
// Set the holdingSymbol purchaseDate to selling to signify the sell
// is "inflight"
updateHoldingStatus(conn, holdingData.getHoldingID(), holdingData.getQuoteID());
// UPDATE -- account should be credited during completeOrder
BigDecimal price = quoteData.getPrice();
BigDecimal orderFee = orderData.getOrderFee();
total = (new BigDecimal(quantity).multiply(price)).subtract(orderFee);