示例#1
0
        private void _inputbut_Click(object sender, EventArgs e)
        {
            // make sure we only convert one group at a time
            if (bw.IsBusy || isgenericbusy)
            {
                debug("wait until conversion completes..."); return;
            }
            // see if we're converting from files or webservices
            switch (_conval)
            {
            case Converter.GenericCSV:
            {
                // prompt
                GenericConvert gc = new GenericConvert();
                gc.SendDebugEvent += new DebugDelegate(debug);
                if (gc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (gc.isConvertOk)
                    {
                        // reset progress
                        progress(0);
                        // get map
                        genericcsv = gc.CurrentMap;
                        // start process
                        RunHelper.run(dogenericconvert, null, debug, "generic convert start");
                    }
                }
                else
                {
                    debug("user canceled generic csv convert.");
                }
                return;
            }

            // 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;

                    case Converter.TrueFX:
                        // the symbol name is extracted from the filename
                        // do not rename files downloaded from TrueFX.com
                        string[] symstrs = Path.GetFileNameWithoutExtension(sn).Split('-');
                        sym = symstrs[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");
            }
        }
示例#2
0
        private void _inputbut_Click(object sender, EventArgs e)
        {
            // make sure we only convert one group at a time
            if (bw.IsBusy || isgenericbusy) { debug("wait until conversion completes..."); return; }
            // see if we're converting from files or webservices
            switch (_conval)
            {
                case Converter.GenericCSV:
                    {
                        // prompt
                        GenericConvert gc = new GenericConvert();
                        gc.SendDebugEvent+=new DebugDelegate(debug);
                        if (gc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {

                            if (gc.isConvertOk)
                            {
                                // reset progress
                                progress(0);
                                // get map
                                genericcsv = gc.CurrentMap;
                                // start process
                                RunHelper.run(dogenericconvert, null, debug, "generic convert start");

                            }
                        }
                        else
                        {
                            debug("user canceled generic csv convert.");
                        }
                        return;
                    }

                    // 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;
                        case Converter.TrueFX:
                            // the symbol name is extracted from the filename
                            // do not rename files downloaded from TrueFX.com
                            string[] symstrs = Path.GetFileNameWithoutExtension(sn).Split('-');
                            sym = symstrs[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");

            }
        }