public void PubStockMessage(StockMessageNode data) { try { var xData = this.StockMessageMarketTick(data); var dataBuf = YunLib.DataHelper.StructToBytes <MarketTickNode>(xData); this.pubData("stock", dataBuf); this.mLastMarketData = xData; } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } }
/// <summary> /// 深交所股票消息转云财经统一数据格式 /// </summary> /// <param name="data"></param> /// <returns></returns> public MarketTickNode StockMessageMarketTick(StockMessageNode data) { MarketTickNode nodeData = new MarketTickNode(); nodeData.foxxcode = string.Format("{0}.SZ", MessageHelper.GetMessageString(data.marketInfo.SecurityID).Trim()); nodeData.code = string.Format("{0}", MessageHelper.GetMessageString(data.marketInfo.SecurityID).Trim()); 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 = MessageHelper.GetMessageString(data.marketInfo.TradingPhaseCode).Trim(); nodeData.name = string.Empty; nodeData.preclose = (int)((UInt64)data.marketInfo.PrevClosePx); nodeData.vol = (long)((Int64)data.marketInfo.TotalVolumeTrade / 100); nodeData.money = (long)((Int64)data.marketInfo.TotalValueTrade / 10000); nodeData.transnum = (long)((Int64)data.marketInfo.NumTrades); nodeData.buyorder = 0; nodeData.sellorder = 0; nodeData.buyorder_aveprice = 0; nodeData.sellorder_aveprice = 0; nodeData.buy1 = 0; nodeData.buy1_count = 0; nodeData.sell1 = 0; nodeData.sell1_count = 0; nodeData.buy2 = 0; nodeData.buy2_count = 0; nodeData.sell2 = 0; nodeData.sell2_count = 0; nodeData.buy3 = 0; nodeData.buy3_count = 0; nodeData.sell3 = 0; nodeData.sell3_count = 0; nodeData.buy4 = 0; nodeData.buy4_count = 0; nodeData.sell4 = 0; nodeData.sell4_count = 0; nodeData.buy5 = 0; nodeData.buy5_count = 0; nodeData.sell5 = 0; nodeData.sell5_count = 0; nodeData.buy6 = 0; nodeData.buy6_count = 0; nodeData.sell6 = 0; nodeData.sell6_count = 0; nodeData.buy7 = 0; nodeData.buy7_count = 0; nodeData.sell7 = 0; nodeData.sell7_count = 0; nodeData.buy8 = 0; nodeData.buy8_count = 0; nodeData.sell8 = 0; nodeData.sell8_count = 0; nodeData.buy9 = 0; nodeData.buy9_count = 0; nodeData.sell9 = 0; nodeData.sell9_count = 0; nodeData.buy10 = 0; nodeData.buy10_count = 0; nodeData.sell10 = 0; nodeData.sell10_count = 0; foreach (var item in data.MDEntry) { var mdType = MessageHelper.GetMessageString(item.MDEntryType).Trim(); //买五档 if (mdType == "0") { if (item.MDPriceLevel == 1) { nodeData.buy1 = (long)((UInt64)item.MDEntryPx / 100); nodeData.buy1_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 2) { nodeData.buy2 = (long)((UInt64)item.MDEntryPx / 100); nodeData.buy2_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 3) { nodeData.buy3 = (long)((UInt64)item.MDEntryPx / 100); nodeData.buy3_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 4) { nodeData.buy4 = (long)((UInt64)item.MDEntryPx / 100); nodeData.buy4_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 5) { nodeData.buy5 = (long)((UInt64)item.MDEntryPx / 100); nodeData.buy5_count = (long)((UInt64)item.MDEntrySize / 100); } } //卖五档 if (mdType == "1") { if (item.MDPriceLevel == 1) { nodeData.sell1 = (long)((UInt64)item.MDEntryPx / 100); nodeData.sell1_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 2) { nodeData.sell2 = (long)((UInt64)item.MDEntryPx / 100); nodeData.sell2_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 3) { nodeData.sell3 = (long)((UInt64)item.MDEntryPx / 100); nodeData.sell3_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 4) { nodeData.sell4 = (long)((UInt64)item.MDEntryPx / 100); nodeData.sell4_count = (long)((UInt64)item.MDEntrySize / 100); } if (item.MDPriceLevel == 5) { nodeData.sell5 = (long)((UInt64)item.MDEntryPx / 100); nodeData.sell5_count = (long)((UInt64)item.MDEntrySize / 100); } } //最新价格 if (mdType == "2") { nodeData.close = (int)((UInt64)item.MDEntryPx / 100); continue; } //开盘价格 if (mdType == "4") { nodeData.dopen = (int)((UInt64)item.MDEntryPx / 100); continue; } //最高价格 if (mdType == "7") { nodeData.dhigh = (int)((UInt64)item.MDEntryPx / 100); continue; } //最低价格 if (mdType == "8") { nodeData.dlow = (int)((UInt64)item.MDEntryPx / 100); continue; } //平均委托买,不知道level1有不有 if (mdType == "x3") { nodeData.buyorder = (long)((UInt64)item.MDEntrySize / 100); nodeData.buyorder_aveprice = (int)((UInt64)item.MDEntryPx / 100); continue; } //平均委托卖,不知道level1有不有 if (mdType == "x4") { nodeData.sellorder = (long)((UInt64)item.MDEntrySize / 100); nodeData.sellorder_aveprice = (int)((UInt64)item.MDEntryPx / 100); continue; } } nodeData.status = this.getStatus(nodeData); return(nodeData); }
public string getStatus(MarketTickNode data) { string sRet = "0"; try { string firstCode = string.Empty; string secondCode = string.Empty; if (data.status.Length > 0) { firstCode = data.status.Substring(0, 1); } if (data.status.Length > 1) { secondCode = data.status.Substring(1, 1); } //未开盘 if (firstCode == "S") { sRet = "3"; return(sRet); } //已经休市 if (firstCode == "B") { sRet = "4"; return(sRet); } //已经闭市 if (firstCode == "E") { sRet = "5"; return(sRet); } //临时停牌 if (firstCode == "H") { sRet = "6"; return(sRet); } //全天停牌 if (secondCode == "1") { sRet = "7"; return(sRet); } //暂停交易,如熔断等特殊情况 if (firstCode == "V") { sRet = "8"; return(sRet); } //正常交易 if (secondCode == "0") { //涨停 if (data.sell1 == 0 && data.sell1_count == 0) { if (data.buy1 > 0 && data.buy1_count > 0) { sRet = "1"; return(sRet); } } //跌停 if (data.buy1 == 0 && data.buy1_count == 0) { if (data.sell1 > 0 && data.sell1_count > 0) { sRet = "2"; return(sRet); } } } } catch (Exception ex) { YunLib.LogWriter.Log(ex.ToString()); } return(sRet); }
public static MarketSecModel FromStruct(MarketTickNode iNode) { MarketSecModel iData = new MarketSecModel(); iData.foxxcode = iNode.foxxcode; iData.code = iNode.code; iData.date = iNode.date; iData.time = iNode.time; iData.status = iNode.status; iData.preclose = iNode.preclose; iData.close = iNode.close; iData.ratio = 0; iData.dopen = iNode.dopen; iData.dhigh = iNode.dhigh; iData.dlow = iNode.dlow; iData.vol = iNode.vol; iData.money = iNode.money; iData.transnum = iNode.transnum; iData.name = iNode.name; iData.buyorder = iNode.buyorder; iData.sellorder = iNode.sellorder; iData.buyorder_aveprice = iNode.buyorder_aveprice; iData.sellorder_aveprice = iNode.sellorder_aveprice; iData.buy1 = iNode.buy1; iData.buy2 = iNode.buy2; iData.buy3 = iNode.buy3; iData.buy4 = iNode.buy4; iData.buy5 = iNode.buy5; iData.buy6 = iNode.buy6; iData.buy7 = iNode.buy7; iData.buy8 = iNode.buy8; iData.buy9 = iNode.buy9; iData.buy10 = iNode.buy10; iData.buy1_count = iNode.buy1_count; iData.buy2_count = iNode.buy2_count; iData.buy3_count = iNode.buy3_count; iData.buy4_count = iNode.buy4_count; iData.buy5_count = iNode.buy5_count; iData.buy6_count = iNode.buy6_count; iData.buy7_count = iNode.buy7_count; iData.buy8_count = iNode.buy8_count; iData.buy9_count = iNode.buy9_count; iData.buy10_count = iNode.buy10_count; iData.sell1 = iNode.sell1; iData.sell2 = iNode.sell2; iData.sell3 = iNode.sell3; iData.sell4 = iNode.sell4; iData.sell5 = iNode.sell5; iData.sell6 = iNode.sell6; iData.sell7 = iNode.sell7; iData.sell8 = iNode.sell8; iData.sell9 = iNode.sell9; iData.sell10 = iNode.sell10; iData.sell1_count = iNode.sell1_count; iData.sell2_count = iNode.sell2_count; iData.sell3_count = iNode.sell3_count; iData.sell4_count = iNode.sell4_count; iData.sell5_count = iNode.sell5_count; iData.sell6_count = iNode.sell6_count; iData.sell7_count = iNode.sell7_count; iData.sell8_count = iNode.sell8_count; iData.sell9_count = iNode.sell9_count; iData.sell10_count = iNode.sell10_count; return(iData); }