public Policy(SecurityInfo si, Parameter rpp, PolicyProperties pp)
 {
     this.isSim        = pp.IsSim;
     this.SecInfo      = si;
     this.stockAccount = pp.Account;
     this.parameter    = rpp;
     this.policyName   = PName;
     this.startDate    = rpp.StartDate;
     this.endDate      = rpp.EndDate;
     this.inteval      = rpp.Inteval;
     this.isReal       = rpp.IsReal;
     this.policyguid   = Guid.NewGuid();
     initialDataReceiver();
     InitialDataProcessor();
     currentDay         = DateTime.Now;
     openPoints         = new List <OpenPoint>();
     IsSimulateFinished = false;
     //isOpened = false;
     if (rpp.save)
     {
         SaveParameter(rpp);
     }
     currentTick = new TickData();
     this.isLiveDataProcessor = true;
     tps        = new ConcurrentDictionary <Guid, TradePoints>();
     SecondSi   = GlobalValue.GetFutureByCodeAndMarket(parameter.SecondCode, parameter.SecondMarket);
     SecondTick = new TickData();
 }
        public Policy(SecurityInfo si, Parameter rpp, PolicyProperties pp)
        {
            this.isSim        = pp.IsSim;
            this.SecInfo      = si;
            this.stockAccount = pp.Account;
            this.parameter    = rpp;
            this.policyName   = string.Format("{0}%{1}%{2}%{3}", PName, si.Code, parameter.Bz1, parameter.Bz2);
            this.startDate    = rpp.StartDate;
            this.endDate      = rpp.EndDate;
            this.inteval      = rpp.Inteval;
            this.isReal       = rpp.IsReal;
            this.policyguid   = Guid.NewGuid();

            initialDataReceiver();
            InitialDataProcessor();
            currentDay         = DateTime.MinValue.Date;
            openPoints         = new List <OpenPoint>();
            IsSimulateFinished = false;
            //isOpened = false;
            if (rpp.save)
            {
                SaveParameter(rpp);
            }

            currentTick = new TickData();
            lockObject  = new object();
            this.isLiveDataProcessor = true;
            MomList    = new List <double>();
            MomAbsList = new List <double>();
            DieBars    = new List <DieBar>();
            tps        = new List <TradePoints>();
            lock_tps   = new object();
            eosusdtsi  = GlobalValue.GetFutureByCodeAndMarket(parameter.Bz1, si.Market);
            eosbtcsi   = GlobalValue.GetFutureByCodeAndMarket(parameter.Bz2, si.Market);
        }
Beispiel #3
0
        private void btn_stock_Click(object sender, EventArgs e)
        {
            inifile.WriteString("daterange", "fromdate", this.dateTimePicker1.Value.Date.ToString("yyyy-MM-dd"));
            inifile.WriteString("daterange", "todate", this.dateTimePicker2.Value.Date.ToString("yyyy-MM-dd"));
            List <RunningPolicy> policies = new List <RunningPolicy>();

            for (int i = 0; i < this.grid_stocks.Rows.Count; i++)
            {
                string           code        = this.grid_stocks.Rows[i].Cells[0].Value.ToString().Trim();
                string           name        = this.grid_stocks.Rows[i].Cells[1].Value.ToString().Trim();
                string           market      = this.grid_stocks.Rows[i].Cells[2].Value.ToString();
                SecurityInfo     si          = GlobalValue.GetFutureByCodeAndMarket(code, market);
                string           programname = this.grid_stocks.Rows[i].Cells[5].Value.ToString();
                string           dllname     = programname.Substring(0, programname.Length - 4);
                Assembly         assembly    = ((GridRowTag)this.grid_stocks.Rows[i].Tag).assembly;
                Type             ClassPolicy = assembly.GetType(string.Format("{0}.Policy", dllname));
                Object           o           = ((GridRowTag)this.grid_stocks.Rows[i].Tag).parameter;
                PolicyProperties pp          = new PolicyProperties();
                pp.Account    = string.Empty;
                pp.IsLianDong = false;
                pp.IsSim      = true;
                Object ObjectPolicy = assembly.CreateInstance(ClassPolicy.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, o, pp }, null, null);
                policies.Add((RunningPolicy)ObjectPolicy);
            }

            this.MainForm.AddStock(policies);
            this.Close();
        }
Beispiel #4
0
        private void bt_importfile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            ofd.ShowDialog();
            StringBuilder strb     = new StringBuilder();
            string        filename = ofd.FileName;
            XmlDocument   doc      = new XmlDocument();

            try
            {
                doc.Load(filename);
            }
            catch
            {
                MessageBox.Show("对不起,无法加载参数文件");
                return;
            }
            XmlNode root;

            try
            {
                root = doc.SelectSingleNode("Parameters");
            }
            catch
            {
                MessageBox.Show("找不到Parameters");
                return;
            }
            XmlNodeList parameters;

            try
            {
                parameters = root.SelectNodes("PolicyItem");
            }
            catch
            {
                MessageBox.Show("无法找到参数信息");
                return;
            }
            foreach (XmlNode parameter in parameters)
            {
                string       policyname          = parameter.Attributes["policyName"].Value;
                XmlNode      siNode              = parameter.SelectSingleNode("SecurityInfo");
                string       code                = siNode.Attributes["code"].Value;
                string       market              = siNode.Attributes["market"].Value;
                SecurityInfo si                  = GlobalValue.GetFutureByCodeAndMarket(code, market);
                XmlNode      pNode               = siNode.SelectSingleNode("Parameter");
                Dictionary <string, string> pDic = new Dictionary <string, string>();

                foreach (XmlNode item in pNode.ChildNodes)
                {
                    pDic.Add(item.Name, item.InnerText);
                }
                AddStockCodeByFile(si, policyname, pDic);
            }
        }
Beispiel #5
0
        private void bt_load_Click(object sender, EventArgs e)
        {
            string section;

            try
            {
                section = ((ComboBoxItem)this.cb_policy.SelectedItem).Value;
            }
            catch
            {
                MessageBox.Show("请选择策略");
                return;
            }
            DataTable list = null;

            //DataTable list = LocalSQL.QueryDataTable(string.Format("select policysi_code,policysi_name,policysi_market from policysi_mstr where policysi_dll = '{0}' order by policysi_code ", section));
            //string list = inifile.GetString("StockList", section, string.Empty);
            for (int x = 0; x < list.Rows.Count; x++)
            //if (list != string.Empty)
            {
                string       code   = list.Rows[x]["policysi_code"].ToString();
                string       name   = list.Rows[x]["policysi_name"].ToString();
                string       market = list.Rows[x]["policysi_market"].ToString();
                SecurityInfo si     = GlobalValue.GetFutureByCodeAndMarket(code, market);
                AddStockCode(si);
                //bool hasDup = false;
                //for (int j = 0; j < grid_stocks.Rows.Count; j++)
                //{
                //    if (grid_stocks.Rows[j].Cells[0].Value.ToString() == list.Rows[x]["policysi_code"].ToString() && grid_stocks.Rows[j].Cells[2].Value.ToString() == list.Rows[x]["policysi_market"].ToString())
                //    {
                //        //弹出提示框
                //        //MessageBox.Show("有相同的数据,请重新选择");
                //        hasDup = true;
                //        break;
                //        //如果有相同的数据,就返回
                //        //return;
                //    }
                //}
                //if (!hasDup)
                //{
                //    //在查找所有的数据都没有与之匹配的数据,就添加一条数据
                //    //cbi = (ComboBoxItem)com_type.SelectedItem;
                //    int i = grid_stocks.Rows.Add();
                //    //添加code
                //    grid_stocks.Rows[i].Cells[0].Value = list.Rows[x]["policysi_code"];
                //    //添加名称
                //    grid_stocks.Rows[i].Cells[1].Value = list.Rows[x]["policysi_name"];
                //    //添加市场
                //    grid_stocks.Rows[i].Cells[2].Value = list.Rows[x]["policysi_market"];
                //    //添加完之后清空com_type中的股票代码
                //    grid_stocks.Rows[i].Cells[3].Value = "删除";
                //    this.com_type.Text = string.Empty;
                //}
            }
        }
Beispiel #6
0
        private void cbt_ok_Click(object sender, EventArgs e)
        {
            List <RunningPolicy> policies = new List <RunningPolicy>();

            //for (int i = 0; i < this.grid_stocks.Rows.Count; i++)
            //{
            //    string code = this.grid_stocks.Rows[i].Cells[0].Value.ToString().Trim();
            //    string name = this.grid_stocks.Rows[i].Cells[1].Value.ToString().Trim();
            //    byte market = System.Convert.ToByte(this.grid_stocks.Rows[i].Cells[2].Value);
            //    SecurityInfo si = new SecurityInfo(code, name, market);
            //    string programname = this.grid_stocks.Rows[i].Cells[5].Value.ToString();
            //    string dllname = programname.Substring(0, programname.Length - 4);
            //    Assembly assembly = ((GridRowTag)this.grid_stocks.Rows[i].Tag).assembly;
            //    Type ClassPolicy = assembly.GetType(string.Format("{0}.Policy", dllname));
            //    Object o = ((GridRowTag)this.grid_stocks.Rows[i].Tag).parameter;
            //    PolicyProperties pp = new PolicyProperties();
            //    pp.IsLianDong = false;
            //    pp.IsSim = isSim;
            //    pp.Account = stockAccount;
            //    Object ObjectPolicy = assembly.CreateInstance(ClassPolicy.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, o, pp }, null, null);
            //    policies.Add((RunningPolicy)ObjectPolicy);
            //}

            for (int i = grid_stockX.Rows.Fixed; i < this.grid_stockX.Rows.Count; i++)
            {
                string           code        = this.grid_stockX.Rows[i][0].ToString();
                string           name        = this.grid_stockX.Rows[i][1].ToString();
                string           market      = this.grid_stockX.Rows[i][2].ToString();
                SecurityInfo     si          = GlobalValue.GetFutureByCodeAndMarket(code, market);
                string           programname = this.grid_stockX.Rows[i][5].ToString();
                string           dllname     = programname.Substring(0, programname.Length - 4);
                Assembly         assembly    = ((GridRowTag)this.grid_stockX.Rows[i].UserData).assembly;
                Type             ClassPolicy = assembly.GetType(string.Format("{0}.Policy", dllname));
                object           o           = ((GridRowTag)this.grid_stockX.Rows[i].UserData).parameter;
                PolicyProperties pp          = new PolicyProperties();
                pp.IsLianDong = false;
                pp.IsSim      = isSim;
                pp.Account    = stockAccount;
                Object ObjectPolicy = assembly.CreateInstance(ClassPolicy.FullName, true, BindingFlags.CreateInstance, null, new object[] { si, o, pp }, null, null);
                policies.Add((RunningPolicy)ObjectPolicy);
            }



            AddPolicies(policies);
            //this.MainForm.AddStock(policies);
            this.Close();
        }
Beispiel #7
0
        private void AddStockCode()
        {
            string code = com_type.Text.Trim();

            if (code == string.Empty)
            {
                MessageBox.Show("请输入股票代码");
            }
            else
            {
                SecurityInfo si = GlobalValue.GetFutureByCodeAndMarket(code, market);
                if (si == null)
                {
                    MessageBox.Show("找不到股票代码");
                    return;
                }
                AddStockCode(si);
            }
        }
Beispiel #8
0
 private void grid_stocklist_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 4)
     {
         string code   = grid_stocklist.Rows[e.RowIndex].Cells[1].Value.ToString();
         string market = grid_stocklist.Rows[e.RowIndex].Cells[3].Value.ToString();
         if (MessageBox.Show(string.Format("是否要停止接收{0}", code), "确认", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
         {
             for (int i = 0; i < GlobalValue.SecurityList.Count; i++)
             {
                 if (GlobalValue.SecurityList[i].Code == code && GlobalValue.SecurityList[i].Market == market)
                 {
                     GlobalValue.SecurityList.RemoveAt(i);
                     getMonitorList();
                     SaveXml();
                     RaiseRemoveStock(GlobalValue.GetFutureByCodeAndMarket(code, market));
                 }
             }
         }
     }
 }
        public override JObject DeleteOrders(List <Dictionary <string, string> > orderIds)
        {
            Dictionary <string, List <string> > cancelArray = new Dictionary <string, List <string> >();

            foreach (var orderInfo in orderIds)
            {
                if (!cancelArray.ContainsKey(orderInfo["code"]))
                {
                    cancelArray.Add(orderInfo["code"], new List <string>());
                }
                cancelArray[orderInfo["code"]].Add(orderInfo["orderId"]);
            }
            JObject jo = null;

            foreach (var codeItem in cancelArray)
            {
                SecurityInfo si = GlobalValue.GetFutureByCodeAndMarket(codeItem.Key, market);
                foreach (string orderId in codeItem.Value)
                {
                    switch (si.Type)
                    {
                    case "swap":
                        break;

                    case "futures":
                        break;

                    case "spot":
                        var res = DeleteOrder(si, orderId);
                        break;

                    default:
                        break;
                    }
                }
            }
            return(jo);
        }
        public void Simulator(SecurityInfo si, DateTime startDate, DateTime endDate, DataReceiver da, int interval, bool needSimulte = false)
        {
            if (needSimulte)
            {
                DateTime        today       = startDate.Date;
                MarketTimeRange marketRange = MarketTimeRange.getTimeRange(si.Market);
                while (today <= endDate)
                {
                    //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\Okex%" + si.Code + "%" + today.ToString("yyyyMMdd") + ".csv");
                    //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\" + si.Code + "-" + today.ToString("yyyyMMdd") + ".csv");

                    DataTable tickdatas = new DataTable();
                    try
                    {
                        tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\" + si.Code + "%" + today.ToString("yyyyMMdd") + ".csv");
                    }
                    catch { }
                    if (tickdatas.Rows.Count > 0)
                    {
                        for (int i = 0; i < tickdatas.Rows.Count; i++)
                        {
                            try
                            {
                                DataRow  dr       = tickdatas.Rows[i];
                                DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString());
                                //DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString().Replace("D", " ").Substring(0, 23));

                                TickData tickdata = new TickData();
                                tickdata.Code     = si.Code;
                                tickdata.SecInfo  = GlobalValue.GetFutureByCodeAndMarket(tickdata.Code, si.Market);
                                tickdata.Time     = tickTime;
                                tickdata.Preclose = 0;
                                tickdata.Open     = 0;
                                tickdata.High     = 0;
                                tickdata.Low      = 0;
                                tickdata.Ask      = System.Convert.ToDouble(dr["askPrice"].ToString());
                                tickdata.Bid      = System.Convert.ToDouble(dr["bidPrice"].ToString());
                                //tickdata.Last = System.Convert.ToDouble(dr["lastPrice"].ToString());
                                tickdata.Last   = (tickdata.Ask + tickdata.Bid) / 2;
                                tickdata.Volume = 0;
                                tickdata.Amt    = 0;
                                tickdata.IsReal = false;
                                for (int j = 0; j < 10; j++)
                                {
                                    tickdata.Asks[j]     = tickdata.Ask;
                                    tickdata.Bids[j]     = tickdata.Bid;
                                    tickdata.Asksizes[j] = System.Convert.ToDouble(dr["askSize"]);
                                    tickdata.Bidsizes[j] = System.Convert.ToDouble(dr["bidSize"]);
                                }
                                da.DataArrival(tickdata);
                                if (interval != 0)
                                {
                                    Thread.Sleep(interval);
                                }
                            }
                            catch { }
                        }
                    }
                    today = today.AddDays(1);
                }
                //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\rb15.csv");
                ////DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\XBTUSD-" + today.ToString("yyyyMMdd") + ".csv");
                //if (tickdatas.Rows.Count > 0)
                //{
                //    for (int i = 0; i < tickdatas.Rows.Count; i++)
                //    {
                //        DataRow dr = tickdatas.Rows[i];
                //        DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString());
                //        //TickData tickdata = TickData.ConvertFromDataRow(dr);

                //        TickData tickdata = new TickData();
                //        tickdata.Code = "rb";
                //        tickdata.SecInfo = GlobalValue.GetFutureByCode(tickdata.Code);
                //        tickdata.Time = tickTime;
                //        tickdata.Preclose = 0;
                //        tickdata.Open = 0;
                //        tickdata.High = 0;
                //        tickdata.Low = 0;
                //        tickdata.Ask = System.Convert.ToDouble(dr["open"]);
                //        tickdata.Bid = System.Convert.ToDouble(dr["high"]);
                //        tickdata.Last = System.Convert.ToDouble(dr["close"]);
                //        tickdata.Volume = 0;
                //        tickdata.Amt = 0;
                //        tickdata.IsReal = false;
                //        for (int j = 0; j < 10; j++)
                //        {
                //            tickdata.Asks[j] = tickdata.Ask;
                //            tickdata.Bids[j] = tickdata.Bid;
                //        }
                //        da.DataArrival(tickdata);
                //        if (interval != 0)
                //            Thread.Sleep(interval);
                //    }
                //}
            }
            TickData td = new TickData();

            td.Code = string.Empty;
            try
            {
                da.DataArrival(td);
            }
            catch { }
        }