コード例 #1
0
        public void DeleteWorker(object v)
        {
            string id = string.Empty;

            if (v is OPENDELETE)
            {
                OPENDELETE value = v as OPENDELETE;

                id = value.basic.ID;
            }
            else
            {
                CLOSEDELETE value = v as CLOSEDELETE;
                id = value.basic.ID;
            }

            if (!Workers.Keys.Contains(id))
            {
                return;
            }

            //结束策略实例
            Workers[id].breaklabel = true;

            //策略管理中删除该实例信息
            Workers.Remove(id);
            WorkersStratus.Remove(id);

            //行情模块中删除该策略实例的订阅,和消息队列
            DeleteStrategySubscribe(id);
            MarketInfo.SetStrategyQueue(new KeyValuePair <String, Queue>(id, new Queue()));

            if (DBAccessLayer.DBEnable)
            {
                if (v is OPENDELETE)
                {
                    DBAccessLayer.DeleteSGOPEN(id);
                }
                else
                {
                    DBAccessLayer.DeleteSGCLOSE(id);
                }
            }
        }
コード例 #2
0
        /// <summary>a
        /// 创建新的策略实例
        /// </summary>
        /// <param name="para"></param>
        /// <param name="orderList"></param>
        private void RecruitNewWorker(object v)
        {
            //创建新的策略实例
            StrategyWorker newWorker = new StrategyWorker();

            if (v is OPENCREATE)
            {
                //开仓策略
                OPENCREATE value = (OPENCREATE)v;
                newWorker.open_para       = new OPENPARA();
                newWorker.open_para.INDEX = value.INDEX;
                newWorker.open_para.OP    = value.OP;
                Dictionary <string, int> oli = new Dictionary <string, int>();

                foreach (var item in value.orderli.Split('\n'))
                {
                    if (item.Trim() == string.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        oli.Add(item.Split(';')[1] + item.Split(';')[0], Convert.ToInt32(item.Split(';')[2]));
                    }
                }

                newWorker.LiStockOrder = oli;

                newWorker.bAllow = false;
                newWorker.bRun   = false;
                newWorker.CT     = value.CT;

                newWorker.HD = value.HD;
                newWorker.StrategyInstanceID = value.basic.ID;
                newWorker.User = value.basic.USER;

                newWorker.Type = "OPEN";

                Dictionary <string, double> wli = new Dictionary <string, double>();

                foreach (var item in value.weightli.Split('\n'))
                {
                    if (item.Trim() == String.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        wli.Add(item.Split(';')[1] + item.Split(';')[0], Convert.ToDouble(item.Split(';')[2]));
                    }
                }

                newWorker.open_para.WeightList = wli;

                if (DBAccessLayer.DBEnable)
                {
                    DBAccessLayer.InsertSGOPEN((object)value);
                }
            }
            else
            {
                //平仓策略
                CLOSECREATE value = (CLOSECREATE)v;
                newWorker.close_para         = new CLOSEPARA();
                newWorker.User               = value.basic.USER;
                newWorker.StrategyInstanceID = value.basic.ID;
                newWorker.CT            = value.CT;
                newWorker.close_para.SP = value.SP;
                newWorker.HD            = value.HD;
                Dictionary <string, int>    oli   = new Dictionary <string, int>();
                Dictionary <string, double> weili = new Dictionary <string, double>();

                foreach (var item in value.POSITION.Split('\n'))
                {
                    if (item.Trim() == string.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        oli.Add(item.Split(';')[1] + item.Split(';')[0], Convert.ToInt32(item.Split(';')[2]));
                    }
                }


                newWorker.LiStockOrder          = oli;
                newWorker.close_para.WeightList = weili;
                newWorker.Type = "CLOSE";

                newWorker.bAllow = false;
                newWorker.bRun   = false;

                newWorker.close_para.SP     = value.SP;
                newWorker.close_para.COE    = value.COSTOFEQUITY;
                newWorker.close_para.SD     = value.STOCKDIVIDENDS;
                newWorker.close_para.SA     = value.STOCKALLOTMENT;
                newWorker.close_para.PE     = value.PROSPECTIVEARNINGS;
                newWorker.close_para.BASIS  = value.OB;
                newWorker.close_para.Charge = value.CHARGE;

                if (DBAccessLayer.DBEnable)
                {
                    DBAccessLayer.InsertSGCLOSE((object)value);
                    DBAccessLayer.UpdateSGOPENStatus(value.Open_STR_ID, 4);
                }
            }


            try
            {
                WorkersStratus.Add(newWorker.StrategyInstanceID, 0);
                Workers.Add(newWorker.StrategyInstanceID, newWorker);

                newWorker.RUN();

                //向行情模块添加消息列表映射
                MarketInfo.SetStrategyQueue(new KeyValuePair <String, Queue>(newWorker.StrategyInstanceID, newWorker.GetRefQueue()));
            }
            catch (Exception ex)
            {
                DBAccessLayer.LogSysInfo("StrategyMonitorClass-RecruitNewWorker", ex.ToString());
                GlobalErrorLog.LogInstance.LogEvent(ex.ToString() + ":StrategyMonitorClass.cs" + ":" + newWorker.StrategyInstanceID);
            }
        }