Ejemplo n.º 1
0
        internal void Refresh()
        {
            lock (m_synchronizer)
            {
                Algorithm.Swap(ref m_first, ref m_second);
                m_first.Clear();
            }
            foreach (var element in m_second)
            {
                m_quotes.Enqueue(element);
                m_last = element;
            }
            long now = EnvironmentEx.GetTickCountEx();

            for (; m_quotes.Count > 0;)
            {
                QuoteEx entry = m_quotes.Peek();
                long    delta = (now - entry.Time);
                if (delta > m_intervalInMs)
                {
                    m_quotes.Dequeue();
                }
                else
                {
                    break;
                }
            }
            m_time = now;
        }
Ejemplo n.º 2
0
        internal static GraphPart CreateAsks(double requiredVolume, Quotes quotes)
        {
            GraphPart      result = new GraphPart(quotes);
            List <Point2F> points = result.m_points;
            long           now    = quotes.Time;

            foreach (var element in quotes.Items)
            {
                Point2F point = new Point2F();
                point.X = (element.Time - now) / 1000.0F;
                point.Y = MathEx.CalculateWAVP(requiredVolume, element.Quote.Asks);
                points.Add(point);
            }

            QuoteEx quote = quotes.Last;

            if (null != quote.Quote)
            {
                Point2F point = new Point2F();
                point.X = (quote.Time - now) / 1000.0F;
                if (point.X < -quotes.Interval)
                {
                    point.X = -(float)quotes.Interval;
                }
                point.Y = MathEx.CalculateWAVP(requiredVolume, quote.Quote.Asks);
                points.Add(point);
            }
            return(result);
        }
Ejemplo n.º 3
0
        private static void WriteQuote(double lotSize, double roundingStepOfPrice, IEnumerable<double> volumes, QuoteEx quote, long start, StringBuilder builder)
        {
            double delta = (quote.Time - start) / 1000.0;
            builder.Append(delta);
            builder.AppendFormat(",{0}", quote.Quote.CreatingTime.ToString("yyyy-MM-ddTHH:mm:ss.fff"));

            foreach(var element in volumes)
            {
                float? bid = MathEx.CalculateWAVP(element * lotSize, quote.Quote.Bids);
                float? ask = MathEx.CalculateWAVP(element * lotSize, quote.Quote.Asks);

                if (bid.HasValue)
                {
                    bid = (float)MathEx.RoundDown(bid.Value, roundingStepOfPrice);
                }

                if (ask.HasValue)
                {
                    ask = (float)MathEx.RoundUp(ask.Value, roundingStepOfPrice);
                }

                builder.AppendFormat(",{0},{1}", bid, ask);
            }

            builder.AppendLine();
        }
Ejemplo n.º 4
0
 internal void Add(Quote quote)
 {
     lock (m_synchronizer)
     {
         long    now   = EnvironmentEx.GetTickCountEx();
         QuoteEx entry = new QuoteEx(now, quote);
         m_first.Add(entry);
     }
 }
Ejemplo n.º 5
0
        internal void Set(Quote[] quotes)
        {
            m_quotes.Clear();

            Quote last = quotes.Last();

            m_time = 0;

            foreach (var element in quotes)
            {
                long time  = (long)(element.CreatingTime - last.CreatingTime).TotalMilliseconds;
                long delta = (m_time - time);
                if (delta <= m_intervalInMs)
                {
                    QuoteEx quote = new QuoteEx(time, element);
                    m_quotes.Enqueue(quote);
                }
            }
        }
Ejemplo n.º 6
0
 internal void Refresh()
 {
     lock (m_synchronizer)
     {
         Algorithm.Swap(ref m_first, ref m_second);
         m_first.Clear();
     }
     foreach (var element in m_second)
     {
         m_quotes.Enqueue(element);
         m_last = element;
     }
     long now = EnvironmentEx.GetTickCountEx();
     for (; m_quotes.Count > 0; )
     {
         QuoteEx entry = m_quotes.Peek();
         long delta = (now - entry.Time);
         if (delta > m_intervalInMs)
         {
             m_quotes.Dequeue();
         }
         else
         {
             break;
         }
     }
     m_time = now;
 }
Ejemplo n.º 7
0
 internal void Add(Quote quote)
 {
     lock (m_synchronizer)
     {
         long now = EnvironmentEx.GetTickCountEx();
         QuoteEx entry = new QuoteEx(now, quote);
         m_first.Add(entry);
     }
 }
Ejemplo n.º 8
0
        internal void Set(Quote[] quotes)
        {
            m_quotes.Clear();

            Quote last = quotes.Last();
            m_time = 0;

            foreach (var element in quotes)
            {
                long time = (long)(element.CreatingTime - last.CreatingTime).TotalMilliseconds;
                long delta = (m_time - time);
                if (delta <= m_intervalInMs)
                {
                    QuoteEx quote = new QuoteEx(time, element);
                    m_quotes.Enqueue(quote);
                }
            }
        }
Ejemplo n.º 9
0
        private static void WriteQuote(double lotSize, double roundingStepOfPrice, IEnumerable <double> volumes, QuoteEx quote, long start, StringBuilder builder)
        {
            double delta = (quote.Time - start) / 1000.0;

            builder.Append(delta);
            builder.AppendFormat(",{0}", quote.Quote.CreatingTime.ToString("yyyy-MM-ddTHH:mm:ss.fff"));

            foreach (var element in volumes)
            {
                float?bid = MathEx.CalculateWAVP(element * lotSize, quote.Quote.Bids);
                float?ask = MathEx.CalculateWAVP(element * lotSize, quote.Quote.Asks);

                if (bid.HasValue)
                {
                    bid = (float)MathEx.RoundDown(bid.Value, roundingStepOfPrice);
                }

                if (ask.HasValue)
                {
                    ask = (float)MathEx.RoundUp(ask.Value, roundingStepOfPrice);
                }

                builder.AppendFormat(",{0},{1}", bid, ask);
            }

            builder.AppendLine();
        }