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"); } }
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."); } } }
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)); } }
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); } }
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."); } } }
public void ZAutoReconnection() { using (VerifyFeed verify = Factory.Utility.VerifyFeed()) using (Provider provider = ProviderFactory()) { verify.PauseSeconds = secondsDelay; if (debug) { log.Debug("===ZAutoReconnection==="); } provider.SendEvent(verify, null, EventType.Connect, null); provider.SendEvent(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue)); VerifyConnected(verify); if (debug) { log.Debug("===ClearOrders==="); } 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; Assert.GreaterOrEqual(bid, 0, "Bid"); Assert.GreaterOrEqual(ask, 0, "Ask"); if (debug) { log.Debug("===Create a Buy and Sell Limit ==="); } CreateLogicalEntry(OrderType.BuyLimit, bid - 280 * symbol.MinimumTick, 1); CreateLogicalEntry(OrderType.SellLimit, ask + 340 * symbol.MinimumTick, 1); SendOrders(provider, verify, secondsDelay); ClearOrders(0); ClearPosition(provider, verify, secondsDelay); } }
public void VerifyConnected(VerifyFeed verify) { var expectedBrokerState = BrokerState.Connected; var expectedSymbolState = SymbolState.RealTime; var actualState = verify.VerifyState(expectedBrokerState, expectedSymbolState, 600); Assert.IsTrue(actualState, "Expected " + expectedBrokerState + " and " + expectedSymbolState); }
private void ClearPositionInternal(Provider provider, VerifyFeed verify, int expectedPosition) { if (SyncTicks.Enabled) { tickSync.AddPositionChange(); } provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, expectedPosition, orders)); }
// public LogicalOrder CreateEntry(OrderType type, double price, int size, int strategyId) { // var logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.StrategyId = strategyId; // logical.StrategyPosition = 0; // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Entry; // logical.Type = type; // logical.Price = price; // logical.Positions = size * lotSize; // orders.AddLast(logical); // return logical; // } // public LogicalOrder CreateLogicalEntry(OrderType type, double price, int size) { // LogicalOrder logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Entry; // logical.Type = type; // logical.Price = price; // logical.Positions = size * lotSize; // orders.AddLast(logical); // return logical; // } // public LogicalOrder CreateLogicalExit(OrderType type, double price) { // LogicalOrder logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Exit; // logical.Type = type; // logical.Price = price; // orders.AddLast(logical); // return logical; // } public void SendOrders(Provider provider, VerifyFeed verify, int desiredPosition, int secondsDelay) { if (SyncTicks.Enabled) { tickSync.AddPositionChange(); } provider.SendEvent(verify, symbol, (int)EventType.PositionChange, new PositionChangeDetail(symbol, desiredPosition, orders)); }
public void TestMarketOrder() { using (VerifyFeed verify = Factory.Utility.VerifyFeed(symbol)) using (Agent provider = ProviderFactory()) { verify.PauseSeconds = secondsDelay; provider.SendEvent(new EventItem(verify, null, EventType.Connect, null)); if (debug) { log.Debug("===TestMarketOrder==="); } provider.SendEvent(new EventItem(verify, symbol, EventType.StartSymbol, new StartSymbolDetail(TimeStamp.MinValue))); VerifyConnected(verify); ClearOrders(0); ClearPosition(provider, verify, secondsDelay); var desiredPosition = 2 * LotSize; log.Notice("Sending 1"); CreateEntry(strategy, OrderType.BuyMarket, 0.0, desiredPosition, 0); var actualPosition = verify.VerifyPosition(desiredPosition, secondsDelay, () => { SendOrders(provider, verify, 0, 30); }); Assert.AreEqual(desiredPosition, actualPosition, "position"); desiredPosition = 0; log.Warn("Sending 2"); ClearOrders(0); CreateExit(strategy, OrderType.SellMarket, 0.0, actualPosition); actualPosition = verify.VerifyPosition(desiredPosition, secondsDelay, () => { SendOrders(provider, verify, actualPosition, 30); }); Assert.AreEqual(desiredPosition, actualPosition, "position"); desiredPosition = 2 * LotSize; log.Warn("Sending 3"); ClearOrders(0); CreateEntry(strategy, OrderType.BuyMarket, 0.0, desiredPosition, actualPosition); actualPosition = verify.VerifyPosition(desiredPosition, secondsDelay, () => { SendOrders(provider, verify, actualPosition, 30); }); desiredPosition = 2 * LotSize; log.Warn("Sending 4"); ClearOrders(0); CreateEntry(strategy, OrderType.BuyMarket, 0.0, desiredPosition, actualPosition); actualPosition = verify.VerifyPosition(desiredPosition, secondsDelay, () => { SendOrders(provider, verify, actualPosition, 30); }); Assert.AreEqual(desiredPosition, actualPosition, "position"); desiredPosition = 0; log.Warn("Sending 5"); ClearOrders(0); CreateExit(strategy, OrderType.SellMarket, 0.0, actualPosition); actualPosition = verify.VerifyPosition(desiredPosition, secondsDelay, () => { SendOrders(provider, verify, actualPosition, 30); }); Assert.AreEqual(desiredPosition, actualPosition, "position"); } }
public void ClearPosition(Agent provider, VerifyFeed verify, int secondsDelay) { var expectedPosition = 0; var actualPosition = verify.VerifyPosition(expectedPosition, secondsDelay, () => { ClearPositionInternal(provider, verify, expectedPosition); }); Assert.AreEqual(expectedPosition, actualPosition, "Starting position."); }
private void ClearPositionInternal(Agent provider, VerifyFeed verify, int expectedPosition) { if (SyncTicks.Enabled) { tickSync.AddPositionChange("Test"); } var strategyPositions = new ActiveList <StrategyPosition>(); provider.SendEvent(new EventItem(verify, symbol, EventType.PositionChange, new PositionChangeDetail(symbol, expectedPosition, orders, strategyPositions, TimeStamp.UtcNow.Internal, 1L))); }
// public LogicalOrder CreateEntry(OrderType type, double price, int size, int strategyId) { // var logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.StrategyId = strategyId; // logical.StrategyPosition = 0; // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Entry; // logical.Type = type; // logical.Price = price; // logical.Positions = size * lotSize; // orders.AddLast(logical); // return logical; // } // public LogicalOrder CreateLogicalEntry(OrderType type, double price, int size) { // LogicalOrder logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Entry; // logical.Type = type; // logical.Price = price; // logical.Positions = size * lotSize; // orders.AddLast(logical); // return logical; // } // public LogicalOrder CreateLogicalExit(OrderType type, double price) { // LogicalOrder logical = Factory.Engine.LogicalOrder(symbol,strategy); // logical.Status = OrderStatus.Active; // logical.TradeDirection = TradeDirection.Exit; // logical.Type = type; // logical.Price = price; // orders.AddLast(logical); // return logical; // } public void SendOrders(Agent provider, VerifyFeed verify, int desiredPosition, int secondsDelay) { if (SyncTicks.Enabled) { tickSync.AddPositionChange("Test"); } var strategyPositions = new ActiveList <StrategyPosition>(); provider.SendEvent(new EventItem(verify, symbol, EventType.PositionChange, new PositionChangeDetail(symbol, desiredPosition, orders, strategyPositions, TimeStamp.UtcNow.Internal, 1L))); }
public void CreateProvider(bool inProcessFlag) { if (inProcessFlag) { provider = new eSInterface(); } else { provider = Factory.Provider.ProviderProcess("127.0.0.1", 6492, "eSignalProviderService.exe"); } verify = new VerifyFeed(); provider.Start(verify); }
public void CreateProvider() { if (inProcessFlag) { provider = new MbtInterface(); } else { provider = Factory.Provider.ProviderProcess("127.0.0.1", 6492, "MBTradingService.exe"); } verify = new VerifyFeed(); provider.SendEvent(verify, null, (int)EventType.Connect, null); }
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)); } }
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); } }
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); } }
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); } }
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); } }
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)); } }