//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// .NET StockTrader Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications
using System;
using System.Globalization;
using System.Web;
using System.Text;
using Trade.StockTraderWebApplicationModelClasses;
using Trade.StockTraderWebApplicationSettings;
using Trade.StockTraderWebApplicationServiceClient;
using Trade.Utility;
namespace Trade.Web
{
///
/// Calls into Business Services to place an order (buy/sell). Note that this page is called from the
/// StockTrade.aspx page after user enters number of shares. This is slightly different than Trade 6.1 flow,
/// but necessary since we allow selling portions of a holding vs. just entire holding ala Trade 6.1. However,
/// for benchmarking this page can be called directly without visiting StockTrade.aspx when comparing perf to Trade 6.1,
/// for equivalence.
///
public partial class Order : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BSLClient businessServicesClient = new BSLClient();
OrderDataUI order = null;
string userid = HttpContext.Current.User.Identity.Name;
string action = Input.InputText(Request["action"], 10) ?? string.Empty;
double quantity = 0;
string symbol = null;
int holdingID = -1;
bool badQuantity = false;
/****************************
* Buy a Stock
****************************/
if (action.Equals(StockTraderUtility.ORDER_TYPE_BUY))
{
if (!Double.TryParse(Request["quantity"], out quantity))
badQuantity = true;
symbol = Input.InputText(Request["symbol"], StockTraderUtility.SYMBOLSTRING_MAXLENGTH);
if (quantity > 0)
order = businessServicesClient.buy(userid, symbol, quantity);
else
badQuantity = true;
}
/****************************
* Sell a Stock
****************************/
else if (action.Equals(StockTraderUtility.ORDER_TYPE_SELL))
{
holdingID = Int32.Parse(Request["holdingid"]);
//WebSphere Trade 6.1 does not provide functionality for trading partial holdings.
//.NET StockTrader does, but will default to Trade 6.1 behavior and sell and entire holding if no
//quantity parameter is detected on the query string. Here we check if a quantity parameter actually
//exists on the query string. This is a bit of extra overhead, but done so we can add functionality
// (selling part of a holding) yet not sacrifice interop with WebSphere Trade 6.1
string quantityParam = Request["quantity"];
if (quantityParam != null)
{
quantity = Double.Parse(Request["quantity"]);
if (quantity <= 0)
badQuantity = true;
}
else
quantity = 0; //Value of 0 indicates to sell entire holding.
if (!badQuantity)
order = businessServicesClient.sell(userid, holdingID, quantity);
}
else
{
ConfirmMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_BAD_ACTION;
return;
}
if (!badQuantity)
{
if (order != null)
{
Cache.Remove(Settings.CACHE_KEY_CLOSED_ORDERSALERT + userid);
string orderIdStr = order.orderID.ToString();
OrderID.Text = orderIdStr;
OrderStatus.Text = order.orderStatus;
OpenDate.Text = order.openDate.ToString();
CompletionDate.Text = order.completionDate.ToString();
OrderFee.Text = string.Format("{0:C}", order.orderFee);
OrderType.Text = order.orderType;
string orderLink = order.quoteLink;
Symbol.Text = orderLink;
string orderQty = string.Format("{0:0,0}", order.quantity);
Quantity.Text = orderQty;
StringBuilder strBuilder = new StringBuilder("Order ");
strBuilder.Append(orderIdStr);
strBuilder.Append(" to ");
strBuilder.Append(order.orderType);
strBuilder.Append(" ");
strBuilder.Append(orderQty);
strBuilder.Append(" shares of ");
strBuilder.Append(orderLink);
strBuilder.Append(" has been submitted for processing.
");
strBuilder.Append("Order Details:");
ConfirmMessage.Text = (strBuilder.ToString());
// only show the panel if it didn't fail
this.OrderSummaryPanel.Visible = true;
}
else
ConfirmMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_BAD_ORDER_RETURN;
}
else
{
ConfirmMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_BAD_ORDER_PARMS;
}
}
}
}