示例#1
0
        public void SettingNewPriceWhileOrderActiveResultsInMarketOrderCancelAndCreatesNewOrder()
        {
            const decimal totalQ = 25;
            const decimal clipQ  = 10;

            const string orderID = "OrderID";

            var expected = DefaultFakeOrderRecord(quantity: totalQ);

            var newPrice = expected.Price + 10;

            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            var updatedOrders = new UpdatedOrders();

            mockServer.Setup(s => s.UpdateOrder(It.IsAny <OrderRecord>(), It.IsAny <OrderRecord>()))
            .Returns(true)
            .Callback <OrderRecord, OrderRecord>(updatedOrders.AddUpdate);

            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipQ,
                                                        expected.Price,
                                                        priceDelta);

            iceberg.Activate();
            iceberg.ActivatedMarketOrderAccepted(orderID);

            iceberg.SetNewOrderPrice(newPrice);

            mockServer.Verify(s => s.CreateOrder(It.IsAny <OrderRecord>()),
                              Times.Once());

            mockServer.Verify(s => s.UpdateOrder(It.IsAny <OrderRecord>(), It.IsAny <OrderRecord>()),
                              Times.Once());

            Assert.AreEqual(1,
                            updatedOrders.OldRecords.Count,
                            "Incorrect number of old orders in update callback");
            var old = updatedOrders.OldRecords[0];

            Assert.AreEqual(expected.ClOrdID,
                            old.ClOrdID,
                            "Incorrect ClOrdID for old record when updating");

            Assert.AreEqual(1,
                            updatedOrders.NewRecords.Count,
                            "Incorrect number of new orders in update callback");
            var update = updatedOrders.NewRecords[0];

            Assert.AreEqual(newPrice, update.Price, "Updated order price incorrect");
        }
示例#2
0
 public void InsertUpdatedOrder(DisplayedOrder dOrder)
 {
     lock (updatedOrdersLock)
     {
         UpdatedOrders.Add(dOrder);
         MinorLog(new Log
         {
             Text = string.Format("OrderId:{0}, status:{1}, filled:{2}, remaining:{3}",
                                  dOrder.OrderId, dOrder.Status, dOrder.Filled, dOrder.Remaining),
             Source = "Insert UpdatedOrder",
             Time   = DateTime.Now
         });
     }
 }
示例#3
0
        public void SettingNewPriceWhileOrderActiveResultsInMarketOrderCancelAndCreatesNewOrder()
        {
            const decimal totalQ = 25;
            const decimal clipQ = 10;

            const string orderID = "OrderID";

            var expected = DefaultFakeOrderRecord(quantity: totalQ);

            var newPrice = expected.Price + 10;

            var mockServer = new Mock<IServerFacade>();
            mockServer.Setup(s => s.CreateOrder(It.IsAny<OrderRecord>())).Returns(true);

            var updatedOrders = new UpdatedOrders();
            mockServer.Setup(s => s.UpdateOrder(It.IsAny<OrderRecord>(), It.IsAny<OrderRecord>()))
                      .Returns(true)
                      .Callback<OrderRecord, OrderRecord>(updatedOrders.AddUpdate);

            const decimal priceDelta = 0;
            var iceberg = new IcebergOrder(mockServer.Object,
                                           expected.Symbol,
                                           expected.ClOrdID,
                                           expected.Side,
                                           expected.Quantity,
                                           clipQ,
                                           expected.Price,
                                           priceDelta);

            iceberg.Activate();
            iceberg.ActivatedMarketOrderAccepted(orderID);

            iceberg.SetNewOrderPrice(newPrice);

            mockServer.Verify(s => s.CreateOrder(It.IsAny<OrderRecord>()),
                              Times.Once());

            mockServer.Verify(s => s.UpdateOrder(It.IsAny<OrderRecord>(), It.IsAny<OrderRecord>()),
                              Times.Once());

            Assert.AreEqual(1,
                            updatedOrders.OldRecords.Count,
                            "Incorrect number of old orders in update callback");
            var old = updatedOrders.OldRecords[0];
            Assert.AreEqual(expected.ClOrdID,
                            old.ClOrdID,
                            "Incorrect ClOrdID for old record when updating");

            Assert.AreEqual(1,
                            updatedOrders.NewRecords.Count,
                            "Incorrect number of new orders in update callback");
            var update = updatedOrders.NewRecords[0];
            Assert.AreEqual(newPrice, update.Price, "Updated order price incorrect");
        }