public static OrderEditView CheckPrice(OrderEditView orderEditView) { using (IDalSession session = NHSessionFactory.CreateSession()) { ISecurityOrder order = (ISecurityOrder)OrderMapper.GetOrder(session, orderEditView.OrderId); ITradeableInstrument tradedInstrument = order.TradedInstrument; Price price = new Price(orderEditView.Price, order.TradedInstrument.CurrencyNominal, order.TradedInstrument); // Check if the Price is still reliable IPriceDetail instrumentPrice = tradedInstrument.CurrentPrice; if (instrumentPrice == null || instrumentPrice.Price.IsZero) orderEditView.Warning = string.Format("No price was found for {0} so the validation is not very reliable.", tradedInstrument.DisplayName); else { // check if the price is within 1% of the last exRate decimal rate = instrumentPrice.Price.Quantity; decimal diff = (price.Quantity - rate) / rate; decimal diffPct = Math.Round(Math.Abs(diff), 4) * 100; if (diffPct > 1) orderEditView.Warning = string.Format("The price you entered is {0}% {1} than the last known price ({2}).", diffPct.ToString("0.##"), (diff < 0 ? "smaller" : "higher"), instrumentPrice.Price.ShortDisplayString); if (instrumentPrice.IsOldDate) orderEditView.Warning += (orderEditView.Warning != string.Empty ? Environment.NewLine : "") + string.Format("The price found for {0} is old ({1}) so the validation is not very reliable.", tradedInstrument.DisplayName, instrumentPrice.Date.ToShortDateString()); } return orderEditView; } }
public static List<OrderEditView> GetOrderEditData(int orderId) { List<OrderEditView> allOrderFills = new List<OrderEditView>(); IDalSession session = NHSessionFactory.CreateSession(); IOrder order = OrderMapper.GetOrder(session, (int)orderId); OrderEditView oev = new OrderEditView(order.OrderID, order.PlacedValue.NumberOfDecimals, ((SecurityOrder)order).Route.Key); oev.IsSizeBased = order.IsSizeBased; allOrderFills.Add(oev); session.Close(); return allOrderFills; }
public static List<OrderEditView> GetOrderFxConvertData(int orderId) { List<OrderEditView> allOrderFills = new List<OrderEditView>(); if (orderId != 0) { using (IDalSession session = NHSessionFactory.CreateSession()) { ISecurityOrder order = (ISecurityOrder)OrderMapper.GetOrder(session, (int)orderId); ITradeableInstrument instrument = order.TradedInstrument; decimal exRate = instrument.CurrencyNominal.ExchangeRate.Rate; decimal originalAmount = order.Amount.Quantity; decimal convAmount = order.Amount.Convert(exRate, instrument.CurrencyNominal).Quantity; OrderEditView oev = new OrderEditView(order.OrderID, exRate, convAmount, originalAmount, instrument.CurrencyNominal.AltSymbol); allOrderFills.Add(oev); } } return allOrderFills; }