示例#1
0
        private void loadStrategy()
        {
            //获取文件列表
            string[] files = new string[] { };
            try
            {
                files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\strategys");
            }
            catch (Exception ex)
            {
                LogUtils.EnginLog(ex.StackTrace);
            }

            //加载策略
            foreach (string f in files)
            {
                Assembly assembly = Assembly.LoadFrom(f);
                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;
                    }

                    addStrategy(t.Name, stg);
                }
            }
        }
示例#2
0
        internal void addStrategy(string name, BaseStrategy strategy)
        {
            //策略去重
            if (mStrategyMap.ContainsKey(name))
            {
                return;
            }

            //交易接口
            if (mTdProvider != null)
            {
                strategy.TdProvider = mTdProvider;
            }

            //行情映射
            mStrategyMap.Add(name, strategy);
            string[] instIDs = strategy.OnLoadInstrument();
            foreach (string instID in instIDs)
            {
                HashSet <BaseStrategy> strategySet;
                if (!mInstIDStrategyMap.TryGetValue(instID, out strategySet))
                {
                    strategySet = new HashSet <BaseStrategy>();
                }
                strategySet.Add(strategy);
                mInstIDStrategyMap[instID] = strategySet;
            }

            //启动策略
            strategy.SendStart();
        }
示例#3
0
 public Order(BaseStrategy strategy, string instrumentID, DirectionType direction, double price, int volume)
 {
     this.mStrategy     = strategy;
     this.mInstrumentID = instrumentID;
     this.mDirection    = direction;
     this.mPrice        = price;
     this.mOrderTime    = DateTime.Now;
     this.mVolume       = volume;
     this.mVolumeLeft   = volume;
     this.mStatus       = OrderStatus.Normal;
 }