Exemple #1
0
 public QuikBar(QuikQuote quote)
 {
     Symbol    = quote.Symbol;
     Volume    = quote.Volume;
     Open      = quote.Close;
     High      = quote.Close;
     Low       = quote.Close;
     Close     = quote.Close;
     OpenTime  = quote.Time;
     CloseTime = quote.Time;
 }
Exemple #2
0
        /// <summary>
        /// Add data to data store
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="data"></param>
        public static void AddQuotesFromDde(object[][] table)
        {
            //object[][] table = XLTable.Cells(data);

            // Parse rows to bars
            foreach (object[] row in table)
            {
                try
                {
                    // Write to WL streaming provider
                    if (StreamingProvider == null)
                    {
                        return;
                    }

                    // Load row
                    QuikQuote quikQuote = new QuikQuote(row);
                    // Maybe first ticks are zero ticks
                    if (quikQuote.Close == 0)
                    {
                        continue;
                    }

                    // Update streaming provider
                    Quote q = new Quote();
                    q.Symbol    = quikQuote.Symbol;
                    q.TimeStamp = quikQuote.Time;
                    q.Ask       = quikQuote.Close;
                    q.Bid       = quikQuote.Close;
                    q.Price     = quikQuote.Close;
                    q.Size      = quikQuote.Volume;

                    q.Open          = q.Price;
                    q.PreviousClose = q.Price;


                    //StreamingProvider.UpdateQuote(q);

                    StreamingProvider.UpdateMiniBar(q,
                                                    q.Open,
                                                    (q.Ask != 0) ? q.Ask : q.Price,
                                                    (q.Bid != 0) ? q.Bid : q.Price);
                    StreamingProvider.Hearbeat(quikQuote.Time);
                }
                // Header rows contains titles, ignore them
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
        /// <summary>
        /// Add data to data store
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="data"></param>
        public static void AddQuotesFromDde(object[][] table)
        {
            //object[][] table = XLTable.Cells(data);

            // Parse rows to bars
            foreach (object[] row in table)
            {
                try
                {
                    // Write to WL streaming provider
                    if (StreamingProvider == null)
                        return;

                    // Load row
                    QuikQuote quikQuote = new QuikQuote(row);
                    // Maybe first ticks are zero ticks
                    if (quikQuote.Close == 0)
                        continue;

                    // Update streaming provider
                    Quote q = new Quote();
                    q.Symbol = quikQuote.Symbol;
                    q.TimeStamp = quikQuote.Time;
                    q.Ask = quikQuote.Close;
                    q.Bid = quikQuote.Close ;
                    q.Price = quikQuote.Close;
                    q.Size = quikQuote.Volume;

                    q.Open = q.Price;
                    q.PreviousClose = q.Price;

                    //StreamingProvider.UpdateQuote(q);

                    StreamingProvider.UpdateMiniBar(q,
                        q.Open,
                        (q.Ask != 0) ? q.Ask : q.Price,
                        (q.Bid != 0) ? q.Bid : q.Price);
                    StreamingProvider.Hearbeat(quikQuote.Time);
                }
                // Header rows contains titles, ignore them
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// True if QuikQuote is inside QuikBar time interval
        /// </summary>
        /// <param name="bar">QuikBar</param>
        /// <param name="quote">QuikQuote</param>
        /// <param name="dataScale">Bar data scale</param>
        /// <returns></returns>
        private static bool IsNewBarQuote(QuikBar bar, QuikQuote quote, BarDataScale dataScale)
        {
            switch (dataScale.Scale)
            {
            case BarScale.Tick:
                return(true);

                break;

            case BarScale.Second:
                return(quote.Time.Second != bar.OpenTime.Second &&
                       quote.Time.Second % dataScale.BarInterval == 0);

                break;

            case BarScale.Minute:
                return(quote.Time.Minute != bar.OpenTime.Minute &&
                       quote.Time.Minute % dataScale.BarInterval == 0);

                break;

            case BarScale.Daily:
            case BarScale.Weekly:
            default:
                return(quote.Time.Day != bar.OpenTime.Day &&
                       quote.Time.Day % dataScale.BarInterval == 0);

                break;

            case BarScale.Monthly:
            case BarScale.Quarterly:
                return(quote.Time.Month != bar.OpenTime.Month &&
                       quote.Time.Month % dataScale.BarInterval == 0);

                break;

            case BarScale.Yearly:
                return(quote.Time.Year != bar.OpenTime.Year &&
                       quote.Time.Year % dataScale.BarInterval == 0);
            }
        }
Exemple #5
0
        //public QuikBar(string data, NumberFormatInfo numberFormatInfo)
        //{
        //    string[] dataArray = data.Split(QuikDdeServer.Delimiter);
        //    // Symbol
        //    Symbol = dataArray[0];

        //    // Date
        //    string dateString = dataArray[2];
        //    int year = int.Parse(dateString.Substring(0, 4));
        //    int month = int.Parse(dateString.Substring(4, 2));
        //    int day = int.Parse(dateString.Substring(6, 2));
        //    // Time
        //    string timeString = dataArray[3];
        //    int hour = int.Parse(timeString.Substring(0, 2));
        //    int minute = int.Parse(timeString.Substring(2, 2));
        //    int second = int.Parse(timeString.Substring(4, 2));
        //    // Set time
        //    Time = new DateTime(year, month, day, hour, minute, second);

        //    // OHLCV

        //    string closeString = dataArray[4];
        //    Clos = double.Parse(openString, numberFormatInfo);
        //    string highString = dataArray[5];
        //    High = double.Parse(highString, numberFormatInfo);
        //    string lowString = dataArray[6];
        //    Low = double.Parse(lowString, numberFormatInfo);
        //    string closeString = dataArray[7];
        //    Close = double.Parse(closeString, numberFormatInfo);
        //    string volString = dataArray[8];
        //    Volume = double.Parse(volString, numberFormatInfo);
        //}

        public void Update(QuikQuote quote)
        {
            // ToDo: find out, maybe add, not max
            Volume = Math.Max(quote.Volume, Volume);
//            Low = High = Close = quote.Close;
            Low  = Math.Min(quote.Close, Low);
            High = Math.Max(quote.Close, High);
            //Close = quote.Price;
            // If new quote is a first quote, update open time and price
            if (CloseTime.Ticks < quote.Time.Ticks)
            {
                CloseTime = quote.Time;
                Close     = quote.Close;
            }
            // If new quote is a last quote, update close time and price
            if (OpenTime.Ticks > quote.Time.Ticks)
            {
                OpenTime = quote.Time;
                Open     = quote.Close;
            }
        }
        /// <summary>
        /// Get Wealth Lab bars from QuikBars
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public static BarsAndDom GetHistoryBars(string symbol, DataSource ds, DateTime startTime, DateTime endTime)
        {
            // Return bars in ticks data. Will be recalculated by Wealth-lab
            //            Bars bars = new Bars(symbol.Trim(new char[] { ' ', '"' }), ds.Scale, ds.BarInterval);
            if (HistoryBars.ContainsKey(symbol))
            {
                HistoryBars.Remove(symbol);
                //return HistoryBars[symbol];

            }
            BarsAndDom bars = new BarsAndDom(symbol.Trim(new char[] { ' ', '"' }), ds.Scale, ds.BarInterval);
            HistoryBars.Add(bars.Symbol, bars);

            // Load from file
            string[] lines = File.ReadAllLines(string.Format(historyFilePath, bars.Symbol));
            int i = 0;
            // Init quik bar
            QuikBar quikBar = null;
            if (lines.Length > 2)
            {
                if (ds.Scale == BarScale.Tick)
                {
                    QuikQuote quikQuote = new QuikQuote(lines[1]);
                    quikBar = new QuikBar(quikQuote);
                }
                else
                {
                    quikBar = new QuikBar(lines[1]);
                }
            }
            // Add bars
            foreach (string line in lines)
            {
                // First line is a header, no parse
                if (i++ == 0)
                    continue;
                QuikQuote quikQuote = new QuikQuote(line);

                // Add bar to wealth-lab if quote is a quote of new bar
                if(IsNewBarQuote(quikBar, quikQuote, ds.BarDataScale))
                {
                    bars.Add(quikBar.OpenTime, quikBar.Open, quikBar.High, quikBar.Low, quikBar.Close, quikBar.Volume);
                    quikBar = new QuikBar();
                }
                quikBar.Update(quikQuote);

                // Start a new bar or not?
                //TimeSpan timeFromOpen = quikBar.OpenTime - quikQuote.Time;

            //                bars.Add(quikQuote.Time, quikQuote.Close, quikQuote.Close, quikQuote.Close, quikQuote.Close, quikQuote.Volume);

            }

            // Load history
            if (bars.Count != 0)
            {

                bars.Level2History= new Level2History(bars.Symbol);
                bars.Level2History.Load(bars.Date.Last());
            }
            return bars;
        }
        /// <summary>
        /// True if QuikQuote is inside QuikBar time interval
        /// </summary>
        /// <param name="bar">QuikBar</param>
        /// <param name="quote">QuikQuote</param>
        /// <param name="dataScale">Bar data scale</param>
        /// <returns></returns>
        private static bool IsNewBarQuote(QuikBar bar, QuikQuote quote, BarDataScale dataScale)
        {
            switch (dataScale.Scale)
            {
                case BarScale.Tick:
                    return true;
                    break;
                case BarScale.Second:
                    return (quote.Time.Second != bar.OpenTime.Second
                        && quote.Time.Second % dataScale.BarInterval == 0);
                    break;
                case BarScale.Minute:
                    return ( quote.Time.Minute != bar.OpenTime.Minute
                        && quote.Time.Minute % dataScale.BarInterval == 0);
                    break;
                case BarScale.Daily:
                case BarScale.Weekly:
                default:
                    return (quote.Time.Day != bar.OpenTime.Day
                        && quote.Time.Day % dataScale.BarInterval == 0);
                    break;
                case BarScale.Monthly:
                case BarScale.Quarterly:
                    return (quote.Time.Month != bar.OpenTime.Month
                        && quote.Time.Month % dataScale.BarInterval == 0);
                    break;
                case BarScale.Yearly:
                    return (quote.Time.Year != bar.OpenTime.Year
                        && quote.Time.Year % dataScale.BarInterval == 0);

            }
        }
Exemple #8
0
        /// <summary>
        /// Get Wealth Lab bars from QuikBars
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public static BarsAndDom GetHistoryBars(string symbol, DataSource ds, DateTime startTime, DateTime endTime)
        {
            // Return bars in ticks data. Will be recalculated by Wealth-lab
//            Bars bars = new Bars(symbol.Trim(new char[] { ' ', '"' }), ds.Scale, ds.BarInterval);
            if (HistoryBars.ContainsKey(symbol))
            {
                HistoryBars.Remove(symbol);
                //return HistoryBars[symbol];
            }
            BarsAndDom bars = new BarsAndDom(symbol.Trim(new char[] { ' ', '"' }), ds.Scale, ds.BarInterval);

            HistoryBars.Add(bars.Symbol, bars);

            // Load from file
            string[] lines = File.ReadAllLines(string.Format(historyFilePath, bars.Symbol));
            int      i     = 0;
            // Init quik bar
            QuikBar quikBar = null;

            if (lines.Length > 2)
            {
                if (ds.Scale == BarScale.Tick)
                {
                    QuikQuote quikQuote = new QuikQuote(lines[1]);
                    quikBar = new QuikBar(quikQuote);
                }
                else
                {
                    quikBar = new QuikBar(lines[1]);
                }
            }
            // Add bars
            foreach (string line in lines)
            {
                // First line is a header, no parse
                if (i++ == 0)
                {
                    continue;
                }
                QuikQuote quikQuote = new QuikQuote(line);

                // Add bar to wealth-lab if quote is a quote of new bar
                if (IsNewBarQuote(quikBar, quikQuote, ds.BarDataScale))
                {
                    bars.Add(quikBar.OpenTime, quikBar.Open, quikBar.High, quikBar.Low, quikBar.Close, quikBar.Volume);
                    quikBar = new QuikBar();
                }
                quikBar.Update(quikQuote);

                // Start a new bar or not?
                //TimeSpan timeFromOpen = quikBar.OpenTime - quikQuote.Time;

//                bars.Add(quikQuote.Time, quikQuote.Close, quikQuote.Close, quikQuote.Close, quikQuote.Close, quikQuote.Volume);
            }

            // Load history
            if (bars.Count != 0)
            {
                bars.Level2History = new Level2History(bars.Symbol);
                bars.Level2History.Load(bars.Date.Last());
            }
            return(bars);
        }