示例#1
0
        public void SubmitOrderSimMarket()
        {
            // reset the message cllection
            _messages = null;

            // AAB will just be put into the simulators internal book
            _driver = new KTASimulator.KTASimulator();
            _priceHandler = new L1PriceSupport.MemoryPriceHandler();
            _driver.Facade.PriceHandler = _priceHandler;

            // Wire up a message hander for the executin messages
            _driver.Message += new KaiTrade.Interfaces.Message(OnMessage);
            (_driver as DriverBase.DriverBase).PriceUpdate += new K2ServiceInterface.PriceUpdate(this.PriceUpdate);

            _driver.Start("");

            // Load a file of products to the simulator
            _driver.AddProductDirect(@"Data\SimProduct.txt");
            List<IProduct> products = _driver.Facade.GetProductManager().GetProducts("KTASIM", "", "");

            // test that these are available as products
            Assert.AreEqual(products.Count, 3);

            // Create and register a price publisher for each product
            KaiTrade.Interfaces.IProduct aabProduct = null;
            foreach (IProduct product in products)
            {
                if (product.Mnemonic == "AAB")
                {
                    aabProduct = product;
                    _driver.Facade.PriceHandler.CreatePxPub(product);
                    _driver.OpenPrices(product,0,DateTime.Now.Ticks.ToString());
                }

            }

            // Wait for prices in the publisher
            System.Threading.Thread.Sleep(20000);

            // test that some prices are there
            K2ServiceInterface.IL1PX pxPub = _driver.Facade.PriceHandler.GetPXPublisher(aabProduct) as K2ServiceInterface.IL1PX;
            Assert.IsNotNull(pxPub);
            Assert.IsNotNull(pxPub.BidPrice);

            // Test orders in the market - these are filled when the price is
            // matched and there is enough volume
            K2DataObjects.SubmitRequest nos = new K2DataObjects.SubmitRequest();
            nos.Account = "TEST";
            nos.ClOrdID = DriverBase.Identities.Instance.getNextOrderID();

            nos.Mnemonic = "AAB";
            nos.SecurityID = "AAB";
            nos.OrderQty = 5;
            nos.OrdType = KaiTrade.Interfaces.OrderType.LIMIT;
            nos.Price = 11.99M;
            nos.Side = KaiTrade.Interfaces.Side.BUY;

            K2DataObjects.Message msg = new K2DataObjects.Message();
            msg.Label = "D";
            msg.Data = JsonConvert.SerializeObject(nos);

            _driver.OnMessage(msg);

            System.Threading.Thread.Sleep(5000);

            K2DataObjects.SubmitRequest nos1 = new K2DataObjects.SubmitRequest();
            nos1.Account = "TEST";
            nos1.ClOrdID = DriverBase.Identities.Instance.getNextOrderID();

            nos1.Mnemonic = "AAB";
            nos1.SecurityID = "AAB";
            nos1.OrderQty = 5;
            nos1.OrdType = KaiTrade.Interfaces.OrderType.LIMIT;
            nos1.Price = 11.99M;
            nos1.Side = KaiTrade.Interfaces.Side.SELL;

            msg = new K2DataObjects.Message();
            msg.Label = "D";
            msg.Data = JsonConvert.SerializeObject(nos1);

            _driver.OnMessage(msg);

            // wait for the orders to fill - test that the right fills
            // were received
            System.Threading.Thread.Sleep(180000);

            if (_messages.Count > 0)
            {
                Assert.IsTrue(_messages["8"].Count >= 4);

                ReceivedfillStates ord1States = new ReceivedfillStates();
                ord1States.osNew = false;
                ord1States.osPartFill = false;
                ord1States.odFilled = false;
                ReceivedfillStates ord2States;
                ord2States.osNew = false;
                ord2States.osPartFill = false;
                ord2States.odFilled = false;

                // Both orders should be fully filled 3 reports each
                // New, Partial, Fill
                foreach (IMessage recvMsg in _messages["8"])
                {
                    Fill fill = JsonConvert.DeserializeObject<Fill>(recvMsg.Data);
                    if (fill.ClOrdID == nos.ClOrdID)
                    {
                        // check we have new, partfill, filled
                        switch (fill.OrderStatus)
                        {
                            case OrderStatus.NEW:
                                ord1States.osNew = true;
                                break;
                            case OrderStatus.PARTIALLY_FILLED:
                                ord1States.osPartFill = true;
                                break;
                            case OrderStatus.FILLED:
                                ord1States.odFilled = true;
                                break;
                        }
                    }
                    if (fill.ClOrdID == nos1.ClOrdID)
                    {
                        // check we have new, partfill, filled
                        switch (fill.OrderStatus)
                        {
                            case OrderStatus.NEW:
                                ord2States.osNew = true;
                                break;
                            case OrderStatus.PARTIALLY_FILLED:
                                ord2States.osPartFill = true;
                                break;
                            case OrderStatus.FILLED:
                                ord2States.odFilled = true;
                                break;
                        }
                    }

                }

                Assert.IsTrue(ord1States.osNew && ord1States.osPartFill && ord1States.odFilled);
                Assert.IsTrue(ord2States.osNew && ord2States.osPartFill && ord2States.odFilled);

            }
        }
示例#2
0
        public void TestPriceFileStartDriverInit()
        {
            // HPQ will just fill over time an order of 5 will fill 2,1,2
            _driver = new KTASimulator.KTASimulator();
            string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
            path = System.IO.Path.GetDirectoryName(path);
            _driver.Facade.AppPath = path;

            _priceHandler = new L1PriceSupport.MemoryPriceHandler();
            _driver.Facade.PriceHandler = _priceHandler;

            // Gets driver messages (fills, Accounts etc)
            _driver.Message += new KaiTrade.Interfaces.Message(OnMessage);
            (_driver as DriverBase.DriverBase).PriceUpdate += new K2ServiceInterface.PriceUpdate(this.PriceUpdate);

            _driver.Start("");

            // Test that S.DELL is set up as expected
            IProduct product = _driver.Facade.GetProductManager().GetProductMnemonic("S.DELL");
            _priceHandler.GetPXPublisher(product);

            _driver.OpenPrices(product, 0, DateTime.Now.Ticks.ToString());

            System.Threading.Thread.Sleep(110000);

            List<KaiTrade.Interfaces.IProduct> products = _driver.Facade.GetProductManager().GetProducts("KTSIM", "", "");
            Assert.AreEqual(13, products.Count);

            var pub = _priceHandler.GetPXPublisher(product);
        }