/// <summary> /// 下单 /// </summary> /// <param name="side"></param> /// <param name="qty"></param> public void SendOrder(OrderSide side, double qty) { if (!TimeHelper.IsTradingTime()) { return; } if (qty <= 0) { return; } // 为减少滑点,对数量少的单子直接市价单 bool bMarketOrder = false; if (EnumOpenClose.OPEN == TextParameter.OpenClose) { if (qty <= MarketOpenQtyThreshold) { bMarketOrder = true; } } else { if (qty <= MarketCloseQtyThreshold) { bMarketOrder = true; } } //lock(this) { if (bMarketOrder) { SendMarketOrder(side, qty, TextParameter.ToString()); } else { SendLimitOrder(side, qty, PriceHelper.GetMatchPrice(this, side, Jump), TextParameter.ToString()); } } }
// 这里假设已经挂的单子已经是按最优数量进行处理过,目标是直接挂单 // 目前对前两层做智能开平,后面的全用开仓单 // 因为后面的使用平仓单,还要处理复杂的大量开挂单的问题。 // 实际上不能太深,因为深了占用资金 public int 单边全面补单(OrderBook_OneSide_Order buy1, OrderBook_OneSide_Size buy2) { int cnt = 0; List <CopyOrder> list = new List <CopyOrder>(); // 方向不对,不可能补单 if (buy1.Side != buy2.Side) { return(cnt); } TextCommon tp = buy1.Side == OrderSide.Buy ? TextParameterBid : TextParameterAsk; PositionRecord LongShort = buy1.Side == OrderSide.Buy ? base.DualPosition.Short : base.DualPosition.Long; lock (this) { int l = 0; // 由于在别的地方做了撤单,在这buy2中的数量是大于等于buy1的 foreach (var b2 in buy2.GridList) { ++l; int level = b2.Key; double size = b2.Value; // 要补单的数量 double leave = size - buy1.SizeByLevel(level); if (leave <= 0) { continue; } double price = PriceHelper.GetPriceByLevel(level); cnt += (int)leave; // 超过两层的全用开仓 if (l > AlwaysOpenIfDepthGreatThan) { tp.OpenClose = EnumOpenClose.OPEN; tp.Text = string.Format("{0}层,开仓补单", l); } else { // 计算开平 double q = CloseTodayHelper.GetCloseAndQty(LongShort, out tp.OpenClose); if (q < leave) { tp.OpenClose = EnumOpenClose.OPEN; tp.Text = string.Format("开仓:可平量{0}<{1}", q, leave); } else { tp.Text = string.Format("平仓:可平量{0}>={1}", q, leave); } } // 入场下单 // 在模拟下,这个地方有可能导致成交回报lock //SendLimitOrder(buy2.Side, leave, price, tp.ToString()); list.Add(new CopyOrder() { Side = buy2.Side, Qty = leave, Price = price, Text = tp.ToString(), }); } } foreach (var o in list) { SendLimitOrder(o.Side, o.Qty, o.Price, o.Text); } return(cnt); }