示例#1
0
        public override bool OnProcessTick(Tick tick)
        {
            int askDepth = tick.AskDepth;
            int bidDepth = tick.BidDepth;

            totalAskSize += askDepth;
            totalBidSize += bidDepth;
            tickCount++;

            int total = askDepth + bidDepth;

            if (bidDepth > askDepth)
            {
                ratio[0] = askDepth == 0 ? 0 : bidDepth / askDepth;
            }
            else if (bidDepth < askDepth)
            {
                ratio[0] = bidDepth == 0 ? 0 : -askDepth / bidDepth;
            }
            else
            {
                ratio[0] = 0;
            }

            bidSize[0] = tick.BidLevel(0) + tick.BidLevel(1);
            askSize[0] = tick.AskLevel(0) + tick.AskLevel(1);

            return(true);
        }
示例#2
0
        public override bool OnProcessTick(Tick tick)
        {
            for (int i = 0; i < 5; i++)
            {
                sumBidSizes += tick.BidLevel(i);
                sumAskSizes += tick.AskLevel(i);
            }
            countAskLevels += 5;
            countBidLevels += 5;

            bid[0] += tick.BidLevel(0);            // + tick.BidLevels(1);
            ask[0] += tick.AskLevel(0);            // + tick.AskLevels(1);
            return(true);
        }
示例#3
0
        private Yield OnTick(SymbolInfo symbol, Tick tick)
        {
            if (quotePacketQueue.Count > 10)
            {
                return(Yield.NoWork.Repeat);
            }
            if (trace)
            {
                log.Trace("Sending tick: " + tick);
            }
            var           packet = quoteSocket.CreatePacket();
            StringBuilder sb     = new StringBuilder();

            if (tick.IsTrade)
            {
                sb.Append("3|");                 // Trade
            }
            else
            {
                sb.Append("1|");            // Level 1
            }
            sb.Append("2026=USD;");         //Currency
            sb.Append("1003=");             //Symbol
            sb.Append(symbol.Symbol);
            sb.Append(';');
            sb.Append("2037=0;");             //Open Interest
            sb.Append("2085=.144;");          //Unknown
            sb.Append("2048=00/00/2009;");    //Unknown
            sb.Append("2049=00/00/2009;");    //Unknown
            if (tick.IsTrade)
            {
                sb.Append("2002=");                 //Last Trade.
                sb.Append(tick.Price);
                sb.Append(';');
                sb.Append("2007=");
                sb.Append(tick.Size);
                sb.Append(';');
            }
            sb.Append("2050=0;");           //Unknown
            sb.Append("2003=");             // Last Bid
            sb.Append(tick.Bid);
            sb.Append(';');
            sb.Append("2051=0;");           //Unknown
            sb.Append("2004=");             //Last Ask
            sb.Append(tick.Ask);
            sb.Append(';');
            sb.Append("2052=00/00/2010;");             //Unknown
            sb.Append("2005=");
            sb.Append(Math.Max((int)tick.AskLevel(0), 1));
            sb.Append(';');
            sb.Append("2053=00/00/2010;");             //Unknown
            sb.Append("2006=");
            sb.Append(Math.Max((int)tick.BidLevel(0), 1));
            sb.Append(';');
            sb.Append("2008=0.0;");         // Yesterday Close
            sb.Append("2056=0.0;");         // Unknown
            sb.Append("2009=0.0;");         // High today
            sb.Append("2057=0;");           // Unknown
            sb.Append("2010=0.0");          // Low today
            sb.Append("2058=1;");           // Unknown
            sb.Append("2011=0.0;");         // Open Today
            sb.Append("2012=6828928;");     // Volume Today
            sb.Append("2013=20021;");       // Up/Down Tick
            sb.Append("2014=");             // Time
            sb.Append(tick.UtcTime.TimeOfDay);
            sb.Append(".");
            sb.Append(tick.UtcTime.Microsecond);
            sb.Append(';');
            sb.Append("2015=");
            sb.Append(tick.UtcTime.Month.ToString("00"));
            sb.Append('/');
            sb.Append(tick.UtcTime.Day.ToString("00"));
            sb.Append('/');
            sb.Append(tick.UtcTime.Year);
            sb.Append('\n');
            var message = sb.ToString();

            if (trace)
            {
                log.Trace("Tick message: " + message);
            }
            packet.DataOut.Write(message.ToCharArray());
            if (packet == null)
            {
                throw new NullReferenceException();
            }
            quotePacketQueue.Enqueue(packet);
            return(Yield.DidWork.Return);
        }