/// <summary> /// 买入操作 /// </summary> /// <returns></returns> public bool doBuy() { showBeginMessage("选择买入股票..."); try { //创建策略上下文 createStrategyContext(); //取得策略 String strategyname = props.Get <String>("strategy"); KeyValuePair <IStrategyMeta, insp.Utility.Bean.Properties> kv = context.GetStrateMetaAndParam(strategyname); if (kv.Key == null || kv.Value == null) { throw new Exception("缺少有效策略"); } StrategyInstance instance = (StrategyInstance)kv.Key.CreateInstance("1", kv.Value, ""); //取得买入算法类 String buyername = kv.Value.Get <String>("buyer"); Buyer buyer = (Buyer)instance.Buyer; if (buyer == null) { throw new Exception("缺少有效的卖出策略:" + buyername); } List <TradeInfo> tradeInfos = buyer.DoBuy(kv.Value, this.tradeDate, context); if (tradeInfos != null && tradeInfos.Count >= 0) { String tradeFilename = FileUtils.GetDirectory("records") + "trades.csv"; buyEntrust.AddRange(tradeInfos); File.AppendAllLines(tradeFilename, buyEntrust.ConvertAll(x => x.ToText()).ToArray()); } return(true); }catch (Exception e) { showResultMessage("买入操作异常", -1, e.Message); return(false); } }