예제 #1
0
        /// <summary>
        /// 行情更新。
        /// </summary>
        /// <remarks>行情数据。</remarks>
        /// <returns></returns>
        public override void UpdateMarketData(USeMarketData marketData)
        {
            Debug.Assert(m_kLine != null);

            Debug.Assert(m_componentDic.ContainsKey(marketData.Instrument.InstrumentCode));

            if (m_componentDic.ContainsKey(marketData.Instrument.InstrumentCode))
            {
                m_componentDic[marketData.Instrument.InstrumentCode] = marketData;
            }
            else
            {
                return;
            }

            if (m_allowCalc == false)
            {
                CheckIsAllowCalc();
            }

            if (m_allowCalc == false)
            {
                return;
            }

            CalcIndexKLine();

            if (DateTime.Now >= m_nextPublishTime || m_kLine.SettlementPrice > 0m)
            {
                m_publisher.PublishKLine(m_kLine.Clone());

                m_nextPublishTime = DateTime.Now.AddTicks(m_publishInterval.Ticks);
            }
        }
예제 #2
0
        /// <summary>
        /// 行情更新。
        /// </summary>
        /// <remarks>行情数据。</remarks>
        /// <returns></returns>
        public override void UpdateMarketData(USeMarketData marketData)
        {
            if (m_kLine == null)
            {
                m_kLine = CreateFirstKLine(marketData);
            }
            else
            {
                if (marketData.Volume < m_kLine.Volumn)
                {
                    return;
                }

                if (GetCycleTime(marketData.UpdateTime) == m_kLine.DateTime)
                {
                    int           volumeDiff = marketData.Volume - m_kLine.Volumn;
                    USeActiveSide activeSide = GetActiveSide(marketData);
                    int           askVolume  = 0;
                    int           bidVolume  = 0;
                    if (activeSide == USeActiveSide.Ask)
                    {
                        askVolume = volumeDiff;
                    }
                    else if (activeSide == USeActiveSide.Bid)
                    {
                        bidVolume = volumeDiff;
                    }
                    else
                    {
                        Debug.Assert(activeSide == USeActiveSide.None);
                        askVolume = (int)(volumeDiff / 2);
                        bidVolume = volumeDiff - askVolume;
                    }

                    m_kLine.Open               = marketData.OpenPrice;
                    m_kLine.High               = marketData.HighPrice;
                    m_kLine.Low                = marketData.LowPrice;
                    m_kLine.Close              = marketData.LastPrice;
                    m_kLine.Volumn             = marketData.Volume;
                    m_kLine.Turnover           = marketData.Turnover;
                    m_kLine.OpenInterest       = marketData.OpenInterest;
                    m_kLine.SettlementPrice    = marketData.SettlementPrice;
                    m_kLine.PreSettlementPrice = marketData.PreSettlementPrice;
                    m_kLine.BidVolumn         += bidVolume;
                    m_kLine.AskVolumn         += askVolume;
                    m_kLine.AvgPrice           = marketData.AvgPrice;
                    if (marketData.OpenInterest != 0m)
                    {
                        m_kLine.SpeculateRadio = marketData.Volume / marketData.OpenInterest;
                    }
                    else
                    {
                        m_kLine.SpeculateRadio = 0m;
                    }

                    Debug.Assert(m_kLine.BidVolumn + m_kLine.AskVolumn == m_kLine.Volumn);

                    //计算资金总沉淀(盘中就用最新价计算资金沉淀,待下午结算价出来之后,按照结算价再更新一次)
                    int     perSharesContract       = GetInstrumentPerSharesContract(marketData.Instrument.InstrumentCode);                   //合约规模
                    decimal exchangeLongMarginRatio = GetExchangeLongMarginRatio(marketData.Instrument.InstrumentCode);                       //保证金
                    m_kLine.SendimentaryMoney = marketData.OpenInterest * marketData.LastPrice * perSharesContract * exchangeLongMarginRatio; //资金沉淀
                }
                else
                {
                    m_eventLogger.WriteError(string.Format("[YM]{0} receive different data,Code:{3},KLindDate:{1},MarketData:{2}",
                                                           ToString(), m_kLine.DateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                                           marketData.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                                           m_instrument.InstrumentCode.ToString()));
                    //Debug.Assert(false);
                    m_publisher.PublishKLine(m_kLine.Clone());
                    //如果是检查到该合约属于主力合约,重新克隆发送一遍存在day_kline里面作为**9999
                    if (m_isMainContract)
                    {
                        USeKLine mainKLine = m_kLine.Clone();
                        mainKLine.InstrumentCode = m_mainContractCode.InstrumentCode;
                        m_publisher.PublishKLine(mainKLine);
                    }
                    m_nextPublishTime = DateTime.Now.AddTicks(m_publishInterval.Ticks);
                    m_kLine           = CreateFirstKLine(marketData);
                    return;
                }
            }

            if (DateTime.Now >= m_nextPublishTime || m_kLine.SettlementPrice > 0m)
            {
                m_publisher.PublishKLine(m_kLine.Clone());
                //如果是检查到该合约属于主力合约,重新克隆发送一遍存在day_kline里面作为**9999
                if (m_isMainContract)
                {
                    USeKLine mainKLine = m_kLine.Clone();
                    mainKLine.InstrumentCode = m_mainContractCode.InstrumentCode;
                    m_publisher.PublishKLine(mainKLine);
                }
                m_nextPublishTime = DateTime.Now.AddTicks(m_publishInterval.Ticks);
            }
        }
예제 #3
0
        /// <summary>
        /// 行情更新。
        /// </summary>
        /// <remarks>行情数据。</remarks>
        /// <returns></returns>
        public override void UpdateMarketData(USeMarketData marketData)
        {
            Debug.Assert(marketData.Instrument.InstrumentCode == m_instrument.InstrumentCode);
            DateTime updateTime = marketData.UpdateTime;

            //if(m_lastUpdateTime.HasValue)
            //{
            //    Debug.Assert(m_lastUpdateTime.Value <= updateTime);
            //}
            //Debug.Assert(m_volume <= marketData.Volume);
            //m_lastUpdateTime = updateTime;
            //m_volume = marketData.Volume;
            if (m_tradeRange.IsTradeTime(updateTime.TimeOfDay) == false)
            {
                //非交易时间行情忽略
                return;
            }

            if (m_kLine == null)
            {
                if (m_tradeRange.IsEndTime(updateTime.TimeOfDay) == false)
                {
                    m_kLine = CreateFirstKLine(marketData);
                }
            }
            else
            {
                if (m_tradeRange.IsEndTime(updateTime.TimeOfDay))
                {
                    //交易时段结束时间行情,发布KLine并且清空
                    UpdateKLine(m_kLine, marketData);
                    m_publisher.PublishKLine(m_kLine.Clone());
                    if (m_isMainContract)
                    {
                        USeKLine mainKLine = m_kLine.Clone();
                        mainKLine.InstrumentCode = m_mainContract.InstrumentCode;
                        m_publisher.PublishKLine(mainKLine);
                    }
                    m_kLine = null;
                }
                else
                {
                    DateTime cycelTime = GetCycleTime(marketData.UpdateTime);
                    if (IsSameCycle(m_kLine.DateTime, cycelTime))
                    {
                        UpdateKLine(m_kLine, marketData);
                    }
                    else
                    {
                        m_publisher.PublishKLine(m_kLine.Clone());
                        if (m_isMainContract)
                        {
                            USeKLine mainKLine = m_kLine.Clone();
                            mainKLine.InstrumentCode = m_mainContract.InstrumentCode;
                            m_publisher.PublishKLine(mainKLine);
                        }

                        m_kLine = CreateFirstKLine(marketData);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 行情更新。
        /// </summary>
        /// <remarks>行情数据。</remarks>
        /// <returns></returns>
        public override void UpdateMarketData(USeMarketData marketData)
        {
            Debug.Assert(m_componentDic.ContainsKey(marketData.Instrument.InstrumentCode));
            if (m_componentDic.ContainsKey(marketData.Instrument.InstrumentCode) == false)
            {
                return;
            }

            m_componentDic[marketData.Instrument.InstrumentCode] = marketData;

            if (m_allowCalc == false)
            {
                CheckIsAllowCalc();
            }

            if (m_allowCalc == false)
            {
                return;
            }

            DateTime updateTime = marketData.UpdateTime;

            if (m_tradeRange.IsTradeTime(updateTime.TimeOfDay) == false)
            {
                //非交易时间行情忽略
                return;
            }

            if (m_kLine == null)
            {
                if (m_tradeRange.IsEndTime(updateTime.TimeOfDay) == false)
                {
                    //if (marketData.Instrument.InstrumentCode.StartsWith("j"))
                    //{
                    //    Debug.WriteLine(string.Format("PublishKLine,FirstKline{0},{1}",
                    //        marketData.Instrument.InstrumentCode, marketData.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")));
                    //}

                    m_kLine = CreateNewKLine(updateTime);
                }
            }
            else
            {
                if (m_tradeRange.IsEndTime(updateTime.TimeOfDay))
                {
                    //交易时段结束时间行情,发布KLine并且清空
                    CalcIndexKLine();
                    m_publisher.PublishKLine(m_kLine.Clone());
                    m_kLine = null;
                }
                else
                {
                    DateTime cycelTime = GetCycleTime(marketData.UpdateTime);
                    if (IsSameCycle(m_kLine.DateTime, cycelTime) == false)
                    {
                        if (cycelTime > m_kLine.DateTime)
                        {
                            m_publisher.PublishKLine(m_kLine.Clone());

                            //if (m_kLine.InstrumentCode.StartsWith("j"))
                            //{
                            //    Debug.WriteLine(string.Format("PublishKLine,{0},{1},{2},{3}",
                            //        m_kLine.InstrumentCode, m_kLine.DateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                            //        marketData.Instrument.InstrumentCode, marketData.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")));
                            //}
                            m_kLine = CreateNewKLine(cycelTime);
                        }
                    }

                    CalcIndexKLine();
                }
            }
        }