public void WrongInstrumentThrowsException()
        {
            var order = new EquityOrder(999, Order.OrderTypes.GoodUntilCancelled,
                                        Order.BuyOrSell.Buy, 5, 10ul);

            Assert.Throws <ArgumentException>(() => m_BuyOrders.Insert(order));
        }
Exemplo n.º 2
0
        public void WrongInstrumentThrowsException()
        {
            var order = new EquityOrder(new Instrument("WRONG"), Order.OrderTypes.GoodUntilCancelled,
                                        Order.BuyOrSell.Sell, 10, 10ul);

            Assert.Throws <ArgumentException>(() => m_SellOrders.Insert(order));
        }
Exemplo n.º 3
0
        public void SubmitSellOrderTest()
        {
            var sellOrder = new EquityOrder(m_Instrument, Order.OrderTypes.LimitPrice, Order.BuyOrSell.Sell, 100, 100);

            m_Market.SubmitOrder(sellOrder);

            Assert.That(m_Market[m_Instrument].SellOrders[0], Is.EqualTo(sellOrder));
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            this._orderServiceMock = new Mock <IOrderService>();

            this._equityOrderFactory = new EquityOrderFactory(this._orderServiceMock.Object);

            this._sut = _equityOrderFactory.Create(EQUITY_CODE, 10, TRESHOLD);
        }
        public void TickReceivedAtOrAboveThreshold()
        {
            var orderServiceMoq = new Mock <IOrderService>();
            var equityCode      = "CODE1";
            var quantity        = 1;
            var price           = 10.23M;

            var equityOrder = new EquityOrder(orderServiceMoq.Object, 10);

            equityOrder.ReceiveTick(equityCode, price);
            orderServiceMoq.Verify(t => t.Buy(equityCode, quantity, price), Times.Never);
        }
Exemplo n.º 6
0
        public void BigBuyMatchesMultipleSellsTest()
        {
            var secondSellOrder = new EquityOrder(m_Instrument, Order.OrderTypes.GoodUntilCancelled,
                                                  Order.BuyOrSell.Sell, 95, 100);

            m_SellOrders.Insert(secondSellOrder);
            m_BuyOrder.Quantity = 150;
            Assert.True(OrderProcessor.TryMatchOrder(m_BuyOrder, m_SellOrders, m_Trades));

            Assert.That(m_TradeProcessor.Trades.Count, Is.EqualTo(2));
            Assert.That(m_BuyOrder.Quantity, Is.EqualTo(0));
            Assert.That(secondSellOrder.Quantity, Is.EqualTo(50));
            Assert.That(m_SellOrders[0] == secondSellOrder && m_SellOrders.Count() == 1);
        }
Exemplo n.º 7
0
 public void Init()
 {
     m_Instrument = new Instrument("GOOG");
     m_BuyOrder   = new EquityOrder(m_Instrument, Order.OrderTypes.GoodUntilCancelled, Order.BuyOrSell.Buy, 100M,
                                    100ul);
     m_SellOrder = new EquityOrder(m_Instrument, Order.OrderTypes.GoodUntilCancelled, Order.BuyOrSell.Sell, 90,
                                   100ul);
     m_SellOrders = new SellOrders(m_Instrument);
     m_BuyOrders  = new BuyOrders(m_Instrument);
     m_SellOrders.Insert(m_SellOrder);
     m_BuyOrders.Insert(m_BuyOrder);
     m_Trades         = new Trades(m_Instrument);
     m_TradeProcessor = m_Trades.TradeProcessingStrategy as Trades.InMemoryTradeProcessor;
 }
        public void MultipleReceiveTicksAfterSuccessAreIgnored()
        {
            var orderServiceMoq = new Mock <IOrderService>();
            var equityCode      = "CODE1";
            var quantity        = 1;
            var price           = 1.23M;

            orderServiceMoq.Setup(c => c.Buy(equityCode, quantity, price));
            var equityOrder = new EquityOrder(orderServiceMoq.Object, 10);

            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);
            orderServiceMoq.Verify(t => t.Buy(equityCode, quantity, price), Times.Once);
        }
        public void MultipleReceiveTicketsAfterFailureAreIgnored()
        {
            var orderServiceMoq = new Mock <IOrderService>();
            var equityCode      = "CODE1";
            var quantity        = 1;
            var price           = 1.23M;

            var equityOrder = new EquityOrder(orderServiceMoq.Object, 10);

            equityOrder.OrderPlaced += e => throw new Exception("error raised");

            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);
            equityOrder.ReceiveTick(equityCode, price);

            orderServiceMoq.Verify(t => t.Buy(equityCode, quantity, price), Times.Once);
        }
        public void TickReceivedBelowThreshold()
        {
            var     orderServiceMoq  = new Mock <IOrderService>();
            var     equityCode       = "CODE1";
            var     quantity         = 1;
            var     price            = 1.23M;
            var     actualEquityCode = string.Empty;
            decimal?actualPrice      = null;


            var equityOrder = new EquityOrder(orderServiceMoq.Object, 10);

            equityOrder.OrderPlaced += delegate(OrderPlacedEventArgs e)
            {
                actualEquityCode = e.EquityCode;
                actualPrice      = e.Price;
            };

            equityOrder.ReceiveTick(equityCode, price);

            orderServiceMoq.Verify(t => t.Buy(equityCode, quantity, price), Times.Once);
            Assert.AreEqual(equityCode, actualEquityCode);
            Assert.AreEqual(price, actualPrice);
        }
Exemplo n.º 11
0
 public void Setup()
 {
     _orderServiceMock = new Mock <IOrderService>();
     _equityOrder      = new EquityOrder(_orderServiceMock.Object, equityCode, orderThreshhold, quantity);
 }
Exemplo n.º 12
0
        private async void bttnSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_symbol))
            {
                MessageBox.Show("The symbols is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (cmbActions.SelectedItem == null ||
                cmbOrderTypes.SelectedItem == null)
            {
                MessageBox.Show("Please select an action and order type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string                         symbol    = _symbol;
            int                            quantity  = (!string.IsNullOrEmpty(txtQuantity.Text)) ? Convert.ToInt32(txtQuantity.Text.Trim()) : 0;
            EquityOrderActions             action    = (cmbActions.SelectedItem != null) ? (EquityOrderActions)cmbActions.SelectedItem : EquityOrderActions.buy;
            EquityOrderTypes               orderType = (cmbOrderTypes.SelectedItem != null) ? (EquityOrderTypes)cmbOrderTypes.SelectedItem : EquityOrderTypes.market;
            EquityOrderExpires             expire    = (cmbExpires.SelectedItem != null) ? (EquityOrderExpires)cmbExpires.SelectedItem : EquityOrderExpires.day;
            EquityOrderSpecialInstructions spInst    = (cmbSpInstructions.SelectedItem != null) ? (EquityOrderSpecialInstructions)cmbSpInstructions.SelectedItem : EquityOrderSpecialInstructions.none;
            float                          price     = (!string.IsNullOrEmpty(txtPrice.Text)) ? Convert.ToSingle(txtPrice.Text.Trim()) : 0;
            float                          actPrice  = (!string.IsNullOrEmpty(txtActPrice.Text)) ? Convert.ToSingle(txtActPrice.Text.Trim()) : 0;

            // Check if quantity is greater than 0
            if (quantity == 0)
            {
                MessageBox.Show("Quantity must be greater than 0.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            var newOrder = new EquityOrder(symbol, quantity, action, orderType);

            string orderDescription = string.Empty;

            string confirmMsg = string.Empty;

            switch (orderType)
            {
            case EquityOrderTypes.market:
                newOrder.Expire        = expire;
                newOrder.SpInstruction = spInst;

                break;

            case EquityOrderTypes.limit:
                newOrder.Price         = price;
                newOrder.Expire        = expire;
                newOrder.SpInstruction = spInst;

                break;

            case EquityOrderTypes.stop_limit:
                newOrder.Price    = price;
                newOrder.ActPrice = actPrice;
                newOrder.Expire   = expire;

                break;

            case EquityOrderTypes.stop_market:
                newOrder.ActPrice = actPrice;
                newOrder.Expire   = expire;

                break;

            case EquityOrderTypes.tstopdollar:
                float dollar = Convert.ToSingle(txtTsParam.Text.Trim());
                newOrder.TsParam = dollar;
                newOrder.Expire  = expire;

                break;

            case EquityOrderTypes.tstoppercent:
                int percent = Convert.ToInt32(txtTsParam.Text.Trim());
                newOrder.TsParam = percent;
                newOrder.Expire  = expire;

                break;
            }

            string orderString = EquityOrder.AccountIdString + newOrder.GetOrderString();

            if (newOrder.Validate())
            {
                Debug.Print(orderString);

                var result = MessageBox.Show(newOrder.ConfirmMessage, "Confirm Order", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2);

                if (result == DialogResult.Yes)
                {
                    EquityOrder.AddOrder(newOrder);

                    EquityOrderResponse response = await EquityOrder.SubmitOrder();

                    if (!string.IsNullOrEmpty(response.Error))
                    {
                        MessageBox.Show(response.Error, "Server Response", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("The order submitted successfully.\r\nOrder Id: " + response.OrderId, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ResetBasicControls();
                        ResetOptionalControls();
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show(orderString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 13
0
 public void Setup()
 {
     orderServiceMock = new Mock <IOrderService>();
     equityOrder      = new EquityOrder(orderServiceMock.Object, relevantEquityCode, orderThreshhold, quantity);
 }
Exemplo n.º 14
0
 public void Setup()
 {
     _orderService = new Mock <IOrderService>();
     _instrument   = new Instrument("MIC", 100, 100);
     _equityOrder  = new EquityOrder(_orderService.Object, _instrument);
 }