private void AdjustSessions() { foreach (var kvp in symbolMap) { string symbol = kvp.Key; SymbolProperties symbolProperties = kvp.Value; if (symbolProperties.TimeZone == null || symbolProperties.TimeZone.Length == 0) { continue; } if (symbolProperties.DisplayTimeZone == "Local" || symbolProperties.DisplayTimeZone == "UTC") { // Convert session times from Exchange to UTC. SymbolTimeZone timeZone = new SymbolTimeZone(symbolProperties); timeZone.SetExchangeTimeZone(); int startOffset = (int)timeZone.UtcOffset(new TimeStamp()); int endOffset = (int)timeZone.UtcOffset(new TimeStamp()); Elapsed utcSessionStart = symbolProperties.SessionStart - new Elapsed(0, 0, startOffset); Elapsed utcSessionEnd = symbolProperties.SessionEnd - new Elapsed(0, 0, endOffset); // Convert UTCI session times to either Local or UTC as chosen // by the DisplayTimeZone property. timeZone = new SymbolTimeZone(symbolProperties); startOffset = (int)timeZone.UtcOffset(new TimeStamp()); endOffset = (int)timeZone.UtcOffset(new TimeStamp()); symbolProperties.SessionStart = utcSessionStart + new Elapsed(0, 0, startOffset); symbolProperties.SessionEnd = utcSessionEnd + new Elapsed(0, 0, endOffset); } } }
public void SendFill(PacketFIX4_4 packetFIX) { if (debug) { log.Debug("SendFill( " + packetFIX.ClientOrderId + ")"); } var symbolInfo = Factory.Symbol.LookupSymbol(packetFIX.Symbol); var timeZone = new SymbolTimeZone(symbolInfo); if (GetSymbolStatus(symbolInfo)) { var algorithm = GetAlgorithm(symbolInfo.BinaryIdentifier); var order = GetPhysicalOrder(packetFIX.ClientOrderId); var fillPosition = packetFIX.LastQuantity * SideToSign(packetFIX.Side); TimeStamp executionTime; if (UseLocalFillTime) { executionTime = TimeStamp.UtcNow; } else { executionTime = new TimeStamp(packetFIX.TransactionTime); } var configTime = executionTime; configTime.AddSeconds(timeZone.UtcOffset(executionTime)); var fill = Factory.Utility.PhysicalFill(fillPosition, packetFIX.LastPrice, configTime, executionTime, order, false); if (debug) { log.Debug("Sending physical fill: " + fill); } algorithm.ProcessFill(fill, packetFIX.OrderQuantity, packetFIX.CumulativeQuantity, packetFIX.LeavesQuantity); } }
public void SendFill(MessageFIX4_2 packetFIX) { var clientOrderId = 0L; long.TryParse(packetFIX.ClientOrderId, out clientOrderId); var originalClientOrderId = 0L; long.TryParse(packetFIX.ClientOrderId, out originalClientOrderId); if (debug) { log.Debug("SendFill( " + packetFIX.ClientOrderId + ")"); } var symbolInfo = Factory.Symbol.LookupSymbol(packetFIX.Symbol); var timeZone = new SymbolTimeZone(symbolInfo); SymbolAlgorithm algorithm; if (!TryGetAlgorithm(symbolInfo.BinaryIdentifier, out algorithm)) { log.Info("Fill received but OrderAlgorithm not found for " + symbolInfo + ". Ignoring."); return; } var fillPosition = packetFIX.LastQuantity * SideToSign(packetFIX.Side); if (GetSymbolStatus(symbolInfo)) { CreateOrChangeOrder order; if (OrderStore.TryGetOrderById(clientOrderId, out order)) { TimeStamp executionTime; if (UseLocalFillTime) { executionTime = TimeStamp.UtcNow; } else { executionTime = new TimeStamp(packetFIX.TransactionTime); } var configTime = executionTime; configTime.AddSeconds(timeZone.UtcOffset(executionTime)); var fill = Factory.Utility.PhysicalFill(fillPosition, packetFIX.LastPrice, configTime, executionTime, order.BrokerOrder, false, packetFIX.OrderQuantity, packetFIX.CumulativeQuantity, packetFIX.LeavesQuantity, IsRecovered, true); if (debug) { log.Debug("Sending physical fill: " + fill); } algorithm.OrderAlgorithm.ProcessFill(fill); algorithm.OrderAlgorithm.ProcessOrders(); TrySendStartBroker(symbolInfo, "position sync on fill"); } else { algorithm.OrderAlgorithm.IncreaseActualPosition(fillPosition); log.Notice("Fill id " + packetFIX.ClientOrderId + " not found. Must have been a manual trade."); if (SyncTicks.Enabled) { var tickSync = SyncTicks.GetTickSync(symbolInfo.BinaryIdentifier); tickSync.RemovePhysicalFill(packetFIX.ClientOrderId); } } } }
// This method is for performance. It only update the UTC offset on weekend boundaries. private long GetUtcOffset(TimeStamp tickTime) { if (tickTime.Internal >= nextOffsetUpdate.Internal) { if (timeZone == null) { timeZone = new SymbolTimeZone(symbol); timeZone.SetExchangeTimeZone(); } utcOffset = timeZone.UtcOffset(tickTime); nextOffsetUpdate = utcTime; int dayOfWeek = nextOffsetUpdate.GetDayOfWeek(); nextOffsetUpdate.AddDays(7 - dayOfWeek); nextOffsetUpdate.SetDate(nextOffsetUpdate.Year, nextOffsetUpdate.Month, nextOffsetUpdate.Day); } return(utcOffset); }
/// <inheritdoc/> public void SetTime(TimeStamp utcTime) { binary.UtcTime = utcTime.Internal; if (utcTime.Internal >= nextUtcOffsetUpdate.Internal) { if (timeZone == null) { if (binary.Symbol == 0) { throw new ApplicationException("Please call SetSymbol() prior to SetTime() method."); } SymbolInfo symbol = Factory.Symbol.LookupSymbol(binary.Symbol); timeZone = new SymbolTimeZone(symbol); } utcOffset = timeZone.UtcOffset(UtcTime); nextUtcOffsetUpdate = utcTime; int dayOfWeek = nextUtcOffsetUpdate.GetDayOfWeek(); nextUtcOffsetUpdate.AddDays(7 - dayOfWeek); nextUtcOffsetUpdate.SetDate(nextUtcOffsetUpdate.Year, nextUtcOffsetUpdate.Month, nextUtcOffsetUpdate.Day); } localTime = new TimeStamp(binary.UtcTime); localTime.AddSeconds(utcOffset); }