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