namespace YLErp.Web.Controllers { public class trade_autoruleController : BaseController { public ActionResult List() { var optId = CurUser.UserId; var list = yldb.trade_autorule.Where(n => n.OptId == optId).ToList(); return View(list); } public ActionResult Edit(int id) { var rule = yldb.trade_autorule.Find(id); return View(rule ?? new TradeAutoRule { UnderlyingCode = "错误代码" }); } public ActionResult Edit2(string code) { TradeAutoRule rule = null; if (string.IsNullOrWhiteSpace(code)) { code = null; } if (code != null) { if (!yldb.underlying_manager.Any(n => n.UnderlyingCode == code)) { return Content("标的代码不存在:" + code); } var optId = CurUser.UserId; rule = yldb.trade_autorule.FirstOrDefault(n => n.OptId == optId && n.UnderlyingCode == code); } if (rule == null) { rule = new TradeAutoRule { UnderlyingCode = code, OptId = CurUser.UserId, MaxDelta = 25, MinDelta = -25, Enable = true, DeltaPercent = 100, PnlAdjustType = "固定" }; } return View("Edit", rule); } public JsonResult AjaxSave(TradeAutoRule req) { if (req.MaxDelta < 0 || req.MinDelta > 0) { return JsonError("请输入正确的Delta限值"); } if (req.DeltaPercent < 0 || req.DeltaPercent > 200) { return JsonError("'对冲比率'请填写0到200(包括)之间的数字"); } if (!yldb.underlying_manager.Any(n => n.UnderlyingCode == req.UnderlyingCode)) { return JsonError("标的代码不存在"); } var optId = CurUser.UserId; var rule = yldb.trade_autorule.FirstOrDefault(n => n.OptId == optId && n.UnderlyingCode == req.UnderlyingCode); if (rule != null) { rule.MinDelta = req.MinDelta; rule.MaxDelta = req.MaxDelta; rule.DeltaPercent = req.DeltaPercent; rule.Enable = req.Enable; rule.AutoExecute = req.AutoExecute; rule.PnlAdjust = req.PnlAdjust; rule.PnlAdjustType = req.PnlAdjustType; req.UpdateTime = DateTime.Now; yldb.SaveChanges(); req.id = rule.id; } else { req.OptId = optId; req.CreateTime = DateTime.Now; req.UpdateTime = DateTime.Now; yldb.trade_autorule.Add(req); yldb.SaveChanges(); } return JsonSuccess("设置对冲规则成功", req); } public JsonResult AjaxRemove(int id) { var r = yldb.trade_autorule.Find(id); if (r != null) { yldb.trade_autorule.Remove(r); yldb.SaveChanges(); } return JsonSuccess("删除成功"); } public JsonResult AjaxGetRules() { var optId = CurUser.UserId; var list = yldb.trade_autorule.Where(n => n.OptId == optId && n.Enable).ToList(); var sList = new SearchListResult { rows = list }; return Json(sList); } public JsonResult AjaxGetDetail(string code) { var optId = CurUser.UserId; var rule = yldb.trade_autorule.FirstOrDefault(n => n.OptId == optId && n.UnderlyingCode == code); return Json(rule ?? new TradeAutoRule()); } } }