Ejemplo n.º 1
0
        /// <summary>
        /// 解析指数消息数据包
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IndexMessageNode ParseIndexMessageNode(byte[] data)
        {
            var msg = new IndexMessageNode();


            try
            {
                var marketInfoSize = YunLib.DataHelper.StructSize <MarketMessageNode>();
                msg.marketInfo = YunLib.DataHelper.BytesToStruct <MarketMessageNode>(data.Take(marketInfoSize).ToArray());

                var NoMDEntriesSize = YunLib.DataHelper.StructSize <BigEndianUInt32>();
                msg.NoMDEntries = YunLib.DataHelper.BytesToStruct <BigEndianUInt32>(data.Skip(marketInfoSize).Take(NoMDEntriesSize).ToArray());

                UInt32 dataCount = msg.NoMDEntries;

                var startIndex = marketInfoSize + NoMDEntriesSize;

                var MDEntrySize = YunLib.DataHelper.StructSize <IndexMDEntry>();
                msg.MDEntry = new IndexMDEntry[dataCount];
                for (int i = 0; i < dataCount; ++i)
                {
                    msg.MDEntry[i] = YunLib.DataHelper.BytesToStruct <IndexMDEntry>(data.Skip(startIndex + i * MDEntrySize).Take(MDEntrySize).ToArray());
                }
            }
            catch (Exception ex)
            {
                YunLib.LogWriter.Log(ex.ToString());
            }

            return(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 深交所指数消息转云财经统一数据格式
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public IndexTickNode IndexMessageToIndexTick(IndexMessageNode data)
        {
            IndexTickNode nodeData = new IndexTickNode();

            nodeData.foxxcode = string.Format("{0}.SZ", data.marketInfo.SecurityID);
            nodeData.code     = string.Format("{0}", data.marketInfo.SecurityID);
            nodeData.date     = int.Parse(string.Format("{0}", data.marketInfo.OrigTime).Substring(0, 8));
            nodeData.time     = int.Parse(string.Format("{0}", data.marketInfo.OrigTime).Substring(8));
            nodeData.status   = "idx";
            nodeData.name     = string.Empty;

            nodeData.preclose = (int)((UInt64)data.marketInfo.PrevClosePx);
            nodeData.vol      = (long)((UInt64)data.marketInfo.TotalVolumeTrade);
            nodeData.money    = (long)((UInt64)data.marketInfo.TotalValueTrade);
            nodeData.transnum = (long)((UInt64)data.marketInfo.NumTrades);

            nodeData.buyorder           = 0;
            nodeData.sellorder          = 0;
            nodeData.buyorder_aveprice  = 0;
            nodeData.sellorder_aveprice = 0;

            foreach (var item in data.MDEntry)
            {
                if (item.MDEntryType == "3")
                {
                    nodeData.close = (int)((UInt64)item.MDEntryPx);
                    continue;
                }

                if (item.MDEntryType == "xa")
                {
                    nodeData.preclose = (int)((UInt64)item.MDEntryPx);
                    continue;
                }

                if (item.MDEntryType == "xb")
                {
                    nodeData.dopen = (int)((UInt64)item.MDEntryPx);
                    continue;
                }

                if (item.MDEntryType == "xc")
                {
                    nodeData.dhigh = (int)((UInt64)item.MDEntryPx);
                    continue;
                }

                if (item.MDEntryType == "xd")
                {
                    nodeData.dlow = (int)((UInt64)item.MDEntryPx);
                    continue;
                }
            }


            return(nodeData);
        }
Ejemplo n.º 3
0
 public void PubIndexMessage(IndexMessageNode data)
 {
     try
     {
         var xData   = this.IndexMessageToIndexTick(data);
         var dataBuf = YunLib.DataHelper.StructToBytes <IndexTickNode>(xData);
         this.pubData("index", dataBuf);
     }
     catch (Exception ex)
     {
         YunLib.LogWriter.Log(ex.ToString());
     }
 }