public void Submit(Order order, XDocument document)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            var ordersElement = document.Element("Orders");
            if (ordersElement == null)
            {
                ordersElement = new XElement("Orders");
                document.Add(ordersElement);
            }

            var orderElement = new XElement("Order",
                new XAttribute("OrderType", order.OrderType),
                new XAttribute("Shares", order.Shares),
                new XAttribute("StopLimitPrice", order.StopLimitPrice),
                new XAttribute("TickerSymbol", order.TickerSymbol),
                new XAttribute("TimeInForce", order.TimeInForce),
                new XAttribute("TransactionType", order.TransactionType),
                new XAttribute("Date", DateTime.Now.ToString(CultureInfo.InvariantCulture))
                );
            ordersElement.Add(orderElement);

            string message = String.Format(CultureInfo.CurrentCulture, Resources.LogOrderSubmitted,
                                           orderElement.ToString());
            logger.Log(message, Category.Debug, Priority.Low);
        }
示例#2
0
        public void Submit(Order order)
        {
#if !SILVERLIGHT
            XDocument document = File.Exists(FileName) ? XDocument.Load(FileName) : new XDocument();
            Submit(order, document);
            document.Save(FileName);
#else
            // In silverlight, you would normally not save the order to a file, but rather send it to an XML webservice
            // This would be the place were you would call that xml webservice. 
#endif
        }
        public void SubmitLogsAnEntry()
        {
            var logger = new MockLogger();
            var ordersService = new XmlOrdersService(logger);
            var document = new XDocument();

            var order = new Order
            {
                OrderType = OrderType.Stop,
                Shares = 3,
                StopLimitPrice = 14,
                TickerSymbol = "TESTSTOCK",
                TimeInForce = TimeInForce.ThirtyDays,
                TransactionType = TransactionType.Buy
            };

            ordersService.Submit(order, document);

            StringAssert.Contains(logger.LastMessage, "An order has been submitted.");
            StringAssert.Contains(logger.LastMessage, "TESTSTOCK");
            StringAssert.Contains(logger.LastMessage, "3");
            StringAssert.Contains(logger.LastMessage, TransactionType.Buy.ToString());
        }
        public void SubmitSavesOrderToXml()
        {
            var logger = new MockLogger();
            var ordersService = new XmlOrdersService(logger);
            var document = new XDocument();

            var order = new Order
                              {
                                  OrderType = OrderType.Stop,
                                  Shares = 3,
                                  StopLimitPrice = 14,
                                  TickerSymbol = "TESTSTOCK",
                                  TimeInForce = TimeInForce.ThirtyDays,
                                  TransactionType = TransactionType.Buy
                              };

            ordersService.Submit(order, document);

            var root = document.Element("Orders");
            Assert.IsNotNull(root);
            Assert.AreEqual(1, root.Elements("Order").Count());
            var orderElement = root.Element("Order");
            Assert.IsNotNull(orderElement);
            Assert.IsTrue(orderElement.Attributes().Count() >= 6);
            Assert.AreEqual<string>(order.OrderType.ToString(), orderElement.Attribute("OrderType").Value);
            Assert.AreEqual<string>(order.Shares.ToString(), orderElement.Attribute("Shares").Value);
            Assert.AreEqual<string>(order.StopLimitPrice.ToString(CultureInfo.InvariantCulture), orderElement.Attribute("StopLimitPrice").Value);
            Assert.AreEqual<string>(order.TickerSymbol, orderElement.Attribute("TickerSymbol").Value);
            Assert.AreEqual<string>(order.TimeInForce.ToString(), orderElement.Attribute("TimeInForce").Value);
            Assert.AreEqual<string>(order.TransactionType.ToString(), orderElement.Attribute("TransactionType").Value);

            var dateElement = orderElement.Attribute("Date");
            Assert.IsNotNull(dateElement);
            var parsedDate = DateTime.Parse(dateElement.Value, CultureInfo.InvariantCulture);
            Assert.IsTrue(parsedDate < DateTime.Now.AddSeconds(1));
            Assert.IsTrue(parsedDate > DateTime.Now.AddSeconds(-10));
        }
        private void Submit(object parameter)
        {
            if (!this.CanSubmit(parameter))
            {
                throw new InvalidOperationException();
            }

            var order = new Order();
            order.TransactionType = this.TransactionType;
            order.OrderType = this.OrderType;
            order.Shares = this.Shares.Value;
            order.StopLimitPrice = this.StopLimitPrice.Value;
            order.TickerSymbol = this.TickerSymbol;
            order.TimeInForce = this.TimeInForce;

            ordersService.Submit(order);

            CloseViewRequested(this, EventArgs.Empty);
        }
 public void Submit(Order order)
 {
     XDocument document = File.Exists(FileName) ? XDocument.Load(FileName) : new XDocument();
     Submit(order, document);
     document.Save(FileName);
 }
 public void Submit(Order order)
 {
     SubmitArgumentOrder = order;
 }