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 void CreateTick() { TimeStamp timeStamp = TimeStamp.UtcNow; tick.Initialize(); tick.SetSymbol(symbol.BinaryIdentifier); tick.SetTime(timeStamp); }
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 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); } } } } }
public void TSConverter(SymbolInfo symbolParam) // public void TSConverter(SymbolInfo symbolParam, string from, string to, TimeStamp startTime, TimeStamp endTime, bool fromMinute) { // this.symbol = symbolInfo; symbol = symbolParam; string path = Factory.Settings["AppDataFolder"] + @"\DataCache\"; // *** specify the path to the input file here // SymbolInfo symbol; // take user input symbol string ext = ".txt"; // *** specify input file extension here // double utcOffset = TimeStamp.UtcOffset; String tsLine; // the raw price data line double tickOpen; double tickHigh; double tickLow; double tickClose; int tickVolume; ArrayList ticksOut = new ArrayList(); // int ticksOutCount = 0; // bool fromMinute; char[] delimiterChars = { ',' }; // Do all the work here. // fromMinute = isFromMinute; int countLines = 0; try { using (StreamReader sr = new StreamReader(fromFile)) { tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); while ((tsLine = sr.ReadLine()) != null) { countLines++; if (countLines > 1) { tsBits = tsLine.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); if (fromMinute) { tickOpen = double.Parse(tsBits[2]); tickHigh = double.Parse(tsBits[3]); tickLow = double.Parse(tsBits[4]); tickClose = double.Parse(tsBits[5]); tickVolume = int.Parse(tsBits[6]); if (tickOpen == tickHigh && tickOpen == tickLow && tickOpen == tickClose) { writeATick(tickOpen, tickVolume); } else { writeATick(tickOpen, 0); if (tickHigh - tickClose >= tickClose - tickOpen) { writeATick(tickHigh, 0); writeATick(tickLow, 0); writeATick(tickHigh, 0); } else { writeATick(tickLow, 0); writeATick(tickHigh, 0); writeATick(tickLow, 0); } writeATick(tickClose, tickVolume); } } } } } } catch (Exception ex) { throw new ApplicationException("Error on line " + countLines + ": " + ex.Message, ex); } finally { if (tickWriter != null) { tickWriter.Close(); } } using (StreamWriter sw = new StreamWriter(path + symbol + "_log" + ext)) { for (int i = 0; i < ticksOut.Count; i++) { sw.WriteLine(ticksOut[i]); } } }