Example #1
0
        /// <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 0x41:
            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 0x42:
            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;
            }
        }
Example #2
0
        internal static void Decode(MitakeQuote stock, PacketBuffer buffer)
        {
            DateTime        cTime;
            bool            isHave = false;
            int             iSerial = 0;
            float           fReferPrice = 0;
            byte            bType = 0, bMode = 0, bVType = 0, bFlag = 0;
            MitakeQuoteTick cTick = null;

            int  iSize  = buffer.Length - 2;
            byte bSType = buffer.Data[6];

            buffer.Position = 7;

            if ((bSType & 0xf) == 11)
            {
                iSerial         = ((buffer[0] << 8) + buffer[1]);
                buffer.Position = 9;
            }
            else
            {
                iSerial         = (buffer[0] << 16) + (buffer[1] << 8) + buffer[2];
                buffer.Position = 10;
            }

            do
            {
                if (bSType == 0x42)
                {
                    bType = 1;
                    cTime = Time.GetSpecial(buffer);
                }
                else
                {
                    //取得類型
                    bType = BitConvert.GetValue(buffer[0], 7, 1);

                    //取得時間
                    if ((bSType & 0x80) == 0)
                    {
                        cTime = Time.GetTime(buffer);
                    }
                    else
                    {
                        cTime = Time.GetOther(buffer);
                    }
                }

                isHave     = stock.GetMitakeTick(iSerial, ref cTick);
                cTick.Time = cTime;

                bFlag = buffer[0];                 //取得價量旗標
                ++buffer.Position;

                cTick.類型 = bType;                  //類型  0=即時  1=盤後(此封包為盤後封包)

                //買賣型態(0=無法區分  1=買盤量  2=賣盤量)
                bVType    = BitConvert.GetValue(bFlag, 2, 2);
                cTick.買賣盤 = bVType;

                //取得成交價模式
                bMode       = BitConvert.GetValue(bFlag, 6, 2);
                cTick.Price = Price.GetPrice(bMode, buffer, ref fReferPrice);
                Decode_S31.CalculatePrice(stock, iSerial, cTick.Price);                 //計算 開盤 最高 最低

                //取得單量模式
                bMode        = BitConvert.GetValue(bFlag, 4, 2);
                cTick.Single = Volumn.GetVolumn(bMode, buffer);

                //取得委買價
                cTick.Bid = new DOMPrice(cTick.Price - EntrustPrice(BitConvert.GetValue(bFlag, 1, 1), buffer), cTick.Bid.Size);

                //取得委賣價
                cTick.Ask = new DOMPrice(cTick.Price + EntrustPrice(BitConvert.GetValue(bFlag, 0, 1), buffer), cTick.Ask.Size);

                //修正總成交量(伺服器會傳輸回補修正封包, 需要重新修正總成交量)
                MitakeQuoteTick cPrevTick = stock.GetPreviousTick(iSerial);
                cTick.Volume = ((cPrevTick == null) ? 0d : cPrevTick.Volume) + cTick.Single;

                if (!isHave)
                {
                    stock.今日總成交額 += cTick.Price * cTick.Single;
                }
                ++iSerial;
            } while (buffer.Position < iSize);            //End While
        }