示例#1
0
        private void rulesDataGridView_UpdateDataSet(object sender, EventArgs e)
        {
            if (preConNameComboBox.SelectedIndex == -1)
            {
                underlyingConCheckBox.Checked = true;
                optionConCheckBox.Checked     = true;

                rulesDataGridView.DataSource = null;
            }
            else
            {
                string rule = preConNameComboBox.SelectedItem.ToString();

                ConfigSet.ParsingTableRow rul = Config.Local.ParsingTable.FindByRule(rule);
                if (rul != null)
                {
                    underlyingConCheckBox.Checked = rul.IncludesUnderlying;
                    optionConCheckBox.Checked     = rul.IncludesOptionsChain;
                }

                DataView view = new DataView(Config.Local.MappingTable);
                view.RowFilter = "(Rule = '" + rule + "')";
                if (underlyingConCheckBox.Checked && !optionConCheckBox.Checked)
                {
                    view.RowFilter += " AND (Field LIKE 'Underlying.*')";
                }
                else if (!underlyingConCheckBox.Checked && optionConCheckBox.Checked)
                {
                    view.RowFilter += " AND (Field LIKE 'Option.*')";
                }
                rulesDataGridView.DataSource = view;
            }
        }
示例#2
0
        private void ImportForm_Load(object sender, EventArgs e)
        {
            string rule = Config.Local.GetParameter(ConfigSet.PRM_LAST_SELECTED_RULE);

            preConNameComboBox_UpdateList(rule);

            ConfigSet.ParsingTableRow rul = Config.Local.ParsingTable.FindByRule(rule);
            if (rul != null)
            {
                underlyingConCheckBox.Checked = rul.IncludesUnderlying;
                optionConCheckBox.Checked     = rul.IncludesOptionsChain;
                CsvDelimiters = rul.Delimiters;
            }

            if (filename.EndsWith(".opo"))
            {
                opoFileTypeRadioButton.Checked = true;
            }
            else if (filename.EndsWith(".opd"))
            {
                opdFileTypeRadioButton.Checked = true;
            }
            else
            {
                csvFileTypeRadioButton.Checked = true;
            }
        }
示例#3
0
        private void xxxConCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (preConNameComboBox.SelectedIndex != -1)
            {
                string rule = preConNameComboBox.SelectedItem.ToString();

                ConfigSet.ParsingTableRow rul = Config.Local.ParsingTable.FindByRule(rule);
                if (rul != null)
                {
                    rul.IncludesUnderlying   = underlyingConCheckBox.Checked;
                    rul.IncludesOptionsChain = optionConCheckBox.Checked;
                }

                rulesDataGridView_UpdateDataSet(sender, e);
            }
        }
示例#4
0
        private void doneButton_Click(object sender, EventArgs e)
        {
            // save done button
            if (preConNameComboBox.SelectedIndex != -1)
            {
                Config.Local.SetParameter(ConfigSet.PRM_LAST_SELECTED_RULE, preConNameComboBox.SelectedItem.ToString());

                // save rule configuration
                ConfigSet.ParsingTableRow rul = Config.Local.ParsingTable.FindByRule(preConNameComboBox.SelectedItem.ToString());
                rul.IncludesUnderlying   = underlyingConCheckBox.Checked;
                rul.IncludesOptionsChain = optionConCheckBox.Checked;
                rul.Delimiters           = CsvDelimiters;
            }
            else
            {
                Config.Local.SetParameter(ConfigSet.PRM_LAST_SELECTED_RULE, "");
            }

            Config.Local.Save();
        }
示例#5
0
            public static bool Load(string filename, string rule, MarketSet data)
            {
                ConfigSet.ParsingTableRow rul = Config.Local.ParsingTable.FindByRule(rule);
                if (rul == null)
                {
                    return(false);
                }

                // get delimiters
                char[] delimiters = rul.Delimiters.ToCharArray();

                // rows dictionary
                Dictionary <string, ConfigSet.MappingTableRow> dict = new Dictionary <string, ConfigSet.MappingTableRow>();

                ConfigSet.MappingTableRow[] rows = (ConfigSet.MappingTableRow[])Config.Local.MappingTable.Select("Rule = '" + rule + "'");
                foreach (ConfigSet.MappingTableRow row in rows)
                {
                    if (!dict.ContainsKey(row.Field))
                    {
                        dict.Add(row.Field, row);
                    }
                }

                bool ret = true;

                try
                {
                    FileStream   stream = new FileStream(filename, FileMode.Open);
                    StreamReader reader = new StreamReader(stream);

                    // disable data notifications
                    data.QuoteTable.BeginLoadData();
                    data.OptionTable.BeginLoadData();

                    try
                    {
                        for (int i = 0; !reader.EndOfStream && ret; i++)
                        {
                            string s = reader.ReadLine();
                            if (s == null)
                            {
                                break;
                            }

                            string[] split;
                            if (delimiters == null || delimiters.Length == 0)
                            {
                                split = new string[] { s }
                            }
                            ;
                            else
                            {
                                split = s.Split(delimiters);
                            }

                            try
                            {
                                CultureInfo ci = new CultureInfo("en-US", false);

                                if (rul.IncludesUnderlying)
                                {
                                    ConfigSet.MappingTableRow row;

                                    DateTime timestamp;
                                    string   symbol, name, currency;
                                    double   last, change, open, low, high, bid, ask, volume, dvrate, hisvol;

                                    try
                                    {
                                        // symbol
                                        row = dict["Underlying.Symbol"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else if (row.Column == 0)
                                        {
                                            symbol = row.Value;
                                        }
                                        else
                                        {
                                            symbol = split[row.Column - 1];
                                        }
                                        symbol = symbol.Trim().ToUpper();
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // name
                                        row = dict["Underlying.Name"];
                                        if (row == null || row.Column == -1)
                                        {
                                            name = symbol;
                                        }
                                        else if (row.Column == 0)
                                        {
                                            name = row.Value;
                                        }
                                        else
                                        {
                                            name = split[row.Column - 1];
                                        }
                                        name = name.Trim().ToUpper();
                                    }
                                    catch { name = symbol; }

                                    try
                                    {
                                        // currency
                                        row = dict["Underlying.Currency"];
                                        if (row == null || row.Column == -1)
                                        {
                                            currency = "";
                                        }
                                        else if (row.Column == 0)
                                        {
                                            currency = row.Value;
                                        }
                                        else
                                        {
                                            currency = split[row.Column - 1];
                                        }
                                        currency = currency.Trim().ToUpper();
                                    }
                                    catch { currency = ""; }

                                    try
                                    {
                                        // last
                                        row = dict["Underlying.Last"];
                                        if (row == null || row.Column == -1)
                                        {
                                            last = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                last = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                last = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // change
                                        row = dict["Underlying.Change"];
                                        if (row == null || row.Column == -1)
                                        {
                                            change = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                change = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                change = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { change = double.NaN; }

                                    try
                                    {
                                        // open
                                        row = dict["Underlying.Open"];
                                        if (row == null || row.Column == -1)
                                        {
                                            open = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                open = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                open = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { open = double.NaN; }

                                    try
                                    {
                                        // low
                                        row = dict["Underlying.Low"];
                                        if (row == null || row.Column == -1)
                                        {
                                            low = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                low = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                low = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { low = double.NaN; }

                                    try
                                    {
                                        // high
                                        row = dict["Underlying.High"];
                                        if (row == null || row.Column == -1)
                                        {
                                            high = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                high = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                high = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { high = double.NaN; }

                                    try
                                    {
                                        // ask
                                        row = dict["Underlying.Ask"];
                                        if (row == null || row.Column == -1)
                                        {
                                            ask = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                ask = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                ask = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { ask = double.NaN; }

                                    try
                                    {
                                        // bid
                                        row = dict["Underlying.Bid"];
                                        if (row == null || row.Column == -1)
                                        {
                                            bid = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                bid = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                bid = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { bid = double.NaN; }

                                    try
                                    {
                                        // volume
                                        row = dict["Underlying.Volume"];
                                        if (row == null || row.Column == -1)
                                        {
                                            volume = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                volume = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                volume = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { volume = double.NaN; }

                                    try
                                    {
                                        // dvrate
                                        row = dict["Underlying.DivRate"];
                                        if (row == null || row.Column == -1)
                                        {
                                            dvrate = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                dvrate = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                dvrate = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { dvrate = double.NaN; }

                                    try
                                    {
                                        // hisvol
                                        row = dict["Underlying.HisVolatility"];
                                        if (row == null || row.Column == -1)
                                        {
                                            hisvol = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                hisvol = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                hisvol = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { hisvol = double.NaN; }

                                    try
                                    {
                                        // timestamp
                                        row = dict["Underlying.TimeStamp"];
                                        if (row == null || row.Column == -1)
                                        {
                                            timestamp = DateTime.Now;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                timestamp = DateTime.Parse(row.Value, ci);
                                            }
                                            else
                                            {
                                                timestamp = DateTime.Parse(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { timestamp = DateTime.Now; }

                                    // delete old entry in quote table
                                    DataRow del = data.QuoteTable.FindBySymbol(symbol);
                                    if (del != null)
                                    {
                                        del.Delete();
                                    }

                                    // add new entry to quote table
                                    data.QuoteTable.AddQuoteTableRow(
                                        symbol, name, currency, last, change, open, low, high,
                                        bid, ask, volume, dvrate, timestamp, hisvol);
                                }

                                if (rul.IncludesOptionsChain)
                                {
                                    ConfigSet.MappingTableRow row;

                                    int      openint;
                                    DateTime expiration, timestamp;
                                    string   symbol, underlying, type;
                                    double   strike, last, change, bid, ask, volume, contract_size;

                                    try
                                    {
                                        // underlying
                                        row = dict["Option.Underlying"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else if (row.Column == 0)
                                        {
                                            underlying = row.Value;
                                        }
                                        else
                                        {
                                            underlying = split[row.Column - 1];
                                        }
                                        underlying = underlying.Trim().ToUpper();
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // strike
                                        row = dict["Option.Strike"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                strike = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                strike = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // expiration
                                        row = dict["Option.Expiration"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                expiration = DateTime.Parse(row.Value, ci);
                                            }
                                            else
                                            {
                                                expiration = DateTime.Parse(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // type
                                        row = dict["Option.Type"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else if (row.Column == 0)
                                        {
                                            type = row.Value;
                                        }
                                        else
                                        {
                                            type = split[row.Column - 1];
                                        }
                                        type = type.Trim().ToUpper();
                                        if (type[0] == 'C')
                                        {
                                            type = "Call";
                                        }
                                        else if (type[0] == 'P')
                                        {
                                            type = "Put";
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // symbol
                                        row = dict["Option.Symbol"];
                                        if (row == null || row.Column == -1)
                                        {
                                            row = dict["Option.Symbol.Base"];
                                            if (row == null || row.Column == -1)
                                            {
                                                symbol = ".";
                                            }
                                            else if (row.Column == 0)
                                            {
                                                symbol = row.Value;
                                            }
                                            else
                                            {
                                                symbol = split[row.Column - 1];
                                            }

                                            row = dict["Option.Symbol.Suffix"];
                                            if (row == null || row.Column == -1)
                                            {
                                                symbol += underlying + expiration.ToString("ddMMMyyyy") + type[0] + strike.ToString("f2");
                                                symbol  = symbol.ToUpper();
                                            }
                                            else if (row.Column == 0)
                                            {
                                                symbol += row.Value;
                                            }
                                            else
                                            {
                                                symbol += split[row.Column - 1];
                                            }
                                        }
                                        else if (row.Column == 0)
                                        {
                                            symbol = row.Value;
                                        }
                                        else
                                        {
                                            symbol = split[row.Column - 1];
                                        }
                                        symbol = symbol.Trim().ToUpper();
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // last
                                        row = dict["Option.Last"];
                                        if (row == null || row.Column == -1)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                last = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                last = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { continue; }

                                    try
                                    {
                                        // change
                                        row = dict["Option.Change"];
                                        if (row == null || row.Column == -1)
                                        {
                                            change = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                change = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                change = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { change = double.NaN; }

                                    try
                                    {
                                        // ask
                                        row = dict["Option.Ask"];
                                        if (row == null || row.Column == -1)
                                        {
                                            ask = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                ask = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                ask = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { ask = double.NaN; }

                                    try
                                    {
                                        // bid
                                        row = dict["Option.Bid"];
                                        if (row == null || row.Column == -1)
                                        {
                                            bid = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                bid = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                bid = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { bid = double.NaN; }

                                    try
                                    {
                                        // volume
                                        row = dict["Option.Volume"];
                                        if (row == null || row.Column == -1)
                                        {
                                            volume = double.NaN;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                volume = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                volume = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { volume = double.NaN; }

                                    try
                                    {
                                        // openint
                                        row = dict["Option.OpenInt"];
                                        if (row == null || row.Column == -1)
                                        {
                                            openint = 0;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                openint = (int)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                openint = (int)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { openint = 0; }

                                    try
                                    {
                                        // contract_size
                                        row = dict["Option.ContractSize"];
                                        if (row == null || row.Column == -1)
                                        {
                                            contract_size = 1;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                contract_size = (double)Convert.ToDecimal(row.Value, ci);
                                            }
                                            else
                                            {
                                                contract_size = (double)Convert.ToDecimal(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { contract_size = 1; }

                                    try
                                    {
                                        // timestamp
                                        row = dict["Option.TimeStamp"];
                                        if (row == null || row.Column == -1)
                                        {
                                            timestamp = DateTime.Now;
                                        }
                                        else
                                        {
                                            if (ci.Name != row.Culture)
                                            {
                                                ci = new CultureInfo(row.Culture, false);
                                            }
                                            if (row.Column == 0)
                                            {
                                                timestamp = DateTime.Parse(row.Value, ci);
                                            }
                                            else
                                            {
                                                timestamp = DateTime.Parse(split[row.Column - 1], ci);
                                            }
                                        }
                                    }
                                    catch { timestamp = DateTime.Now; }

                                    // delete old entry in option table
                                    DataRow del = data.OptionTable.FindBySymbol(symbol);
                                    if (del != null)
                                    {
                                        del.Delete();
                                    }

                                    // add new entry to option table
                                    data.OptionTable.AddOptionTableRow(
                                        symbol, underlying, type, strike, expiration,
                                        last, change, bid, ask, volume, openint, contract_size, timestamp);
                                }
                            }
                            catch { ret = false; }
                        }
                    }
                    catch { ret = false; }

                    // enable data notifications
                    data.QuoteTable.EndLoadData();
                    data.OptionTable.EndLoadData();
                    data.AcceptChanges();

                    reader.Close();
                    stream.Close();
                }
                catch { ret = false; }

                return(ret);
            }