/// <summary> /// 股票封包解碼 /// </summary> /// <param name="item">StockEvent類別</param> internal static void Decode(StockEvent item) { switch (item.Type) { case 0x00: MitakeStorage.Storage.Clear(); //伺服器清盤(客戶端收到也立即清盤) break; case 0x30: Decode_S30.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; case 0x31: case 0xb1: case 0x3e: case 0xbe: Decode_S31.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; case 0x32: Decode_S32.Decode(MitakeStorage.Storage.GetIndex(item.Serial), item.Source); break; case 0x33: Decode_S33.Decode(MitakeStorage.Storage.GetIndex(item.Serial), item.Source); break; case 0xb3: Decode_SB3.Decode(MitakeStorage.Storage.GetIndex(item.Serial), item.Source); break; case 0x34: Decode_S34.Decode(MitakeStorage.Storage.GetIndex(item.Serial), item.Source); break; case 0x36: Decode_S36.Decode(MitakeStorage.Storage.GetIndex(item.Serial), item.Source); break; case 0x37: Decode_S37.Decode(item.Serial, item.Source); break; case 0x38: Decode_S38.Decode(item.Serial, item.Source); break; case 0x3b: case 0xbb: case 0x3f: case 0xbf: Decode_S3B.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; case 0x3c: Decode_S3C.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; case 0x3d: Decode_S3D.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; case 0xf1: Decode_SF1.Decode(MitakeStorage.Storage.GetQuote(item.Serial), item.Source); break; default: break; } }
internal void Decode(StockEvent item, bool IsDecode) { item.Type = item.Source.Data[6]; item.Serial = (item.Source.Data[4] << 8) + item.Source.Data[5]; if (IsDecode) { switch (item.Header) { case 0x53: //台灣股票証期權 lock (__oLockObj) { DecodeStock.Decode(item); } break; } } }
private void StockClient_onStock(object sender, StockEvent e) { switch (e.Header) { case 0x4d: //Mcp命令封包回應解碼 switch (e.Type) { case 0xf0: //訂閱完成通知回應 case 0xf1: //回補完成通知回應 int iSerial = e.Serial; if (iSerial > 0) { //有股票流水號 IQuote cQuote = null; switch(iSerial) { case 9998: //OTC上櫃指數 case 9999: //TWI加權指數 cQuote = MitakeStorage.Storage.GetIndex(iSerial); if (e.Type == 0xf1) { (cQuote as MitakeIndex).ComplementStatus = ComplementStatus.Complemented; } break; default: cQuote = MitakeStorage.Storage.GetQuote(iSerial); if (e.Type == 0xf1) { (cQuote as MitakeQuote).ComplementStatus = ComplementStatus.Complemented; } break; } if (cQuote != null) { if (e.Type == 0xf0) { OnSubscribeCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId)); } else { OnComplementCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId)); } } } break; case 0xf8: //股票代號回補完畢通知回應 this.IsLogin = true; //設定登入完成的旗標 if (this.IsUpdate) { //是否要更新 this.Save(); //更新報價服務器的設定值 } string sName = this.ExchangeName; AbstractExchange cExchange = ProductManager.Manager.GetExchange(sName); if (cExchange.IsUpdate) { //檢查是否需要更新交易所商品代號表 cExchange.Save(); //如果要更新則儲存更新後的結果 } if (logger.IsInfoEnabled) logger.Info("[QuoteService.Login] Login service success..."); OnLoginCompleted(); break; } break; case 0x53: //股票資訊封包 switch (e.Type) { case 0x00: //收到清盤資訊 __bReset = true; //如果收到清盤指令, 設定旗標 __bReseted = false; //將已經清盤完畢的旗標清除 ReLogin(); //重新登入伺服器 break; case 0x31: //即時成交資訊 case 0xb1: //即時成交資訊 case 0x3e: //即時成交資訊 case 0xbe: //即時成交資訊 if (sender == __cSocket) { //比較是否為即時Socket送來的資訊 IQuote cQuote = MitakeStorage.Storage.GetQuote(e.Serial); if (cQuote != null) { OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cQuote)); } } break; case 0x32: //大盤指數資訊 case 0x33: //大盤成交金額資訊 case 0x34: //大盤委買委賣資訊 if (sender == __cSocket) { //比較是否為即時Socket送來的資訊 IQuote cIndex = MitakeStorage.Storage.GetIndex(e.Serial); if (cIndex != null) { OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cIndex)); } } break; case 0x35: //即時公告資訊(三竹傳來的新聞或是公告) MitakeNotice cNotice = Decode_S35.Decode(e.Serial, e.Source); if (cNotice != null) { OnNotice(new QuoteNoticeEvent(this.DataSource, cNotice)); } break; } break; } }
/// <summary> /// 解碼國際金融封包 /// </summary> /// <param name="socket">作用中的Socket</param> /// <param name="item">StockEvent類別</param> /// <param name="isDecode">是否啟動解碼功能</param> private static void DecodeFinance(Socket socket, StockEvent item, bool isDecode) { switch (item.Header) { case 0x23: //上午時間封包 case 0x24: //下午時間封包 item.Type = 0x54; //時間封包 'T' TimerEvent cTimer = DecodeTime.Decode(item.Source, isDecode); if (cTimer != null) { if (TimerProc != null) { TimerProc(socket, cTimer); } } break; case 0x4d: //Mcp命令封包回應解碼 DecodeReturn.Decode(item, isDecode); break; case 0x41: //國際匯市現價[原編碼] case 0x43: //國際匯市最高價[原編碼] case 0x44: //國際匯市最低價[原編碼] case 0x4f: //國際匯市開盤價[原編碼] case 0x50: //國際匯市昨收價[原編碼] item.Type = 1; //國際匯市 break; case 0x2b: //國際期貨BID價[原編碼] case 0x2d: //國際期貨ASK價[原編碼] case 0x31: //國際期貨現價[原編碼] case 0x35: //國際期貨收盤價[原編碼] case 0x36: //國際期貨昨收價[原編碼] case 0x37: //國際期貨成交量[原編碼] case 0x38: //國際期貨未平倉量[原編碼] case 0x68: //國際期貨最高價[原編碼] case 0x6c: //國際期貨最低價[原編碼] case 0x6f: //國際期貨開盤價[原編碼] item.Type = 0; //國際期貨 break; default: __cFinance.Decode(item, isDecode); break; } if (StockProc != null) StockProc(socket, item); }
/// <summary> /// 建構子 /// </summary> /// <param name="Buffer">PacketBuffer 類別</param> public SocketToken(PacketBuffer Buffer) { __cStockEvent = new StockEvent(); __cMcpEvent = new McpPacketEvent(); __cPackage = new PacketBuffer(4096); __cTempBuffer = new PacketBuffer(MAX_BUFFER_SIZE); if (Buffer == null) { __cRecvBuffer = new PacketBuffer(MAX_BUFFER_SIZE); } else { __cRecvBuffer = Buffer; } }
/// <summary> /// Mcp命令封包回應解碼 /// </summary> /// <param name="item">StockEvent類別</param> /// <param name="IsDecode">是否啟動解碼功能</param> internal static void Decode(StockEvent item, bool IsDecode) { item.Type = item.Source.Data[6]; item.Serial = (item.Source.Data[4] << 8) + item.Source.Data[5]; }