/// <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);
            }
        }
Esempio n. 2
0
        public static void UpdateDatebase(string type, object value)
        {
            switch (type)
            {
            case "A1":
            {
                OPENCREATE data = (OPENCREATE)value;

                break;
            }

            case "A2":
            {
                OPENMODIFY data = (OPENMODIFY)value;
                break;
            }

            case "A3":
            {
                OPENRUN data = (OPENRUN)value;
                break;
            }

            case "A4":
            {
                OPENALLOW data = (OPENALLOW)value;
                break;
            }

            case "A5":
            {
                OPENDELETE data = (OPENDELETE)value;
                break;
            }

            case "B1":
            {
                CLOSECREATE data = (CLOSECREATE)value;
                break;
            }

            case "B2":
            {
                CLOSEMODIFY data = (CLOSEMODIFY)value;
                break;
            }

            case "B3":
            {
                CLOSERUN data = (CLOSERUN)value;
                break;
            }

            case "B4":
            {
                CLOSEALLOW data = (CLOSEALLOW)value;
                break;
            }

            case "B5":
            {
                CLOSEDELETE data = (CLOSEDELETE)value;
                break;
            }

            case "C1":
            {
                MakeOrder data = (MakeOrder)value;
                break;
            }
            }
        }