public void CancelOrderTestCase()
        {
            LimitOrder order = OrderMessage.GenerateLimitOrder(DateTime.Now.ToString("yyMMddHmsfff"), new Security()
            {
                Symbol = "EUR/USD"
            }, OrderSide.BUY, 1000, 1.090M,
                                                               "Fxcm");

            order.OrderCurrency = "EUR";
            order.OrderTif      = "GTC";

            bool logon = false;

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            _provider.LogonArrived += delegate(string dataProvider)
            {
                logon = true;
                resetEvent.Set();
            };
            //start provider
            _provider.Start();
            resetEvent.WaitOne(5000);
            Assert.True(logon);
            if (logon)
            {
                bool newArrived          = false;
                bool cancellationArrived = false;
                bool logout = false;

                _provider.NewArrived += delegate(Order newOrder)
                {
                    newArrived = true;
                    _provider.CancelLimitOrder(newOrder);
                };

                _provider.CancellationArrived += delegate(Order cancelledOrder)
                {
                    cancellationArrived = true;
                    resetEvent.Set();
                };

                _provider.SendLimitOrder(order);
                resetEvent.Reset();
                resetEvent.WaitOne(30000);

                _provider.LogoutArrived += delegate(string dataProvider)
                {
                    logout = true;
                    resetEvent.Set();
                };

                resetEvent.Reset();
                _provider.Stop();
                resetEvent.WaitOne(5000);
                Assert.True(logout, "Logout Arrived");
                Assert.True(newArrived, "New Arrived");
                Assert.True(cancellationArrived, "Cancellation Arrived");
            }
        }
Пример #2
0
        public void LimitOrderCruld()
        {
            bool       saved      = false;
            string     id         = DateTime.Now.ToString();
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(id,
                                                                    new Security()
            {
                Isin = "123", Symbol = "ERX"
            }, OrderSide.BUY, 100, 500.50m,
                                                                    OrderExecutionProvider.Blackwood);
            var ordersaved = new ManualResetEvent(false);

            //add limit order to database
            _orderRespository.AddUpdate(limitOrder);

            //get the same order
            LimitOrder getLimitOrder = _orderRespository.FindBy(id) as LimitOrder;

            if (getLimitOrder.OrderID.Equals(id) && getLimitOrder.LimitPrice == 500.50m)
            {
                saved = true;
                ordersaved.Set();
            }
            Assert.AreEqual(getLimitOrder.Security.Symbol, "ERX");

            ordersaved.WaitOne(30000);
            //delete the order
            _orderRespository.Delete(getLimitOrder);

            //get ther order again to verify its deleted or not
            getLimitOrder = _orderRespository.FindBy(id) as LimitOrder;
            Assert.AreEqual(true, saved, "LimitOrderNotSaved");
            Assert.IsNull(getLimitOrder, "Not deleted");
        }
Пример #3
0
        /// <summary>
        /// Sends enrty order to the Order Execution Service
        /// </summary>
        /// <param name="orderSide">Order side on which to open position</param>
        /// <param name="symbol">Symbol on which to send order</param>
        private void SendEntryOrder(string orderSide, string symbol)
        {
            try
            {
                if (!orderSide.Equals(TradeHubConstants.OrderSide.NONE))
                {
                    _entryOrderSent = true;

                    ConsoleWriter.WriteLine(ConsoleColor.Green, "Sending" + orderSide + " entry order.");

                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info("Sending" + orderSide + " entry order.", _type.FullName, "SendEntryOrder");
                    }

                    // Get new unique ID
                    var id = (_orderId++).ToString("X");

                    Security security = new Security {
                        Symbol = symbol
                    };

                    // Create new Limit Order
                    LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(id, security, orderSide, 100, 1.24M, _orderExecutionProvider);

                    // Send Limit Order to OEE
                    SendOrder(limitOrder);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "SendEntryOrder");
            }
        }
Пример #4
0
        public void InsertTestCase()
        {
            bool       saved      = false;
            string     id         = DateTime.Now.ToString();
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(id,
                                                                    new Security()
            {
                Isin = "124", Symbol = "GOOG"
            }, OrderSide.BUY, 100, 500.50m,
                                                                    OrderExecutionProvider.Blackwood);
            var ordersaved = new ManualResetEvent(false);

            //add limit order to database
            _orderRespository.AddUpdate(limitOrder);

            //get the same order
            Order getLimitOrder = _orderRespository.FindBy(id) as Order;

            if (getLimitOrder.OrderID.Equals(id))
            {
                saved = true;
                ordersaved.Set();
            }
            ordersaved.WaitOne(30000);
            Assert.AreEqual(true, saved, "LimitOrderNotSaved");
        }
Пример #5
0
        /// <summary>
        /// Called when HTB Locate event is Raised by Blackwood
        /// </summary>
        private void OnLocate(object sender, BWOrder locatemsg)
        {
            try
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("HTB Locate event raised by Blackwood: " + locatemsg.ToString(), _type.FullName, "OnLocate");
                }

                //Create limit order containing locate parameters
                LimitOrder locateOrder = OrderMessage.GenerateLimitOrder(locatemsg.ClientOrderID.ToString(),
                                                                         new Security()
                {
                    Symbol = locatemsg.Symbol
                },
                                                                         locatemsg.OrderSide2.ToString(),
                                                                         (int)locatemsg.Size,
                                                                         (decimal)locatemsg.LimitPrice,
                                                                         _orderExecutionProviderName);

                // Raise event to notify listeners
                if (OnLocateMessage != null)
                {
                    // Update BW Locate Orders Map
                    _locateOrders.AddOrUpdate(locatemsg.ClientOrderID.ToString(), locatemsg, (key, value) => locatemsg);

                    // Fire Event
                    OnLocateMessage(locateOrder);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "OnLocate");
            }
        }
Пример #6
0
        /// <summary>
        /// Sends a new limit order to the server
        /// </summary>
        /// <param name="id">Unique ID to distinguish the order</param>
        /// <param name="security">Contains symbol information</param>
        /// <param name="orderSize">Trade size or lot</param>
        /// <param name="limitPrice">Limit price</param>
        /// <param name="orderSide">Side on which to send the order</param>
        private void SendLimitOrder(string id, Security security, int orderSize, decimal limitPrice, string orderSide = OrderSide.BUY)
        {
            // Create new Limit Order
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(id, security, orderSide, orderSize, limitPrice, _orderExecutionProvider);

            // Send limit order
            this.SendOrder(limitOrder);
        }
 public void CreateLimitOrder_IfPriceIsZero_ExceptionWillBeThrown()
 {
     LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(new Security()
     {
         Symbol = "AAPL"
     }, OrderSide.BUY, 10, 0,
                                                             OrderExecutionProvider.SimulatedExchange);
 }
Пример #8
0
        public void CancelOrderTest()
        {
            LimitOrder order = OrderMessage.GenerateLimitOrder(DateTime.Now.ToString("yyMMddHmsfff"), new Security()
            {
                Symbol = "TNA"
            }, OrderSide.SELL, 3, 105,
                                                               "WldxFix");

            order.Exchange = "SMARTEDGEP";
            bool             logon                 = false;
            ManualResetEvent resetEvent            = new ManualResetEvent(false);
            WldxFixOrderExecutionProvider provider = new WldxFixOrderExecutionProvider();

            provider.LogonArrived += delegate(string dataProvider)
            {
                logon = true;
                resetEvent.Set();
            };
            //start provider
            provider.Start();
            resetEvent.WaitOne(5000);
            Assert.True(logon);
            if (logon)
            {
                bool newArrived          = false;
                bool cancellationArrived = false;

                provider.NewArrived += delegate(Order newOrder)
                {
                    newArrived = true;
                    provider.CancelLimitOrder(order);
                };
                provider.CancellationArrived += delegate(Order cancelledOrder)
                {
                    cancellationArrived = true;
                    resetEvent.Set();
                };
                provider.SendLimitOrder(order);
                resetEvent.Reset();
                resetEvent.WaitOne(30000);

                bool logout = false;
                provider.LogoutArrived += delegate(string dataProvider)
                {
                    logout = true;
                    resetEvent.Set();
                };
                resetEvent.Reset();
                provider.Stop();
                resetEvent.WaitOne(5000);
                Assert.True(logout);
                Assert.True(newArrived);
                Assert.True(cancellationArrived);
            }
        }
Пример #9
0
        /// <summary>
        /// Sends a new Limit Order Request to 'Order Execution Server'
        /// </summary>
        /// <param name="orderDetails">Contains limit order information</param>
        public void LimitOrderRequest(OrderDetails orderDetails)
        {
            // Get new Order ID
            orderDetails.ID = _orderExecutionService.GetOrderId();

            // Create Limit Order object to be sent to 'Order Execution Service'
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(orderDetails.ID, orderDetails.Security, orderDetails.Side,
                                                                    orderDetails.Quantity, orderDetails.Price, orderDetails.Provider);

            limitOrder.OrderTif = OrderTif.GTC;

            // Send Reques to Server
            _orderExecutionService.SendOrder(limitOrder);
        }
        public void CreateLimitOrder_IfAllParametersAreOk_VerifyLimitOrderIsCreated()
        {
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(new Security()
            {
                Symbol = "AAPL"
            }, OrderSide.BUY, 10, 100,
                                                                    OrderExecutionProvider.SimulatedExchange);

            Assert.NotNull(limitOrder);
            Assert.IsNotNullOrEmpty(limitOrder.OrderID);
            Assert.AreEqual(limitOrder.OrderSide, OrderSide.BUY);
            Assert.AreEqual(limitOrder.OrderSize, 10);
            Assert.AreEqual(limitOrder.LimitPrice, 100);
            Assert.AreEqual(limitOrder.OrderExecutionProvider, OrderExecutionProvider.SimulatedExchange);
        }
Пример #11
0
        public void SendLimitOrderAndCancelItEnsureItGetsCancelled()
        {
            bool       cancellationArrived = false;
            Order      cancelledOrder      = null;
            LimitOrder limitOrder          = OrderMessage.GenerateLimitOrder(new Security()
            {
                Symbol = "MSFT"
            }, OrderSide.BUY, 1,
                                                                             10, "Tradier");

            limitOrder.OrderTif = OrderTif.DAY;
            _executionProvider.SendLimitOrder(limitOrder);
            _executionProvider.CancellationArrived += delegate(Order order)
            {
                cancellationArrived = true;
                cancelledOrder      = order;
            };
            _executionProvider.CancelLimitOrder(limitOrder);
            Assert.True(cancellationArrived);
            Assert.AreEqual(cancelledOrder.OrderID, limitOrder.OrderID);
        }
Пример #12
0
        public void FilterByTestCase()
        {
            bool       saved      = false;
            var        ordersaved = new ManualResetEvent(false);
            string     id         = DateTime.Now.ToString();
            LimitOrder limitOrder = OrderMessage.GenerateLimitOrder(id,
                                                                    new Security()
            {
                Isin = "124", Symbol = "GOOG"
            }, OrderSide.BUY, 100, 500.50m,
                                                                    OrderExecutionProvider.Blackwood);

            //add limit order to database
            _orderRespository.AddUpdate(limitOrder);

            //get the order filter by security
            IList <Order> orders = _orderRespository.FilterBySecurity(new Security()
            {
                Symbol = "GOOG"
            });

            if (orders != null)
            {
                foreach (var order in orders)
                {
                    LimitOrder getLimitOrder = order as LimitOrder;
                    if (getLimitOrder.OrderID.Equals(id) && getLimitOrder.LimitPrice == 500.50m)
                    {
                        saved = true;
                        ordersaved.Set();
                        break;
                    }
                }
            }
            ordersaved.WaitOne(30000);
            Assert.AreEqual(true, saved, "LimitOrderNotSaved");
        }