Beispiel #1
0
        private int close(string pInstrument, DirectionType pPosiDire, int pCloseLots, MarketData pTick, bool pForce, double pPrice, int pCustom)
        {
            PositionField pf;

            if (!DicPositionField.TryGetValue($"{pInstrument}_{pPosiDire}", out pf))
            {
                return(pCloseLots);
            }

            var dire     = pPosiDire == DirectionType.Buy ? DirectionType.Sell : DirectionType.Buy;
            var price    = !double.IsNaN(pPrice) ? pPrice : (dire == DirectionType.Buy ? (pForce ? pTick.UpperLimitPrice : pTick.AskPrice) : (pForce ? pTick.LowerLimitPrice : pTick.BidPrice)); //板价发单
            var volClose = Math.Min(pCloseLots, pf.Position);                                                                                                                                    //可平量
            var rtn      = pCloseLots - volClose;

            if (DicInstrumentField[pInstrument].ExchangeID == Exchange.SHFE && pf.TdPosition > 0)
            {
                var tdClose = Math.Min(pf.TdPosition, volClose);
                ReqOrderInsert(pInstrument, dire, OffsetType.CloseToday, price, tdClose, pCustom: pCustom);
                volClose -= tdClose;
            }
            if (volClose > 0)
            {
                ReqOrderInsert(pInstrument, dire, OffsetType.Close, price, volClose, pCustom: pCustom);
            }
            return(rtn);
        }