private void TryCompleteTick() { if (endOfTickData) { if (tickSync.SentSwtichBrokerState) { tickSync.ClearSwitchBrokerState("Finished."); } if (tickSync.SentOrderChange) { tickSync.RemoveOrderChange(); } } if (!endOfTickData && tickSync.Completed) { if (verbose) { log.Verbose("TryCompleteTick() Next Tick"); } tickSync.Clear(); } else if (tickSync.OnlyProcessPhysicalOrders) { if (trace) { log.Trace("Process physical orders - " + tickSync); } FillSimulator.StartTick(nextTick); if (FillSimulator.IsChanged) { FillSimulator.ProcessOrders(); } tickSync.RemoveProcessPhysicalOrders(); } else if (tickSync.OnlyReprocessPhysicalOrders || FillSimulator.IsChanged) { if (trace) { log.Trace("Reprocess physical orders - " + tickSync); } if (FillSimulator.IsChanged) { FillSimulator.ProcessOrders(); } if (tickSync.SentReprocessPhysicalOrders) { tickSync.ClearReprocessPhysicalOrders(); } } }
private bool DequeueTick() { LatencyManager.IncrementSymbolHandler(); var result = false; if (tickPool.AllocatedCount >= tickPool.Capacity / 2) { return(false); } while (!quoteSimulatorSupport.QuotePacketQueue.IsFull) { if (!reader.TryReadTick(temporaryTick)) { if (onEndTick != null) { onEndTick(id); } else { throw new ApplicationException("OnEndTick was null"); } queueTask.Stop(); return(result); } tickCounter++; if (isFirstTick) { currentTick.Inject(temporaryTick.Extract()); } else { currentTick.Inject(nextTick.Extract()); } isFirstTick = false; FillSimulator.StartTick(currentTick); nextTick.Inject(temporaryTick.Extract()); if (FillSimulator.IsChanged) { FillSimulator.ProcessOrders(); } if (trace) { log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond); } ProcessOnTickCallBack(); result = true; } return(result); }
private Yield SendPlayBackTick() { LatencyManager.IncrementSymbolHandler(); latency.TryUpdate(nextTick.lSymbol, nextTick.UtcTime.Internal); if (isFirstTick) { FillSimulator.StartTick(nextTick); isFirstTick = false; } else { if (FillSimulator.IsChanged) { FillSimulator.ProcessOrders(); } } return(Yield.DidWork.Invoke(ProcessOnTickCallBack)); }
public SimulateSymbolPlayback(FIXSimulatorSupport fixSimulatorSupport, QuoteSimulatorSupport quoteSimulatorSupport, string symbolString, Action <Message, SymbolInfo, Tick> onTick, Action <PhysicalFill, CreateOrChangeOrder> onPhysicalFill, Action <CreateOrChangeOrder, string> onRejectOrder) { log.Register(this); this.fixSimulatorSupport = fixSimulatorSupport; this.quoteSimulatorSupport = quoteSimulatorSupport; this.onTick = onTick; this.symbol = Factory.Symbol.LookupSymbol(symbolString); reader = Factory.TickUtil.TickFile(); this.symbolString = symbolString; reader.Initialize("Test\\MockProviderData", symbolString, TickFileMode.Read); fillSimulator = Factory.Utility.FillSimulator("FIX", Symbol, false, true, null); fillSimulator.EnableSyncTicks = SyncTicks.Enabled; FillSimulator.OnPhysicalFill = onPhysicalFill; FillSimulator.OnRejectOrder = onRejectOrder; }
public FIXServerSymbolHandler(FIXSimulatorSupport fixSimulatorSupport, bool isPlayBack, string symbolString, Func <Yield> onHeartbeat, Func <SymbolInfo, Tick, Yield> onTick, Action <PhysicalFill, int, int, int> onPhysicalFill, Action <PhysicalOrder, string> onRejectOrder) { this.fixSimulatorSupport = fixSimulatorSupport; this.isPlayBack = isPlayBack; this.onHeartbeat = onHeartbeat; this.onTick = onTick; this.symbol = Factory.Symbol.LookupSymbol(symbolString); reader = Factory.TickUtil.TickReader(); reader.Initialize("Test\\MockProviderData", symbolString); fillSimulator = Factory.Utility.FillSimulator("FIX", symbol, false); fillSimulator.OnPhysicalFill = onPhysicalFill; fillSimulator.OnRejectOrder = onRejectOrder; tickSync = SyncTicks.GetTickSync(symbol.BinaryIdentifier); tickSync.ForceClear(); queueTask = Factory.Parallel.Loop("FIXServerSymbol-" + symbolString, OnException, ProcessQueue); firstHearbeat = true; }
private Yield DequeueTick() { LatencyManager.IncrementSymbolHandler(); var result = Yield.NoWork.Repeat; if (isFirstTick) { if (!reader.TryReadTick(currentTick)) { return(result); } } else { currentTick.Inject(nextTick.Extract()); if (!reader.TryReadTick(nextTick)) { return(result); } } tickCounter++; if (isFirstTick) { playbackOffset = fixSimulatorSupport.GetRealTimeOffset(currentTick.UtcTime.Internal); prevTickTime = TimeStamp.UtcNow.Internal + 5000000; } currentTick.SetTime(new TimeStamp(GetNextUtcTime(currentTick.lUtcTime))); prevTickTime = currentTick.UtcTime.Internal; if (tickCounter > 10) { intervalTime = 1000; } isFirstTick = false; FillSimulator.StartTick(currentTick); if (trace) { log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond); } return(Yield.DidWork.Invoke(ProcessTick)); }
public SimulateSymbolSyncTicks(FIXSimulatorSupport fixSimulatorSupport, QuoteSimulatorSupport quoteSimulatorSupport, string symbolString, PartialFillSimulation partialFillSimulation, TimeStamp endTime, long id) { log.Register(this); this.id = id; this.fixSimulatorSupport = fixSimulatorSupport; this.quoteSimulatorSupport = quoteSimulatorSupport; this.onTick = quoteSimulatorSupport.OnTick; this.onEndTick = quoteSimulatorSupport.OnEndTick; this.PartialFillSimulation = partialFillSimulation; this.symbolString = symbolString; this.symbol = Factory.Symbol.LookupSymbol(symbolString); fillSimulator = Factory.Utility.FillSimulator("FIX", Symbol, false, true, null); fillSimulator.EnableSyncTicks = SyncTicks.Enabled; FillSimulator.OnPhysicalFill = fixSimulatorSupport.OnPhysicalFill; FillSimulator.OnRejectOrder = fixSimulatorSupport.OnRejectOrder; fillSimulator.PartialFillSimulation = partialFillSimulation; tickSync = SyncTicks.GetTickSync(Symbol.BinaryIdentifier); latency = new LatencyMetric("SimulateSymbolSyncTicks-" + symbolString.StripInvalidPathChars()); diagnoseMetric = Diagnose.RegisterMetric("Simulator"); if (debug) { log.Debug("Opening tick file for reading."); } reader = Factory.TickUtil.TickFile(); try { reader.Initialize("Test\\MockProviderData", symbolString, TickFileMode.Read); reader.EndTime = endTime; } catch (FileNotFoundException ex) { log.Info("File for symbol " + symbolString + " not found: " + ex.Message); } }
private void DequeueTick() { LatencyManager.IncrementSymbolHandler(); if (!reader.TryReadTick(temporaryTick)) { if (onEndTick == null) { throw new ApplicationException("OnEndTick was null"); } onEndTick(id); endOfTickData = true; queueTask.Resume(); if (debug) { log.Debug("End Of Tick Data."); } return; } tickCounter++; if (isFirstTick) { currentTick.Inject(temporaryTick.Extract()); } else { currentTick.Inject(nextTick.Extract()); } isFirstTick = false; FillSimulator.StartTick(currentTick); nextTick.Inject(temporaryTick.Extract()); tickSync.AddTick(nextTick); if (trace) { log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond); } ProcessOnTickCallBack(); }
public CreateOrChangeOrder GetOrderById(long clientOrderId) { return(FillSimulator.GetOrderById(clientOrderId)); }
public void CancelOrder(CreateOrChangeOrder order) { FillSimulator.OnCancelBrokerOrder(order); }
public void TryProcessAdjustments() { FillSimulator.ProcessAdjustments(); }