public void StartSymbol(Receiver receiver, SymbolInfo symbol, object eventDetail) { TickIO tickIO = Factory.TickUtil.TickIO(); tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); tickIO.SetTime(new TimeStamp(2000, 1, 1)); tickIO.SetQuote(100D, 100D); while (!receiver.OnEvent(symbol, (int)EventType.StartHistorical, symbol)) { Factory.Parallel.Yield(); } var binaryBox = tickPool.Create(); binaryBox.TickBinary = tickIO.Extract(); while (!receiver.OnEvent(symbol, (int)EventType.Tick, binaryBox)) { Factory.Parallel.Yield(); } tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); tickIO.SetTime(new TimeStamp(2000, 1, 2)); tickIO.SetQuote(101D, 101D); binaryBox = tickPool.Create(); binaryBox.TickBinary = tickIO.Extract(); while (!receiver.OnEvent(symbol, (int)EventType.Tick, binaryBox)) { Factory.Parallel.Yield(); } while (!receiver.OnEvent(symbol, (int)EventType.EndHistorical, symbol)) { Factory.Parallel.Yield(); } }
public void SendQuote() { if (isQuoteInitialized || VerifyQuote()) { if (isRunning) { if (Symbol.QuoteType != QuoteType.Level1) { if (!errorWrongLevel1Type) { log.Error("Received " + QuoteType.Level1 + " quote but " + Symbol + " is configured for QuoteType = " + Symbol.QuoteType + " in the symbol dictionary."); errorWrongLevel1Type = true; } } else if (Bid == 0D) { log.Error("Found quote bid was set to " + Bid + " so skipping this tick."); return; } else if (Ask == 0D) { log.Error("Found quote ask was set to " + Ask + " so skipping this tick."); return; } else { tickIO.Initialize(); tickIO.SetSymbol(Symbol.BinaryIdentifier); tickIO.SetTime(Time); tickIO.SetQuote(Bid, Ask, (short)BidSize, (short)AskSize); var box = tickPool.Create(tickPoolCallerId); var tickId = box.TickBinary.Id; box.TickBinary = tickIO.Extract(); box.TickBinary.Id = tickId; quotesLatency.TryUpdate(box.TickBinary.Symbol, box.TickBinary.UtcTime); var eventItem = new EventItem(symbol, EventType.Tick, box); agent.SendEvent(eventItem); Interlocked.Increment(ref tickCount); if (Diagnose.TraceTicks) { Diagnose.AddTick(diagnoseMetric, ref box.TickBinary); } if (trace) { log.Trace("Sent quote for " + Symbol + ": " + tickIO); } } } } }
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); }
public void SendQuote() { if (isInitialized) { if (symbol.QuoteType == QuoteType.Level1) { tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); tickIO.SetTime(TimeStamp.UtcNow); tickIO.SetQuote(Bid, Ask, (ushort)BidSize, (ushort)AskSize); TickBinary binary = tickIO.Extract(); receiver.OnSend(ref binary); } } else { VerifyInitialized(); } }
public bool TryAdd(TickIO tickIO) { if (!isInitialized) { throw new ApplicationException("Please initialized TickWriter first."); } TickBinary tick = tickIO.Extract(); return(writeQueue.TryEnqueue(ref tick)); }
public void SendQuote() { if (isQuoteInitialized || VerifyQuote()) { if (isRunning) { if (symbol.QuoteType != QuoteType.Level1) { if (!errorWrongLevel1Type) { log.Error("Received " + QuoteType.Level1 + " quote but " + symbol + " is configured for QuoteType = " + symbol.QuoteType + " in the symbol dictionary."); errorWrongLevel1Type = true; } } else if (Bid == 0D) { log.Error("Found quote bid was set to " + Bid + " so skipping this tick."); return; } else if (Ask == 0D) { log.Error("Found quote ask was set to " + Ask + " so skipping this tick."); return; } else { tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); tickIO.SetTime(Time); tickIO.SetQuote(Bid, Ask, (short)BidSize, (short)AskSize); var box = tickPool.Create(); box.TickBinary = tickIO.Extract(); receiver.OnEvent(symbol, (int)EventType.Tick, box); if (trace) { log.Trace("Sent tick for " + symbol + ": " + tickIO); } } } } }
private void SendTick() { lastTick.Copy(tick, tick.ContentMask); TickBinary binary = new TickBinary(); binary = tick.Extract(); lastChangeTime = Environment.TickCount; receiver.OnEvent(symbol, (int)EventType.Tick, binary); if (debug) { log.Debug("Sent Tick: " + tick); } }
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 bool TryAdd(TickIO tickIO) { if (!isInitialized) { throw new ApplicationException("Please initialized TickWriter first."); } TickBinary tick = tickIO.Extract(); var result = writeQueue.TryEnqueue(ref tick); if (result) { Interlocked.Increment(ref appendCounter); } return(result); }
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)); }
protected override void TrySendTick(SymbolInfo symbol, TickIO tick) { SendSide(symbol, tick, true); if (tick.IsQuote) { #if NOTUSED bool result; if (!isFirstTick.TryGetValue(symbol.BinaryIdentifier, out result)) { isFirstTick.Add(symbol.BinaryIdentifier, true); } else { var tickSync = SyncTicks.GetTickSync(symbol.BinaryIdentifier); tickSync.AddTick(tick); } #endif SendSide(symbol, tick, false); } var lastTick = lastTicks[symbol.BinaryIdentifier]; lastTick.Inject(tick.Extract()); }
protected override void TrySendTick(SymbolInfo symbol, TickIO tick) { if (trace) { log.Trace("TrySendTick( " + symbol + " " + tick + ")"); } var quoteMessage = QuoteSocket.MessageFactory.Create(); var lastTick = lastTicks[symbol.BinaryIdentifier]; var buffer = quoteMessage.Data.GetBuffer(); var position = quoteMessage.Data.Position; quoteMessage.Data.SetLength(1024); if (tick.IsTrade) { var index = 0; var snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Symbol var value = symbol.Symbol.ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Price var len = ConvertPriceToBytes(tick.lPrice); var pos = len; for (var i = 0; i < len; i++) { buffer[position] = (byte)bytebuffer[--pos]; ++position; } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Size value = tick.Size.ToString().ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Bid if (tick.lBid != lastTick.lBid) { value = ("2003=" + tick.Bid + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Ask if (tick.lAsk != lastTick.lAsk) { value = ("2004=" + tick.Ask + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Ask size var askSize = Math.Max((int)tick.AskLevel(0), 1); if (askSize != lastTick.AskLevel(0)) { value = ("2005=" + askSize + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; // Bid size var bidSize = Math.Max((int)tick.BidLevel(0), 1); if (bidSize != lastTick.BidLevel(0)) { value = ("2006=" + bidSize + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = tradeSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; } else { var index = 0; var snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; var value = symbol.Symbol.ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } ++index; snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; if (tick.lBid != lastTick.lBid) { value = ("2003=" + tick.Bid + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; if (tick.lAsk != lastTick.lAsk) { value = ("2004=" + tick.Ask + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; var askSize = Math.Max((int)tick.AskLevel(0), 1); if (askSize != lastTick.AskLevel(0)) { value = ("2005=" + askSize + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; var bidSize = Math.Max((int)tick.BidLevel(0), 1); if (bidSize != lastTick.BidLevel(0)) { value = ("2006=" + bidSize + ";").ToCharArray(); for (var i = 0; i < value.Length; i++) { buffer[position] = (byte)value[i]; ++position; } } ++index; snippet = quoteSnippetBytes[index]; Array.Copy(snippet, 0, buffer, position, snippet.Length); position += snippet.Length; } var strValue = (tick.UtcTime.TimeOfDay + "." + tick.UtcTime.Microsecond.ToString("000") + ";2015=" + tick.UtcTime.Month.ToString("00") + "/" + tick.UtcTime.Day.ToString("00") + "/" + tick.UtcTime.Year + "\n").ToCharArray(); for (var i = 0; i < strValue.Length; i++) { buffer[position] = (byte)strValue[i]; ++position; } if (trace) { var message = Encoding.ASCII.GetString(buffer, 0, (int)position); log.Trace("Tick message: " + message); } quoteMessage.Data.Position = position; quoteMessage.Data.SetLength(position); lastTick.Inject(tick.Extract()); if (trace) { log.Trace("Added tick to packet: " + tick.UtcTime); } quoteMessage.SendUtcTime = tick.UtcTime.Internal; if (quoteMessage.Data.GetBuffer().Length == 0) { return; } QuotePacketQueue.Enqueue(quoteMessage, quoteMessage.SendUtcTime); if (trace) { log.Trace("Enqueued tick packet: " + new TimeStamp(quoteMessage.SendUtcTime)); } }
public void Copy(TickIO tick) { Copy(tick, tick.Extract().contentMask); }