Ejemplo n.º 1
0
        public int ReqOrderInsert(string pInstrument, DirectionType pDirection, OffsetType pOffset, double pPrice, int pVolume, OrderType pType = OrderType.Limit, int pCustom = 0, HedgeType pHedge = HedgeType.Speculation)
        {
            InstrumentField    dif;
            ExchangeStatusType es;

            //小节收盘:等待重新开盘
            if (DicInstrumentField.TryGetValue(pInstrument, out dif))
            {
                if (_initFlow)
                {
                    pPrice += _floConfig.FirstAddTicks * (pDirection == DirectionType.Buy ? 1 : -1) * dif.PriceTick;
                }
                //限定在涨跌板范围内
                MarketData f;
                if (_q == null)
                {
                    ShowInfo("行情接口异常");
                    return(-1);
                }
                if (!_q.DicTick.TryGetValue(pInstrument, out f))
                {
                    _q.ReqSubscribeMarketData(pInstrument);
                    Thread.Sleep(200);
                }
                if (_q.DicTick.TryGetValue(pInstrument, out f))
                {
                    ShowInfo($"合约{pInstrument}无行情");
                }
                else
                {
                    pPrice = Math.Max(f.LowerLimitPrice, Math.Min(f.UpperLimitPrice, pPrice));
                }
                //下单前修正价格为最小变动的倍数
                pPrice = (int)(pPrice / dif.PriceTick) * dif.PriceTick;

                if (DicExcStatus.TryGetValue(dif.ProductID, out es) || DicExcStatus.TryGetValue(dif.InstrumentID, out es) || DicExcStatus.TryGetValue(dif.ExchangeID.ToString(), out es))
                {
                    if (es == ExchangeStatusType.NoTrading)                    //小节收盘中:待处理
                    {
                        ShowInfo($"小节收盘,待重新开盘后再发委托:{pInstrument},{pDirection},{ pOffset},{ pPrice},{ pVolume},{pCustom}");
                        _listWaitTrading.Add(new object[] { pInstrument, pDirection, pOffset, pPrice, pVolume, pType, pCustom, pHedge });
                        return(0);
                    }
                }
            }
            return(base.ReqOrderInsert(pInstrument, pDirection, pOffset, pPrice, pVolume, pCustom, pType, pHedge));
        }
Ejemplo n.º 2
0
        private void TradeExt_OnRtnCancel(object sender, OrderArgs e)
        {
            if (!e.Value.IsLocal)
            {
                return;
            }

            if (_q == null)
            {
                ShowInfo("请先赋值行情接口");
                return;
            }

            MarketData tick;

            if (!_q.DicTick.TryGetValue(e.Value.InstrumentID, out tick))
            {
                return;
            }
            var id    = e.Value.Custom + 1;
            var times = e.Value.Custom % 100;

            if (times >= _floConfig.FollowTimes)             //达到最大追单次数
            {
                var price = e.Value.Direction == DirectionType.Buy ? tick.UpperLimitPrice : tick.LowerLimitPrice;
                ShowInfo($"[{e.Value.Custom}]达到最大追单次数({_floConfig.FollowTimes},板价追单[custom:{id}][{e.Value.InstrumentID},{e.Value.Direction},{ e.Value.Offset},{ e.Value.Direction},{price},{ e.Value.VolumeLeft}])");
                ReqOrderInsert(e.Value.InstrumentID, e.Value.Direction, e.Value.Offset, price, e.Value.VolumeLeft, OrderType.Limit, id);
            }
            else
            {
                InstrumentField instField;
                if (!DicInstrumentField.TryGetValue(e.Value.InstrumentID, out instField))
                {
                    return;
                }

                var price = e.Value.Direction == DirectionType.Buy ? (tick.AskPrice + _floConfig.NotFirstAddticks * instField.PriceTick) : (tick.BidPrice - _floConfig.NotFirstAddticks * instField.PriceTick);
                ShowInfo($"[{e.Value.Custom}]第{times - 1}次追单[id:{id}][{e.Value.InstrumentID},{e.Value.Direction},{ e.Value.Offset},{ e.Value.Direction},{price},{ e.Value.VolumeLeft}]");
                ReqOrderInsert(e.Value.InstrumentID, e.Value.Direction, e.Value.Offset, price, e.Value.VolumeLeft, OrderType.Limit, id);
            }
        }