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 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 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 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."); }
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); } }