Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
 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);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public bool TryReadTick(TickIO tickIO)
 {
     try
     {
         if (memory.Position >= tickBlockHeader.blockHeader.length)
         {
             return(false);
         }
         tickIO.SetSymbol(tickIO.lSymbol);
         var size = memory.GetBuffer()[memory.Position];
         dataVersion = tickIO.FromReader(memory);
         var utcTime = new TimeStamp(tickIO.lUtcTime);
         tickIO.SetTime(utcTime);
         return(true);
     }
     catch (EndOfStreamException ex)
     {
         return(false);
     }
     catch (IndexOutOfRangeException)
     {
         int x = 0;
         return(false);
     }
 }
Exemplo n.º 4
0
 public bool TryReadTick(TickIO tickIO)
 {
     if (!isInitialized)
     {
         return(false);
     }
     if (dataIn == null || tickCount > MaxCount || endOfData)
     {
         return(false);
     }
     try
     {
         do
         {
             tickIO.SetSymbol(lSymbol);
             byte size = dataIn.ReadByte();
             // Check for old style prior to version 8 where
             // single byte version # was first.
             if (dataVersion < 8 && size < 8)
             {
                 dataVersion = tickIO.FromReader((byte)size, dataIn);
             }
             else
             {
                 // Subtract the size byte.
                 //if (dataIn.BaseStream.Position + size - 1 > length) {
                 //    return false;
                 //}
                 int count = 1;
                 memory.SetLength(size);
                 memory.GetBuffer()[0] = size;
                 while (count < size)
                 {
                     var bytesRead = dataIn.Read(buffer, count, size - count);
                     if (bytesRead == 0)
                     {
                         return(false);
                     }
                     count += bytesRead;
                 }
                 memory.Position = 0;
                 dataVersion     = tickIO.FromReader(memory);
             }
             var utcTime = new TimeStamp(tickIO.lUtcTime);
             if (utcTime > EndTime)
             {
                 ReportEndOfData();
                 return(false);
             }
             tickIO.SetTime(utcTime);
             tickCount++;
         } while (tickIO.UtcTime < StartTime);
         return(true);
     }
     catch (EndOfStreamException ex)
     {
         ReportEndOfData();
         return(false);
     }
 }
Exemplo n.º 5
0
 public void Initialize()
 {
     tick     = Factory.TickUtil.TickIO();
     lastTick = Factory.TickUtil.TickIO();
     tick.SetSymbol(symbol.BinaryIdentifier);
     this.level2Bids = new Level2Collection(this, symbol, enumMarketSide.msBid);
     this.level2Asks = new Level2Collection(this, symbol, enumMarketSide.msAsk);
 }
Exemplo n.º 6
0
        private void CreateTick()
        {
            TimeStamp timeStamp = TimeStamp.UtcNow;

            tick.Initialize();
            tick.SetSymbol(symbol.BinaryIdentifier);
            tick.SetTime(timeStamp);
        }
Exemplo n.º 7
0
 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();
     }
 }
Exemplo n.º 8
0
 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);
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 public bool TryReadTick(TickIO tickIO)
 {
     if (!isInitialized)
     {
         return(false);
     }
     if (isLegacy)
     {
         return(legacy.TryReadTick(tickIO));
     }
     if (tickCount > MaxCount || endOfData)
     {
         return(false);
     }
     try
     {
         do
         {
             tickIO.SetSymbol(lSymbol);
             if (!fileBlock.TryReadTick(tickIO))
             {
                 ReadNextTickBlock();
                 if (!fileBlock.TryReadTick(tickIO))
                 {
                     throw new InvalidOperationException("Unable to write the first tick in a new block.");
                 }
             }
             dataVersion = fileBlock.DataVersion;
             if (tickIO.lUtcTime > EndTime.Internal)
             {
                 ReportEndOfData();
                 return(false);
             }
             tickCount++;
         } while (tickIO.UtcTime < StartTime);
         return(true);
     }
     catch (EndOfStreamException ex)
     {
         ReportEndOfData();
         return(false);
     }
 }
Exemplo n.º 10
0
        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]);
                }
            }
        }