/// <summary> /// 更新策略实例参数 /// </summary> /// <param name="para">开仓基本参数</param> /// <param name="orderList">交易列表</param> /// <param name="id">需要修改的策略实例ID</param> public void UpdateWorker(object v) { string id = string.Empty; if (v is OPENMODIFY) { OPENMODIFY value = (OPENMODIFY)v; id = value.ID; } else { CLOSEMODIFY value = (CLOSEMODIFY)v; id = value.ID; } StrategyWorker worker = Workers[id]; worker.UpdateBaseParas(v); }
/// <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); } }