Example #1
0
        public void TestSpecificLogicalOrder()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = ProviderFactory()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, EventType.Connect));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    VerifyConnected(verify);
                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);

                    var expectedTicks = 2;
//	            var count = verify.Verify(expectedTicks,assertTick,symbol,secondsDelay);
//	            Assert.GreaterOrEqual(count,expectedTicks,"tick count");

                    CreateEntry(strategy, OrderType.BuyLimit, 503.72, 1, 0);

                    var count = verify.Verify(expectedTicks, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, expectedTicks, "tick count");

                    count = verify.Verify(expectedTicks, assertTick, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, expectedTicks, "tick count");
                }
        }
Example #2
0
        public void TestPositionChange()
        {
            if (debug)
            {
                log.Debug("===DemoConnectionTest===");
            }
            provider.SendEvent(verify, symbol, (int)EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue));
            long count = verify.Verify(2, AssertTick, symbol, 25);

            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, 150, null));
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
            provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, 0, null));
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, 100, null));
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, 0, null));
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
        }
Example #3
0
        public virtual void TestPositionSyncAndStopExits()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = ProviderFactory()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, null, EventType.Connect, null));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    VerifyConnected(verify);

                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    TickIO lastTick = verify.LastTick;
                    double bid      = lastTick.IsTrade ? lastTick.Price : lastTick.Bid;
                    double ask      = lastTick.IsTrade ? lastTick.Price : lastTick.Ask;

                    int strategyPosition = 0;
                    CreateExit(strategy, OrderType.SellStop, bid - 180 * symbol.MinimumTick, strategyPosition);
                    LogicalOrder exitBuyStop = CreateExit(strategy, OrderType.BuyStop, ask + 540 * symbol.MinimumTick, strategyPosition);
                    var          count       = verify.Verify(2, assertTick, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, 2, "tick count");

                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    var expectedTicks = 1;
                    count = verify.Wait(expectedTicks, secondsDelay);
                }
        }
Example #4
0
        public void TestSeperateProcess()
        {
            if (!IsTestSeperate)
            {
                return;
            }
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = CreateProvider()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, null, EventType.Connect, null));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    if (debug)
                    {
                        log.Debug("===VerifyState===");
                    }
                    VerifyConnected(verify);
                    if (debug)
                    {
                        log.Debug("===VerifyFeed===");
                    }
                    long count = verify.Verify(2, assertTick, 25);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    Process[] processes = Process.GetProcessesByName(AssemblyName);
                    Assert.AreEqual(1, processes.Length, "Number of provider service processes.");

                    provider.SendEvent(new EventItem(verify, EventType.Disconnect));
                    provider.SendEvent(new EventItem(verify, EventType.Terminate));
                }
        }
Example #5
0
        public void TestFIXPositionFilterSell()
        {
            var expectedPosition = 0;
            var sizeIncrease     = 2;
            int secondsDelay     = 3;

            using (VerifyFeed verify = Factory.Utility.VerifyFeed())
                using (Provider provider = ProviderFactory()) {
                    provider.SendEvent(verify, null, (int)EventType.Connect, null);
                    provider.SendEvent(verify, symbol, (int)EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue));
                    VerifyConnected(verify);
                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    long count = verify.Verify(2, assertTick, symbol, 25);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    var actualPosition = 0;
                    while (true)
                    {
                        ClearOrders(0);
                        var strategy = Factory.Utility.Strategy();
                        CreateEntry(strategy, OrderType.SellMarket, 0.0, sizeIncrease, actualPosition);
                        SendOrders(provider, verify, actualPosition, 30);
                        expectedPosition -= sizeIncrease;
                        actualPosition   += verify.VerifyPosition(sizeIncrease, symbol, secondsDelay);
                        Assert.AreEqual(expectedPosition, actualPosition, "Increasing position.");
                    }
                }
        }
Example #6
0
        public void TestFIXPositionFilterSell()
        {
            var expectedPosition = 0;

            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = ProviderFactory()) {
                    provider.SendEvent(new EventItem(verify, EventType.Connect));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    VerifyConnected(verify);
                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    long count = verify.Verify(2, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    var actualPosition = 0;
                    var strategy       = Factory.Utility.Strategy();
                    strategy.Context = new MockContext();
                    while (true)
                    {
                        ClearOrders(0);
                        CreateChange(strategy, OrderType.SellMarket, 0.0, sizeIncrease, actualPosition);
                        SendOrders(provider, verify, actualPosition, 30);
                        expectedPosition -= sizeIncrease;
                        actualPosition    = verify.VerifyPosition(sizeIncrease, secondsDelay);
                        Assert.AreEqual(expectedPosition, actualPosition, "Increasing position.");
                    }
                }
        }
Example #7
0
        public void DemoStopSymbolTest()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = CreateProvider()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, null, EventType.Connect, null));
                    log.Info("===DemoStopSymbolTest===");
                    if (debug)
                    {
                        log.Debug("===StartSymbol===");
                    }
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    if (debug)
                    {
                        log.Debug("===VerifyState===");
                    }
                    VerifyConnected(verify);
                    if (debug)
                    {
                        log.Debug("===VerifyFeed===");
                    }
                    long count = verify.Verify(2, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    if (debug)
                    {
                        log.Debug("===StopSymbol===");
                    }
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StopSymbol));

                    // Wait for it to switch out of real time or historical mode.
                    var expectedBrokerState = BrokerState.Disconnected;
                    var expectedSymbolState = SymbolState.None;
                    var actualState         = verify.VerifyState(expectedBrokerState, expectedSymbolState, 25000);
                    Assert.IsTrue(actualState, "after receiving a StopSymbol event, if your provider plugin was sending ticks then it must return either respond with an EndHistorical or EndRealTime event. If it has already sent one of those prior to the StopSymbol, then no reponse is required.");

                    // Clean out and ignore any extra ticks.
                    count = verify.Verify(1000, assertTick, secondsDelay);
                    Assert.Less(count, 1000, "your provider plugin must not send any more ticks after receiving a StopSymbol event.");

                    // Make sure we don't get any more ticks.
                    count = verify.Verify(0, assertTick, secondsDelay);
                    Assert.AreEqual(0, count, "your provider plugin must not send any more ticks after receiving a StopSymbol event.");

                    provider.SendEvent(new EventItem(verify, EventType.Disconnect));
                    provider.SendEvent(new EventItem(verify, EventType.Terminate));
                }
        }
Example #8
0
        public void DemoConnectionTest()
        {
            if (debug)
            {
                log.Debug("===DemoConnectionTest===");
            }
            if (debug)
            {
                log.Debug("===StartSymbol===");
            }
            provider.SendEvent(verify, symbol, (int)EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue));
            if (debug)
            {
                log.Debug("===VerifyFeed===");
            }
            long count = verify.Verify(AssertTick, symbol, 25);

            Assert.GreaterOrEqual(count, 2, "tick count");
        }
Example #9
0
        public void TestLogicalStopOrders()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed())
                using (Provider provider = ProviderFactory()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(verify, null, (int)EventType.Connect, null);
                    provider.SendEvent(verify, symbol, (int)EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue));
                    VerifyConnected(verify);

                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
//				var expectedTicks = 1;
//	            var count = verify.Wait(symbol,expectedTicks,secondsDelay);
//	            Assert.GreaterOrEqual(count,expectedTicks,"at least one tick");
                    TickIO lastTick = verify.LastTick;
                    double bid      = lastTick.IsTrade ? lastTick.Price : lastTick.Bid;
                    double ask      = lastTick.IsTrade ? lastTick.Price : lastTick.Ask;

                    int          strategyPosition = 0;
                    LogicalOrder enterBuyStop     = CreateEntry(strategy, OrderType.BuyStop, bid + 420 * symbol.MinimumTick, 2, strategyPosition);
                    LogicalOrder enterSellStop    = CreateEntry(strategy, OrderType.SellStop, bid - 400 * symbol.MinimumTick, 2, strategyPosition);
                    CreateExit(strategy, OrderType.SellStop, bid - 180 * symbol.MinimumTick, strategyPosition);
                    LogicalOrder exitBuyStop = CreateExit(strategy, OrderType.BuyStop, ask + 540 * symbol.MinimumTick, strategyPosition);
                    var          count       = verify.Verify(2, assertTick, symbol, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, 2, "tick count");

                    ClearOrders(0);
                    enterSellStop.Price = bid - 360 * symbol.MinimumTick;
                    enterBuyStop.Price  = ask + 380 * symbol.MinimumTick;
                    orders.AddLast(enterBuyStop);
                    orders.AddLast(enterSellStop);
                    orders.AddLast(exitBuyStop);
                    count = verify.Verify(2, assertTick, symbol, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, 2, "tick count");

//				ClearOrders(0);
//				ClearPosition(provider,verify,secondsDelay);
                }
        }
Example #10
0
        public void TestLogicalLimitOrders()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = ProviderFactory()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, null, EventType.Connect, null));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    VerifyConnected(verify);

                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    TickIO       lastTick         = verify.LastTick;
                    double       bid              = lastTick.IsTrade ? lastTick.Price : lastTick.Bid;
                    double       ask              = lastTick.IsTrade ? lastTick.Price : lastTick.Ask;
                    int          strategyPosition = 0;
                    LogicalOrder enterBuyLimit    = CreateEntry(strategy, OrderType.BuyLimit, bid - 280 * symbol.MinimumTick, 2, strategyPosition);
                    LogicalOrder enterSellLimit   = CreateEntry(strategy, OrderType.SellLimit, ask + 340 * symbol.MinimumTick, 2, strategyPosition);
                    LogicalOrder exitSellLimit    = CreateExit(strategy, OrderType.SellLimit, ask + 380 * symbol.MinimumTick, strategyPosition);
                    CreateExit(strategy, OrderType.SellLimit, ask + 400 * symbol.MinimumTick, strategyPosition);
                    CreateExit(strategy, OrderType.BuyLimit, bid - 150 * symbol.MinimumTick, strategyPosition);
                    LogicalOrder exitBuyStop = CreateExit(strategy, OrderType.BuyStop, ask + 540 * symbol.MinimumTick, strategyPosition);
                    var          count       = verify.Verify(2, assertTick, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, 2, "tick count");

                    ClearOrders(0);
                    enterBuyLimit.Price  = bid - 260 * symbol.MinimumTick;
                    enterSellLimit.Price = ask + 280 * symbol.MinimumTick;
                    orders.AddLast(enterBuyLimit);
                    orders.AddLast(enterSellLimit);
                    orders.AddLast(exitSellLimit);
                    count = verify.Verify(2, assertTick, secondsDelay, () => {
                        SendOrders(provider, verify, 0, secondsDelay);
                    });
                    Assert.GreaterOrEqual(count, 2, "tick count");

                    ClearOrders(0);
                    //ClearPosition(provider,verify,secondsDelay);
                    count = verify.Wait(1, secondsDelay);
                }
        }
Example #11
0
        public void TestSingleOrder()
        {
            if (debug)
            {
                log.Debug("===DemoConnectionTest===");
            }
            provider.StartSymbol(verify, symbol, TimeStamp.MinValue);
            provider.PositionChange(verify, symbol, 150, null);
            long count = verify.Verify(2, AssertTick, symbol, 25);

            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.PositionChange(verify, symbol, 0, null);
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.PositionChange(verify, symbol, 100, null);
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
            Thread.Sleep(500);
            provider.PositionChange(verify, symbol, 0, null);
            count = verify.Verify(2, AssertTick, symbol, 25);
            Assert.GreaterOrEqual(count, 2, "tick count");
        }
Example #12
0
        public void TestFIXPretradeOrderFilterSell()
        {
            var expectedPosition = 0;
            int secondsDelay     = 3;

            using (VerifyFeed verify = Factory.Utility.VerifyFeed())
                using (Provider provider = ProviderFactory()) {
                    provider.SendEvent(verify, null, (int)EventType.Connect, null);
                    provider.SendEvent(verify, symbol, (int)EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue));
                    VerifyConnected(verify);
                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    long count = verify.Verify(2, assertTick, symbol, 25);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    expectedPosition = -10;
                    var strategy = Factory.Utility.Strategy();
                    CreateEntry(strategy, OrderType.SellMarket, 0.0, (int)Math.Abs(expectedPosition), 0);
                    SendOrders(provider, verify, 0, 30);
                    var position = verify.VerifyPosition(expectedPosition, symbol, secondsDelay);
                    Assert.AreEqual(expectedPosition, position, "Increasing position.");
                    Thread.Sleep(2000);
                }
        }
Example #13
0
        public void TestFIXPretradeOrderFilterSell()
        {
            var expectedPosition = 0;

            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = ProviderFactory()) {
                    provider.SendEvent(new EventItem(verify, EventType.Connect));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    VerifyConnected(verify);
                    ClearOrders(0);
                    ClearPosition(provider, verify, secondsDelay);
                    long count = verify.Verify(2, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    expectedPosition = -overSizeIncrease;
                    var strategy = Factory.Utility.Strategy();
                    strategy.Context = new MockContext();
                    CreateChange(strategy, OrderType.SellMarket, 0.0, (int)Math.Abs(expectedPosition), 0);
                    SendOrders(provider, verify, 0, 30);
                    var position = verify.VerifyPosition(expectedPosition, secondsDelay);
                    Assert.AreEqual(expectedPosition, position, "Increasing position.");
                    Thread.Sleep(2000);
                }
        }
Example #14
0
        public void DemoReConnectionTest()
        {
            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = CreateProvider()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, EventType.Connect));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    if (debug)
                    {
                        log.Debug("===VerifyState===");
                    }
                    VerifyConnected(verify);
                    long count = verify.Verify(2, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    provider.SendEvent(new EventItem(verify, EventType.Disconnect));
                    provider.SendEvent(new EventItem(verify, EventType.Terminate));
                }
//			Thread.Sleep(2000);
            log.Info("Starting to reconnect---------\n");

            using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol))
                using (Agent provider = CreateProvider()) {
                    verify.PauseSeconds = secondsDelay;
                    provider.SendEvent(new EventItem(verify, null, EventType.Connect, null));
                    provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)));
                    if (debug)
                    {
                        log.Debug("===VerifyState===");
                    }
                    VerifyConnected(verify);
                    long count = verify.Verify(2, assertTick, secondsDelay);
                    Assert.GreaterOrEqual(count, 2, "tick count");
                    provider.SendEvent(new EventItem(verify, EventType.Disconnect));
                    provider.SendEvent(new EventItem(verify, EventType.Terminate));
                }
        }
Example #15
0
        public void DemoConnectionTest()
        {
            if (debug)
            {
                log.Debug("===DemoConnectionTest===");
            }
            if (debug)
            {
                log.Debug("===StartSymbol===");
            }
            provider.StartSymbol(verify, symbol, TimeStamp.MinValue);
            if (debug)
            {
                log.Debug("===VerifyFeed===");
            }
            long count = verify.Verify(2, AssertTick, symbol, 25);

            Assert.GreaterOrEqual(count, 2, "tick count");
            provider.StopSymbol(verify, symbol);
        }