public void DayTimeInForceForexOrderAfter5PMExpiresAt5PMNextDay() { // set time to 6:00:00 PM (NY time) var utcTime = new DateTime(2018, 4, 25, 18, 0, 0).ConvertToUtc(TimeZones.NewYork); var handler = new DayTimeInForceHandler(); var security = new Forex( SecurityExchangeHoursTests.CreateForexSecurityExchangeHours(), new Cash(CashBook.AccountCurrency, 0, 1m), new SubscriptionDataConfig(typeof(QuoteBar), Symbols.EURUSD, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, true, true), SymbolProperties.GetDefault(CashBook.AccountCurrency)); var localTimeKeeper = new LocalTimeKeeper(utcTime, TimeZones.NewYork); security.SetLocalTimeKeeper(localTimeKeeper); var orderProperties = new OrderProperties { TimeInForce = TimeInForce.Day }; var order = new LimitOrder(Symbols.EURUSD, 10, 100, utcTime, "", orderProperties); Assert.IsFalse(handler.IsOrderExpired(security, order)); var fill1 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.PartiallyFilled, OrderDirection.Buy, order.LimitPrice, 3, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); var fill2 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.Filled, OrderDirection.Buy, order.LimitPrice, 7, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); // set time to midnight (NY time) localTimeKeeper.UpdateTime(utcTime.AddHours(6)); Assert.IsFalse(handler.IsOrderExpired(security, order)); // set time to 4:59:59 PM next day (NY time) localTimeKeeper.UpdateTime(utcTime.AddHours(23).AddSeconds(-1)); Assert.IsFalse(handler.IsOrderExpired(security, order)); // set time to 5:00:00 PM next day (NY time) localTimeKeeper.UpdateTime(utcTime.AddHours(23)); Assert.IsTrue(handler.IsOrderExpired(security, order)); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); }
public void DayTimeInForceEquityOrderExpiresAtMarketClose() { var utcTime = new DateTime(2018, 4, 27, 10, 0, 0).ConvertToUtc(TimeZones.NewYork); var handler = new DayTimeInForceHandler(); var security = new Equity( SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), new SubscriptionDataConfig(typeof(TradeBar), Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, true, true), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)); var localTimeKeeper = new LocalTimeKeeper(utcTime, TimeZones.NewYork); security.SetLocalTimeKeeper(localTimeKeeper); var orderProperties = new OrderProperties { TimeInForce = TimeInForce.Day }; var order = new LimitOrder(Symbols.SPY, 10, 100, utcTime, "", orderProperties); Assert.IsFalse(handler.IsOrderExpired(security, order)); var fill1 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.PartiallyFilled, OrderDirection.Buy, order.LimitPrice, 3, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); var fill2 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.Filled, OrderDirection.Buy, order.LimitPrice, 7, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); localTimeKeeper.UpdateTime(utcTime.AddHours(6).AddSeconds(-1)); Assert.IsFalse(handler.IsOrderExpired(security, order)); localTimeKeeper.UpdateTime(utcTime.AddHours(6)); Assert.IsTrue(handler.IsOrderExpired(security, order)); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); }
public void DayTimeInForceCryptoOrderExpiresAtMidnight() { var utcTime = new DateTime(2018, 4, 27, 10, 0, 0); var handler = new DayTimeInForceHandler(); var security = new Crypto( SecurityExchangeHours.AlwaysOpen(TimeZones.Utc), new Cash(CashBook.AccountCurrency, 0, 1m), new SubscriptionDataConfig(typeof(QuoteBar), Symbols.BTCUSD, Resolution.Minute, TimeZones.Utc, TimeZones.Utc, true, true, true), SymbolProperties.GetDefault(CashBook.AccountCurrency)); var localTimeKeeper = new LocalTimeKeeper(utcTime, TimeZones.Utc); security.SetLocalTimeKeeper(localTimeKeeper); var orderProperties = new OrderProperties { TimeInForce = TimeInForce.Day }; var order = new LimitOrder(Symbols.BTCUSD, 10, 100, utcTime, "", orderProperties); Assert.IsFalse(handler.IsOrderExpired(security, order)); var fill1 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.PartiallyFilled, OrderDirection.Buy, order.LimitPrice, 3, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); var fill2 = new OrderEvent(order.Id, order.Symbol, utcTime, OrderStatus.Filled, OrderDirection.Buy, order.LimitPrice, 7, 0); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); localTimeKeeper.UpdateTime(utcTime.AddHours(14).AddSeconds(-1)); Assert.IsFalse(handler.IsOrderExpired(security, order)); localTimeKeeper.UpdateTime(utcTime.AddHours(14)); Assert.IsTrue(handler.IsOrderExpired(security, order)); Assert.IsTrue(handler.IsFillValid(security, order, fill1)); Assert.IsTrue(handler.IsFillValid(security, order, fill2)); }