コード例 #1
0
        private void AddStockCode(SecurityInfo si, string policyname, string programName)
        {
            DateTime        fromdate = this.dateTimePicker1.Value.Date;
            DateTime        todate   = this.dateTimePicker2.Value.Date;
            PolicyParameter pp       = new PolicyParameter();

            pp.EndDate   = todate;
            pp.StartDate = fromdate;
            pp.Inteval   = 0;
            pp.IsReal    = false;
            try
            {
                string   dllname         = programName.Substring(0, programName.Length - 4);
                Assembly assembly        = Assembly.Load(PolicyProgram.getProgram(programName));
                Type     ClassParamter   = assembly.GetType(string.Format("{0}.Parameter", dllname));
                Object   ObjectParameter = assembly.CreateInstance(ClassParamter.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, pp, string.Empty }, null, null);
                int      i = grid_stocks.Rows.Add();
                grid_stocks.Rows[i].Cells[0].Value = si.Code;
                grid_stocks.Rows[i].Cells[1].Value = si.Name;
                grid_stocks.Rows[i].Cells[2].Value = si.Market;
                grid_stocks.Rows[i].Cells[3].Value = policyname;
                grid_stocks.Rows[i].Cells[4].Value = "删除";
                grid_stocks.Rows[i].Cells[5].Value = programName;
                grid_stocks.Rows[i].Tag            = new GridRowTag(assembly, ObjectParameter);
                this.com_type.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        void grid_policy_MouseClick(object sender, MouseEventArgs e)
        {
            int col = grid_policy.Col;
            int row = grid_policy.Row;

            if (row > grid_policy.Rows.Fixed - 1)
            {
                if (col == 4)
                {
                    string programname = this.grid_policy.Rows[row][2].ToString();// .Rows[e.RowIndex].Cells[1].Value.ToString();
                    string programdesc = this.grid_policy.Rows[row][3].ToString();
                    //string strSql = string.Format("delete from dll_mstr where dll_name = '{0}'", programname);
                    if (MessageBox.Show(string.Format("是否要删除策略'{0}'?", programdesc), "确认", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                    {
                        try
                        {
                            PolicyProgram.DeleteDLL(programname);
                            RefreshGrid();
                        }
                        catch
                        {
                            MessageBox.Show("有错误发生,请稍后再试");
                        }
                    }
                    else
                    {
                        grid_policy.Select(row, col - 1);
                    }
                }
            }
        }
コード例 #3
0
        private void AddStockCode(SecurityInfo si, string policyname, string programname, string filename)
        {
            try
            {
                string   dllname         = programname.Substring(0, programname.Length - 4);
                Assembly assembly        = Assembly.Load(PolicyProgram.getProgram(programname));
                Type     ClassParamter   = assembly.GetType(string.Format("{0}.Parameter", dllname));
                Object   ObjectParameter = assembly.CreateInstance(ClassParamter.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, stockAccount, filename }, null, null);
                //int i = grid_stocks.Rows.Add();
                //grid_stocks.Rows[i].Cells[0].Value = si.Code;
                //grid_stocks.Rows[i].Cells[1].Value = si.Name;
                //grid_stocks.Rows[i].Cells[2].Value = si.Market1;
                //grid_stocks.Rows[i].Cells[3].Value = policyname;
                //grid_stocks.Rows[i].Cells[4].Value = "删除";
                //grid_stocks.Rows[i].Cells[5].Value = programname;
                //grid_stocks.Rows[i].Tag = new GridRowTag(assembly,ObjectParameter);

                grid_stockX.Rows.Add();
                int row = grid_stockX.Rows.Count - 1;
                grid_stockX.Rows[row][0]       = si.Code;
                grid_stockX.Rows[row][1]       = si.Name;
                grid_stockX.Rows[row][2]       = si.Market;
                grid_stockX.Rows[row][3]       = policyname;
                grid_stockX.Rows[row][5]       = programname;
                grid_stockX.Rows[row].UserData = new GridRowTag(assembly, ObjectParameter);
                grid_stockX.SetCellImage(row, 4, global::GeneralForm.Properties.Resources.Ext_Net_Build_Ext_Net_icons_cancel);

                this.com_type.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #4
0
 public frm_Main()
 {
     InitializeComponent();
     GlobalValue.Initialize();
     PolicyProgram.Load();
     CheckDirectory();
     inifile = new IniFile(string.Format("{0}\\{1}", Application.StartupPath, "setting.ini"));
 }
コード例 #5
0
        private void InitialPolicyCombo()
        {
            DataTable dt = PolicyProgram.getProgramList();

            foreach (DataRow dr in dt.Rows)
            {
                ComboBoxItem cbi = new ComboBoxItem(dr[1].ToString().Trim(), dr[0].ToString().Trim());
                this.cb_policy.Items.Add(cbi);
            }
        }
コード例 #6
0
        private void AddStockCodeByFile(SecurityInfo si, string policyname, Dictionary <string, string> pDic)
        {
            try
            {
                string   programname     = pDic["ProgramName"];
                string   dllname         = programname.Substring(0, programname.Length - 4);
                Assembly assembly        = Assembly.Load(PolicyProgram.getProgram(programname));
                Type     ClassParamter   = assembly.GetType(string.Format("{0}.Parameter", dllname));
                Object   ObjectParameter = assembly.CreateInstance(ClassParamter.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, stockAccount, "" }, null, null);
                foreach (System.Reflection.PropertyInfo p in ObjectParameter.GetType().GetProperties())
                {
                    foreach (var item in pDic)
                    {
                        if (p.Name == item.Key)
                        {
                            if (p.PropertyType == typeof(TradeSendOrderPriceType))
                            {
                                foreach (TradeSendOrderPriceType tsopt in Enum.GetValues(typeof(TradeSendOrderPriceType)))
                                {
                                    if (tsopt.ToString() == item.Value)
                                    {
                                        p.SetValue(ObjectParameter, tsopt);
                                        break;
                                    }
                                }
                            }
                            else if (p.PropertyType == typeof(SecurityInfo))
                            {
                                p.SetValue(ObjectParameter, si);
                            }
                            else
                            {
                                p.SetValue(ObjectParameter, Convert.ChangeType(item.Value, p.PropertyType));
                            }
                            break;
                        }
                    }
                }
                grid_stockX.Rows.Add();
                int row = grid_stockX.Rows.Count - 1;
                grid_stockX.Rows[row][0]       = si.Code;
                grid_stockX.Rows[row][1]       = si.Name;
                grid_stockX.Rows[row][2]       = si.Market;
                grid_stockX.Rows[row][3]       = policyname;
                grid_stockX.Rows[row][5]       = programname;
                grid_stockX.Rows[row].UserData = new GridRowTag(assembly, ObjectParameter);
                grid_stockX.SetCellImage(row, 4, global::GeneralForm.Properties.Resources.Ext_Net_Build_Ext_Net_icons_cancel);

                this.com_type.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
        private void InitialPolicyCombo()
        {
            DataTable dt = PolicyProgram.getProgramList();

            foreach (DataRow dr in dt.Rows)
            {
                ComboBoxItem cbi = new ComboBoxItem(dr[1].ToString().Trim(), dr[0].ToString().Trim());
                this.cb_policy.Items.Add(cbi);
            }
            //this.cb_policy.Items.Add(new ComboBoxItem("预埋组合策略", "yumai"));
            //this.cb_policy.Items.Add(new ComboBoxItem("起量组合策略", "qiliang"));
            this.cb_policy.SelectedIndex = 0;
        }
コード例 #8
0
 public frm_MainX()
 {
     InitializeComponent();
     SiArray = new List <SecurityInfo>();
     da      = new DataMonitor();
     this.rbt_stop.Enabled = false;
     GlobalValue.Initialize();
     PolicyProgram.Load();
     TradeSDK.Load();
     CheckDirectory();
     _dataQueue = new ConcurrentQueue <TickData>();
     RunningST  = new Dictionary <string, BaseTradeAPI>();
     traders    = new Dictionary <string, Trader>();
 }
コード例 #9
0
 private void cb_policy_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string programname = ((ComboBoxItem)this.cb_policy.SelectedItem).Value;
         string dllname     = programname.Substring(0, programname.Length - 4);
         //加载程序集(dll文件地址),使用Assembly类
         assembly = Assembly.Load(PolicyProgram.getProgram(programname));
         //assembly = Assembly.LoadFile(string.Format(@"{0}\RunningPolicy1.dll", Application.StartupPath));
         //获取类型,参数(名称空间+类)
         ClassParamter = assembly.GetType(string.Format("{0}.BackTestParameter", dllname));
         //ClassPolicy = assembly.GetType(string.Format("{0}.Policy", dllname));
         //创建该对象的实例,object类型,参数(名称空间+类)
         Object ObjectParameter = assembly.CreateInstance(ClassParamter.FullName);
         //可视属性窗体
         this.propertyGrid1.SelectedObject = ObjectParameter;
     }
     catch (Exception ex)
     {
         //弹出错误信息
         MessageBox.Show(ex.Message);
     }
 }
コード例 #10
0
        private void bt_upload_Click(object sender, EventArgs e)
        {
            string filename = this.tx_filename.Text.Trim();
            string desc     = this.tx_name.Text.Trim();

            if (desc == string.Empty)
            {
                MessageBox.Show("请输入策略名称");
                return;
            }
            if (filename != string.Empty)
            {
                try
                {
                    FileInfo   fi  = new FileInfo(filename);
                    FileStream fs  = fi.OpenRead();
                    byte[]     bfs = new byte[fs.Length];
                    fs.Read(bfs, 0, (int)fs.Length);
                    string fname = fi.Name;
                    if (PolicyProgram.exists(fname))
                    {
                        PolicyProgram.UpdateDLL(fname, bfs, desc);
                    }
                    else
                    {
                        PolicyProgram.InsertDLL(fname, bfs, desc);
                    }
                    fs.Close();
                    RefreshGrid();
                    MessageBox.Show("上传成功");
                }
                catch
                {
                    MessageBox.Show("上传失败");
                }
            }
        }
コード例 #11
0
        private void RefreshGrid()
        {
            if (grid_policy.Rows.Count > grid_policy.Rows.Fixed)
            {
                grid_policy.Rows.RemoveRange(grid_policy.Rows.Fixed, grid_policy.Rows.Count - grid_policy.Rows.Fixed);//.Rows.Clear();
            }
            DataTable dt = PolicyProgram.getProgramList();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                grid_policy.Rows.Add(1);
                grid_policy.Rows[i + grid_policy.Rows.Fixed][1] = (i + 1).ToString();

                //this.grid_programlist.Rows.Add();
                //this.grid_programlist[0, i].Value = (i + 1).ToString();
                grid_policy.Rows[i + grid_policy.Rows.Fixed][2] = dt.Rows[i][0].ToString();
                grid_policy.Rows[i + grid_policy.Rows.Fixed][3] = dt.Rows[i][1].ToString();

                grid_policy.SetCellImage(i + grid_policy.Rows.Fixed, 4, global::GeneralForm.Properties.Resources.Ext_Net_Build_Ext_Net_icons_cancel);
                //this.grid_programlist[3, i].Value = "Delete";
                //this.grid_programlist[4, i].Value = "Run";
                //this.grid_programlist[5, i].Value = "Download";
            }
        }
コード例 #12
0
        private void bt_import_Click(object sender, EventArgs e)
        {
            string filename = string.Format("{0}\\parameter.xml", Application.StartupPath);
            {
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(filename);
                }
                catch
                {
                    MessageBox.Show("对不起,无法加载参数文件");
                    return;
                }
                XmlNode root;
                try
                {
                    root = doc.SelectSingleNode("PolicyPool");
                }
                catch
                {
                    MessageBox.Show("找不到PolicyPool");
                    return;
                }
                XmlNodeList accounts;
                try
                {
                    accounts = root.SelectNodes("Account");
                }
                catch
                {
                    MessageBox.Show("无法找到账户信息");
                    return;
                }
                foreach (XmlNode account in accounts)
                {
                    string acctname;
                    try
                    {
                        acctname = account.Attributes["name"].Value;
                        //MessageBox.Show(acctname);
                    }
                    catch
                    {
                        MessageBox.Show("无法找到账户名称");
                        return;
                    }
                    if (acctname == string.Empty)
                    {
                        XmlNodeList policyitems;
                        try
                        {
                            policyitems = account.SelectNodes("PolicyItem");
                        }
                        catch
                        {
                            MessageBox.Show("找不到账号对应的策略信息");
                            return;
                        }
                        foreach (XmlNode policyitem in policyitems)
                        {
                            string programName;
                            try
                            {
                                programName = policyitem.Attributes["programName"].Value;
                            }
                            catch
                            {
                                MessageBox.Show("找不到策略名称");
                                return;
                            }
                            XmlNodeList sinodes;

                            try
                            {
                                sinodes = policyitem.SelectNodes("SecurityInfo");
                            }
                            catch
                            {
                                MessageBox.Show("找不到股票信息");
                                return;
                            }
                            foreach (XmlNode sinode in sinodes)
                            {
                                string code       = sinode.Attributes["code"].Value;
                                byte   market     = System.Convert.ToByte(sinode.Attributes["market"].Value);
                                string siname     = sinode.Attributes["name"].Value;
                                string policyname = PolicyProgram.getPolicyName(programName);
                                if (policyname == string.Empty)
                                {
                                    MessageBox.Show(string.Format("找不到{0}对应的策略", programName));
                                    return;
                                }
                                //this.AddStockCode(GlobalValue.GetFutureByCode(code), policyname, programName);
                            }
                        }
                    }
                }
            }
        }