Esempio n. 1
0
 public StrategyPosition(BaseStrategy strategy, Instrument instrument, long vol, DateTime lastTime)
 {
     mStrategy   = strategy;
     mInstrument = instrument;
     mVol        = vol;
     mLastTime   = lastTime;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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();
                }
            }
        }
Esempio n. 4
0
 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();
     }
 }