コード例 #1
0
ファイル: HFForm.cs プロジェクト: ssh352/hf_trade_terminal
        //行情响应
        private void OnTick(object sender, TickEventArgs e)
        {
            if (!_q.IsLogin)
            {
                return;
            }
            this.BeginInvoke(new Action(() =>
            {
                var bs = this.dataGridViewQuote.DataSource as BindingSource;
                if (bs.IndexOf(e.Tick) < 0)
                {
                    bs.Add(e.Tick);
                }
                if ((this.labelPrice.Text == "跟盘价" || this.numericUpDownPrice.Value == 0) && e.Tick.InstrumentID == this.comboBoxInstrument.Text)
                {
                    this.labelUpper.Text          = e.Tick.UpperLimitPrice.ToString();
                    this.labelLower.Text          = e.Tick.LowerLimitPrice.ToString();
                    this.numericUpDownPrice.Value = (decimal)e.Tick.LastPrice;

                    this.labelAsk.Text    = e.Tick.AskPrice.ToString();
                    this.labelAskVol.Text = e.Tick.AskVolume.ToString();
                    this.labelBid.Text    = e.Tick.BidPrice.ToString();
                    this.labelBidVol.Text = e.Tick.BidVolume.ToString();
                }
            }));
        }
コード例 #2
0
ファイル: Plat.cs プロジェクト: yutiansut/hf_at
        private void quote_OnRtnTick(object sender, TickEventArgs e)
        {
            Product    instField;
            Instrument inst;

            if (!_dataProcess.InstrumentInfo.TryGetValue(e.Tick.InstrumentID, out inst) || !_dataProcess.ProductInfo.TryGetValue(inst.ProductID, out instField) || _t == null)
            {
                return;
            }

            Tick tick = new Tick
            {
                AskPrice        = e.Tick.AskPrice,
                AveragePrice    = e.Tick.AveragePrice,
                BidPrice        = e.Tick.BidPrice,
                LastPrice       = e.Tick.LastPrice,
                LowerLimitPrice = e.Tick.LowerLimitPrice,
                OpenInterest    = e.Tick.OpenInterest,
                UpperLimitPrice = e.Tick.UpperLimitPrice,
                AskVolume       = e.Tick.AskVolume,
                BidVolume       = e.Tick.BidVolume,
                InstrumentID    = e.Tick.InstrumentID,
                TradingDay      = int.Parse(_tradingDay),
                UpdateMillisec  = e.Tick.UpdateMillisec,
                UpdateTime      = e.Tick.UpdateTime,
                Volume          = e.Tick.Volume,
            };

            //20170720全处理,避免000的行情错误.
            //if (_t.DicExcStatus.Count > 1) //非模拟才进行处理
            if (!_dataProcess.FixTick(tick, _tradingDay, _dataProcess.InstrumentInfo[tick.InstrumentID].ProductID))    //修正tick时间格式:yyyMMdd HH:mm:ss
            {
                return;
            }
            //非交易时间不调用策略的ontick:防止59:00时触发委托信号
            var excStatus = _t.GetInstrumentStatus(e.Tick.InstrumentID);

            if (excStatus != ExchangeStatusType.Trading)
            {
                return;
            }
            foreach (var stra in _dicStrategies.Values)
            {
                if (stra.EnableTick)
                {
                    foreach (var data in stra.Datas)
                    {
                        if (data.Instrument == tick.InstrumentID)
                        {
                            if (sender == null)//tick回测
                            {
                                data.OnTick(tick);
                            }
                            else
                            {
                                ThreadPool.QueueUserWorkItem((state) => data.OnTick(tick));
                            }
                        }
                    }
                }
            }

            //处理000数据;20170719增加状态判断,非交易时段会收到脏数据!=>fixtick处理
            if (_dicTick000.TryAdd(tick.InstrumentID, tick))
            {
                return;                                             //首个tick只保存不处理
            }
            //if (_qry.Make000(md, _dicTick, out tick000))
            if (_inst888.IndexOf(tick.InstrumentID) >= 0)
            {
                if (Make000Double(tick, out Tick tick000))
                {
                    Tick TickTmp = (Tick)tick000.Clone();//传递复制体,保证不会因数据修改造成bug
                    foreach (var stra in _dicStrategies.Values.Where(n => n.EnableTick))
                    {
                        foreach (var data in stra.Datas)
                        {
                            if (data.Instrument == TickTmp.InstrumentID)
                            {
                                if (sender == null)//tick回测
                                {
                                    data.OnTick(TickTmp);
                                }
                                else
                                {
                                    ThreadPool.QueueUserWorkItem((state) => data.OnTick(TickTmp));
                                }
                            }
                        }
                    }
                    tick000.UpdateTime     = tick.UpdateTime;
                    tick000.UpdateMillisec = tick.UpdateMillisec;
                }
            }
            //更新合约数据
            _dicTick000[tick.InstrumentID] = tick; //注意f000的先后顺序
        }
コード例 #3
0
ファイル: PlatCommon.cs プロジェクト: bdxnibaba/hf_at
        void _q_OnRtnTick(object sender, TickEventArgs e)
        {
            Product            instField;
            Instrument         inst;
            ExchangeStatusType excStatus = ExchangeStatusType.Trading;

            if (!_dataProcess.InstrumentInfo.TryGetValue(e.Tick.InstrumentID, out inst) || !_dataProcess.ProductInfo.TryGetValue(inst.ProductID, out instField) || (_t != null && !_t.DicExcStatus.TryGetValue(instField._id, out excStatus)))
            {
                return;
            }

            Tick tick = new Tick
            {
                AskPrice        = e.Tick.AskPrice,
                AveragePrice    = e.Tick.AveragePrice,
                BidPrice        = e.Tick.BidPrice,
                LastPrice       = e.Tick.LastPrice,
                LowerLimitPrice = e.Tick.LowerLimitPrice,
                OpenInterest    = e.Tick.OpenInterest,
                UpperLimitPrice = e.Tick.UpperLimitPrice,
                AskVolume       = e.Tick.AskVolume,
                BidVolume       = e.Tick.BidVolume,
                InstrumentID    = e.Tick.InstrumentID,
                TradingDay      = int.Parse(_tradingDay),
                UpdateMillisec  = e.Tick.UpdateMillisec,
                UpdateTime      = e.Tick.UpdateTime,
                Volume          = e.Tick.Volume,
            };

            //20170720全处理,避免000的行情错误.
            //if (_t.DicExcStatus.Count > 1) //非模拟才进行处理
            if (!_dataProcess.FixTick(tick, _tradingDay, _dataProcess.InstrumentInfo[tick.InstrumentID].ProductID))                //修正tick时间格式:yyyMMdd HH:mm:ss
            {
                return;
            }

            foreach (var stra in _dicStrategies.Values)
            {
                if (stra.EnableTick)
                {
                    foreach (var data in stra.Datas)
                    {
                        if (data.Instrument == tick.InstrumentID)
                        {
                            if (sender == null)                            //tick回测
                            {
                                data.OnTick(tick);
                            }
                            else
                            {
                                ThreadPool.QueueUserWorkItem((state) => data.OnTick(tick));
                            }
                        }
                    }
                }
            }

            //处理000数据;20170719增加状态判断,非交易时段会收到脏数据!=>fixtick处理
            Tick f000;

            if (_dicTick000.TryGetValue(instField._id + "000", out f000))             //yyyyMMdd HH:mm:ss格式比较
            {
                if (_dicTick000.TryAdd(tick.InstrumentID, tick))
                {
                    return;                                                             //首个tick只保存不处理
                }
                if (excStatus != ExchangeStatusType.Trading)
                {
                    return;                                                                                   //只在交易时段处理数据
                }
                if (tick.UpdateTime.CompareTo(f000.UpdateTime) <= 0 || string.IsNullOrEmpty(f000.UpdateTime)) //第2个tick再处理;增加稳定性
                {
                    _dicTick000[tick.InstrumentID] = tick;                                                    //注意f000的先后顺序
                    f000.UpdateTime = tick.UpdateTime;
                    return;
                }
                f000.UpdateTime = tick.UpdateTime;

                double priceTick = instField.PriceTick;

                int         sumV = 0;
                double      sumI = 0;
                List <Tick> ts   = new List <Tick>();

                foreach (var instInfo in _dataProcess.InstrumentInfo.Values.Where(n => n.ProductID == instField._id))
                {
                    if (instInfo._id == f000.InstrumentID)
                    {
                        continue;
                    }
                    Tick md;
                    if (!_dicTick000.TryGetValue(instInfo._id, out md))
                    {
                        continue;
                    }
                    if (md.OpenInterest <= 0)
                    {
                        continue;
                    }
                    ts.Add(md);
                }
                //无有用数据:不处理
                if (ts.Count > 0)
                {
                    foreach (var v in ts)
                    {
                        sumV += v.Volume;
                        sumI += v.OpenInterest;
                    }

                    f000.Volume       = sumV;
                    f000.OpenInterest = sumI;
                    f000.UpdateTime   = tick.UpdateTime;

                    //数据初始化
                    f000.LastPrice    = 0;
                    f000.BidPrice     = 0;
                    f000.BidVolume    = 0;
                    f000.AskPrice     = 0;
                    f000.AskVolume    = 0;
                    f000.AveragePrice = 0;

                    foreach (var v in ts)
                    {
                        double rate = v.OpenInterest / sumI;

                        f000.LastPrice    += (v.LastPrice * rate);
                        f000.BidPrice     += (v.BidPrice * rate);
                        f000.BidVolume    += v.BidVolume;
                        f000.AskPrice     += (v.AskPrice * rate);
                        f000.AskVolume    += v.AskVolume;
                        f000.AveragePrice += (v.AveragePrice * rate);
                    }
                    //数据修正
                    f000.LastPrice    = Math.Round(f000.LastPrice / priceTick, 0) * priceTick;
                    f000.BidPrice     = Math.Round(f000.BidPrice / priceTick, 0) * priceTick;
                    f000.AskPrice     = Math.Round(f000.AskPrice / priceTick, 0) * priceTick;
                    f000.AveragePrice = Math.Round(f000.AveragePrice / priceTick, 0) * priceTick;

                    foreach (var stra in _dicStrategies.Values)
                    {
                        if (stra.EnableTick)
                        {
                            foreach (var data in stra.Datas)
                            {
                                if (data.Instrument == f000.InstrumentID)
                                {
                                    if (sender == null)                                    //tick回测
                                    {
                                        data.OnTick(tick);
                                    }
                                    else
                                    {
                                        ThreadPool.QueueUserWorkItem((state) => data.OnTick(f000));
                                    }
                                }
                            }
                        }
                    }
                }
                //更新合约数据
                _dicTick000[tick.InstrumentID] = tick;                 //注意f000的先后顺序
            }
        }
コード例 #4
0
 private void _q_OnRtnTick(object sender, TickEventArgs e)
 {
     Log($"{e.Tick.InstrumentID}\t{e.Tick.LastPrice}");
 }
コード例 #5
0
ファイル: Test.cs プロジェクト: zhuzhenping/hf_ctp_cs_proxy
 private void _q_OnRtnTick(object sender, TickEventArgs e)
 {
     Log($"{e.Tick.InstrumentID}\t{e.Tick.LastPrice}");
     _q.ReqUnSubscribeMarketData(e.Tick.InstrumentID);
 }
コード例 #6
0
 private void _q_OnRtnTick(object sender, TickEventArgs e)
 {
     Log($"Tick::::::: {e.Tick.InstrumentID}\t{e.Tick.LastPrice}");
     _NowPrice = e.Tick.LastPrice.ToString();
 }