Ejemplo n.º 1
0
        public bool ConvertFiles(DoubleDel progress)
        {
            bool ok  = true;
            int  c   = 1;
            int  max = Files.Length;

            // foreach file
            foreach (string fn in Files)
            {
                // read the file
                var csv = Util.getfile(fn, debug);
                // update progress
                progress((double)c++ / max);
                ok &= !string.IsNullOrWhiteSpace(csv);
                if (!ok)
                {
                    debug("Error reading: " + fn);
                    continue;
                }
                // parse data
                var data = Util.ParseCsvData(csv, debug);
                // convert it
                var ks = convert(data);
                ok &= ks.Count > 0;
                if (!ok)
                {
                    debug("No ticks converted in: " + fn);
                    continue;
                }
                // write to ticks
                ok &= TikUtil.TicksToFile(ks.ToArray(), debug);

                // update status
                if (!ok)
                {
                    debug("Error writing ticks to TIK file.");
                }
            }
            return(ok);
        }
Ejemplo n.º 2
0
        private void _inputbut_Click(object sender, EventArgs e)
        {
            // make sure we only convert one group at a time
            if (bw.IsBusy)
            {
                debug("wait until conversion completes..."); return;
            }
            // see if we're converting from files or webservices
            switch (_conval)
            {
            // webservice list
            case Converter.EuronextDaily:
            case Converter.YahooDaily:
            case Converter.GoogleDaily:
                // reset progress
                progress(0);
                // get list of symbols from user
                string symi = Microsoft.VisualBasic.Interaction.InputBox("Enter list of symbols to pull from " + _conval.ToString() + Environment.NewLine + "(eg LVS,GOOG,GE)", "Enter symbol list", string.Empty, 0, 0);
                // remove spaces and capitalize
                symi = symi.Replace(" ", string.Empty).ToUpper();
                // parse
                string[] syms  = symi.Split(',');
                int      count = 0;
                foreach (string sym in syms)
                {
                    try
                    {
                        // get barlists for those symbols
                        BarList bl;
                        if (_conval == Converter.GoogleDaily)
                        {
                            bl = BarListImpl.DayFromGoogle(sym);
                        }
                        else if (_conval == Converter.YahooDaily)
                        {
                            bl = BarListImpl.DayFromYahoo(sym);
                        }
                        else if (_conval == Converter.EuronextDaily)
                        {
                            if (!System.Text.RegularExpressions.Regex.IsMatch(sym, "[A-Z0-9]{12}", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                            {
                                debug("\"" + sym + "\" is not a valid ISIN.  Euronext expects ISINs!");
                                continue;
                            }
                            bl = BarListImpl.DayFromEuronext(sym);
                        }
                        else
                        {
                            continue;
                        }
                        // convert to tick files
                        if (!TikUtil.TicksToFile(TikUtil.Barlist2Tick(bl), debug))
                        {
                            debug("Error saving downloaded bars.");
                        }
                        // notify
                        debug("downloaded " + bl.Count + " bars of daily data for " + sym + " from " + _conval.ToString());
                    }
                    catch (Exception ex)
                    {
                        debug(sym + " converter error: " + ex.Message + ex.StackTrace);
                    }
                    // update progress
                    progress((double)count++ / syms.Length);
                }
                debug("completed daily download.");
                // we're done
                return;
            }
            OpenFileDialog of = new OpenFileDialog();

            // allow selection of multiple inputs
            of.Multiselect = true;
            // keep track of bytes so we can approximate progress
            long bytes = 0;

            if (of.ShowDialog() == DialogResult.OK)
            {
                List <string> symbols = new List <string>();
                foreach (string file in of.FileNames)
                {
                    _path = Path.GetDirectoryName(file);
                    string sn = Path.GetFileName(file);
                    // get size of current file and append to total size
                    FileInfo fi = new FileInfo(file);
                    bytes += fi.Length;
                    string sym = string.Empty;
                    switch (_conval)
                    {
                    case Converter.QCollector_eSignal:
                        string [] r = Path.GetFileNameWithoutExtension(sn).Split('_');
                        if (r.Length != 2)
                        {
                            sym = Microsoft.VisualBasic.Interaction.InputBox("Symbol data represented by file: " + sn, "File's Symbol", string.Empty, 0, 0);
                        }
                        else
                        {
                            sym = r[0];
                        }
                        break;

                    default:
                        // guess symbol
                        string guess = Util.rxm(sn, "[^a-z]*([a-z]{1,6})[^a-z]+");
                        // remove extension
                        guess = Util.rxr(guess, "[.].*", string.Empty);
                        // see if it's a clean match, if not don't guess
                        if (!Util.rxmok(guess, "^[a-z]+$"))
                        {
                            guess = string.Empty;
                        }
                        sym = Microsoft.VisualBasic.Interaction.InputBox("Symbol data represented by file: " + sn, "File's Symbol", guess, 0, 0);
                        break;
                    }
                    if (sym != string.Empty)
                    {
                        symbols.Add(sym);
                    }
                }
                // estimate total ticks
                _approxtotal = (int)((double)bytes / 51);
                // reset progress bar
                progress(0);
                // start background thread to convert
                bw.RunWorkerAsync(new convargs(of.FileNames, symbols.ToArray()));
                debug("started conversion");
            }
        }