public StrategyPosition(BaseStrategy strategy, Instrument instrument, long vol, DateTime lastTime) { mStrategy = strategy; mInstrument = instrument; mVol = vol; mLastTime = lastTime; }
public Order(BaseStrategy strategy, Instrument inst, DirectionType direction, OpenCloseType openClose, double price, int volume) { Strategy = strategy; Instrument = inst; Direction = direction; OpenClose = openClose; Price = price; OrderTime = DateTime.Now; Qty = volume; QtyLeft = volume; Status = OrderStatus.Normal; }
public static void LoadStrategy() { //获取文件列表 string[] files = new string[] { }; try { string dir = AppDomain.CurrentDomain.BaseDirectory + "\\strategys"; if (Directory.Exists(dir)) { files = Directory.GetFiles(dir); } else { Directory.CreateDirectory(dir); } } catch (Exception ex) { LogUtil.SysLog(ex.StackTrace); } //加载策略 foreach (string f in files) { Assembly assembly; try { assembly = Assembly.LoadFrom(f); }catch (Exception e) { continue; } Type[] types = assembly.GetTypes(); foreach (Type t in types) { // if (!t.IsSubclassOf(typeof(BaseStrategy))) { continue; } BaseStrategy stg = Activator.CreateInstance(t) as BaseStrategy; if (stg == null) { continue; } if (sStgDic.ContainsKey(t.FullName)) { LogUtil.SysLog("策略命名空间重复"); continue; } // sStgDic.Add(t.FullName, stg); stg.Start(); } } }
public static void UpdateStrategy(BaseStrategy stg) { loadStrategy(); using (MyDbContext ctx = new MyDbContext()) { T_Strategy tStg; if (!mStgDic.TryGetValue(stg.GetType().FullName, out tStg)) { tStg = new T_Strategy(); tStg.Name = stg.Name; tStg.ClassName = stg.GetType().FullName; tStg.Enable = stg.Enable; ctx.Strategys.Add(tStg); mStgDic[tStg.ClassName] = tStg; } tStg.Enable = stg.Enable; ctx.SaveChanges(); } }