UserPosition createPosition(int count, decimal price, OrderType type, TradeDirectType dir) { UserPosition up = new UserPosition { Order = new Order { Contract = new Contract { Code = "1", Name = "1", Coin = new Coin { Id = 1 } }, OrderType = type, Direction = dir, Count = count, DonePrice = price, DoneCount = count, }, Count = count, Trader = new Trader { } }; return(up); }
public List <Order> FindByDirAndPos(string contractCode, TradeDirectType dir, OrderType orderType) { if (!dic.ContainsKey(contractCode)) { return(new List <Order>()); } return(dic[contractCode].FindByDirAndPos(dir, orderType)); }
public void AddOrder(int contract, TradeDirectType dir, OrderType orderType, OrderPolicy policy, decimal count, decimal price, string userOpId = "") { Execute(() => { var r = srv.AddOrder(CurTrader.Id, contract, dir, orderType, policy, (int)count, price, userOpId); CurCallBack.OnOrder(new OrderDto(r.Order), r); }, "add order"); }
public List <Order> FindByDirAndPos(TradeDirectType dir, OrderType orderType) { if (dir == TradeDirectType.买) { return(sellPack.Items); } else { return(buyPack.Items); } }
public List <Order> GetByDirAndOrderType(TradeDirectType dir, OrderType type) { lock (Sync) { var q = list.Where(a => a.Direction == dir && a.OrderType == type); if (q == null) { return(new List <Order>()); } return(q.ToList()); } }
public static int GetCloseOrderCount(this Trader t, Contract c, TradeDirectType dir) { try { return(t.Orders().GetCloseCount(c, dir)); } catch (Exception e) { Singleton <TextLog> .Instance.Error(e); return(0); } }
public static Order CreateOrder(Trader who, Contract contract, TradeDirectType dir, OrderType orderType, OrderPolicy policy, int count, decimal price1) { var w = who; if (w == null) { return(null); } var c = contract; if (c == null) { return(null); } if (count <= 0) { return(null); } var price = Math.Round(price1, 2); if (price < 0) { return(null); } if (price == 0 && (policy != OrderPolicy.市价剩余转限价 && policy != OrderPolicy.市价IOC && policy != OrderPolicy.市价FOK)) { return(null); } Order o; lock (createOrderSync) { o = new Order { Id = IdService <Order> .Instance.NewId(), Contract = c, Trader = w, Count = count, ReportCount = count, Direction = dir, Price = price, OrderType = orderType, OrderPolicy = policy, State = OrderState.等待中, OrderTime = DateTime.Now }; } return(o); }
public int GetCloseCount(string ccode, TradeDirectType dir) { lock (Sync) { if (Count == 0) { return(0); } var os = list.Where(a => a != null && (a.State == OrderState.部分成交 || a.State == OrderState.等待中) && a.Contract.Code == ccode && a.Direction == dir && a.OrderType == OrderType.平仓).Select(a => a.Count).Sum(); return(os); } }
public List <Order> GetByDir(string contractCode, TradeDirectType dir) { if (!dic.ContainsKey(contractCode)) { return(new List <Order>()); } if (dir == TradeDirectType.卖) { return(dic[contractCode].SellQueue); } else { return(dic[contractCode].BuyQueue); } }
/// <summary> /// 创建委托 /// </summary> /// <param name="who"></param> /// <param name="contract"></param> /// <param name="dir"></param> /// <param name="pos"></param> /// <param name="orderType"></param> /// <param name="policy"></param> /// <param name="count"></param> /// <param name="price"></param> /// <returns></returns> public Order CreateOrder(int who, int contract, TradeDirectType dir, OrderType orderType, OrderPolicy policy, int count, decimal price) { var w = Traders.Where(a => a.Id == who).FirstOrDefault(); if (w == null) { return(null); } var c = Contracts.Where(a => a.Id == contract).FirstOrDefault(); if (c == null) { return(null); } return(EntityFactory.CreateOrder(w, c, dir, orderType, policy, count, price)); }
/// <summary> /// 下单(委托) /// </summary> /// <param name="code"></param> /// <param name="policy"></param> /// <param name="price"></param> /// <param name="count"></param> /// <param name="direct"></param> /// <param name="openclose"></param> /// <returns></returns> public JsonResult OrderIt(string code, OrderPolicy policy, decimal price, int count, TradeDirectType direct, OrderType openclose, string userOpId, string pwd = "") { try { var au = UserManager.FindByName(User.Identity.Name); if (au == null) { return(Json(new OperationResult(501, "必须登录"), JsonRequestBehavior.AllowGet)); } var u = User.GetTraderId(); if (u <= 0) { return(Json(new OperationResult { ResultCode = 500, Desc = "必须登录" }, JsonRequestBehavior.AllowGet)); } string pwdPolicy = GetInputTradeCount(); if (pwdPolicy == "n" || pwdPolicy == "1") { if (pwd != au.TradePwd) { return(Json(new OperationResult(501, "交易密码错误"), JsonRequestBehavior.AllowGet)); } } var ThisUser = adb.Users.Where(a => a.UserName == User.Identity.Name).FirstOrDefault(); if (ThisUser.PhoneNumber == "" || ThisUser.PhoneNumber == null) { return(Json(new OperationResult(1, "请进入安全中心绑定手机号"), JsonRequestBehavior.AllowGet)); } var rr = tradeMgr.OrderIt(u, code, policy, price, count, direct, openclose, userOpId); return(Json(rr, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Singleton <TextLog> .Instance.Error(e, "order it in home"); return(Json(new OperationResult { ResultCode = 600, Desc = "服务器未知错误" }, JsonRequestBehavior.AllowGet)); } }
public static List <Order> SortForDir(this List <Order> l, TradeDirectType forDir) { if (l == null) { return(new List <Order>()); } if (l.Count() < 2) { return(l); } if (forDir == TradeDirectType.买) { return(l.OrderBy(a => a.Price).ToList()); } else { return(l.OrderByDescending(a => a.Price).ToList()); } }
public OrderResultDto OrderIt(int uid, string code, OrderPolicy policy, decimal price, int count, TradeDirectType direct, OrderType openclose, string userOpId) { if (count <= 0) { return new OrderResultDto { ResultCode = 101, Desc = "数量不能小于等于0" } } ; if (price == 0 && (policy != OrderPolicy.市价FOK && policy != OrderPolicy.市价IOC && policy != OrderPolicy.市价剩余转限价)) { return(new OrderResultDto { ResultCode = 102, Desc = "非市价策略价格不能为空" }); } price = Math.Round(price, 2); var srv = MvcApplication.OptionService; var contract = srv.Model.Contracts.Where(a => a.Code == code && a.IsDel == false).FirstOrDefault(); if (contract == null) { return new OrderResultDto { ResultCode = 100, Desc = "无此合约代码" } } ; //if (uid <= 0) // return new OrderResultDto { ResultCode = 500, Desc = "必须登录" }; var r = MvcApplication.OptionService.AddOrder(uid, contract.Id, direct, openclose, policy, count, price, userOpId); return(new OrderResultDto { Desc = r.Desc, ResultCode = r.ResultCode, UserOpId = userOpId, Order = new OrderDto(r.Order) }); }
public List <Order> FindByDirAndPos(TradeDirectType dir, OrderType orderType) { try { if (dir == TradeDirectType.卖) { return(BuyList.OrderByDescending(d => d.Price).ToList()); } else { return(SellList.ToList()); } } catch (Exception ex) { Singleton <TextLog> .Instance.Error(ex, "findbydirandpos"); return(null); } }
public static int GetClosableCount(this Trader t, string code, TradeDirectType dir) { try { var p = t.GetPositionSummary(code, PositionType.权利仓); if (p == null) { return(0); } if (p.PositionType == "权利仓" && dir == TradeDirectType.买) { return(0); } if (p.PositionType == "义务仓" && dir == TradeDirectType.卖) { return(0); } if (t.Orders() == null || t.Orders().Count == 0) { return(p.Count); } var tl = t.Orders(); if (tl == null) { return(p.Count); } var c = tl.GetCloseCount(code, dir); var r = p.Count - c; return(r); } catch (Exception e) { Singleton <TextLog> .Instance.Error(e, "getclosablecountextension"); return(0); } }
public Order CreateOrder(int who, int contract, TradeDirectType dir, OrderPolicy policy, int count, decimal price) { var w = dbContext.Set <Trader>().Where(a => a.Id == who).FirstOrDefault(); if (w == null) { return(null); } var c = dbContext.Set <Contract>().Where(a => a.Id == contract).FirstOrDefault(); if (c == null) { return(null); } Order o = new Order { Contract = c, Trader = w, OrderPolicy = policy, Id = IdService <Contract> .Instance.NewId(), Count = count, Direction = dir, Price = price, State = OrderState.等待中, OrderTime = DateTime.Now }; return(o); }
PositionType GetPositionTypeForClose(TradeDirectType dir) { return(dir == TradeDirectType.买 ? Core.PositionType.义务仓 : Core.PositionType.权利仓); }
public OrderResult AddOrder(int who, int contract, TradeDirectType dir, OrderType orderType, OrderPolicy policy, int count, decimal price, string userOpId = "") { if (IsStoped) { return new OrderResult { ResultCode = 330, Desc = "系统维护中,请稍后重试" } } ; var o = Model.CreateOrder(who, contract, dir, orderType, policy, count, price); if (o == null) { return new OrderResult { ResultCode = 10, Desc = "不能创建委托,请检查参数", UserOpId = userOpId } } ; o.State = OrderState.等待中; if (!IsAcceptByFuse(o)) { return(new OrderResult { UserOpId = userOpId, Desc = "价格不能超出熔断范围", Order = o, ResultCode = 401 }); } var r = preHandler.CouldOrder(o); if (r.ResultCode == 10) { log.Info(string.Format("异常:人{0}-约{1}-向{2}-开{3}-策{4}-量{5}-价{6}-{7}", who, contract, dir, orderType, policy, count, price, userOpId)); return(new OrderResult { UserOpId = userOpId, Desc = "下单未知错误", Order = o, ResultCode = 401 }); } log.Info(string.Format("下单前检查=={0}=={1}", o, r)); if (r.IsSuccess) { var br = postHandler.Handle(o); if (!br) { return(new OrderResult { UserOpId = userOpId, Desc = "保证金不足", Order = o, ResultCode = 5 }); } log.Info(string.Format("下单后处理=={0}=={1}", o, r)); Matcher.Handle(o); log.Info(string.Format("撮合后=={0}=={1}", o, r)); } return(new OrderResult { UserOpId = userOpId, Desc = r.Desc, Order = o, ResultCode = r.ResultCode }); }
public OrderResult AddOrder(int who, int contract, TradeDirectType dir, OrderType orderType, OrderPolicy policy, int count, decimal price, string userOpId = "") { return(processor.AddOrder(who, contract, dir, orderType, policy, count, price, userOpId)); }