コード例 #1
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
        }
コード例 #2
0
		internal static void Decode(MitakeQuote stock, Mitake.Sockets.Data.PacketBuffer Buffer) {
			DateTime cTime;
			float fReferPrice = 0;
			double dAskP = 0, dAskV = 0, dBidP = 0, dBidV = 0, dPrice = 0, dVolume = 0, dSingle = 0;
			byte bType = 0, bMode = 0, bPType = 0, bVType = 0, bFlag = 0, b類型 = 0, b買賣盤 = 0, b價格類型 = 0;

			int iSerial = 0, iSize = Buffer.Length - 2;
			byte bSType = Buffer.Data[6];

			Buffer.Position = 7;

			//取得序號
			if ((bSType & 0x31) == 0x31) {  //0x31 0xb1 與不等於 0x41 (夜盤) 序號都兩個位元組
				iSerial = (Buffer[0] << 8) + Buffer[1];
				Buffer.Position = 9;
			} else {  //其他類型序號都是三個位元組
				iSerial = (Buffer[0] << 16) + (Buffer[1] << 8) + Buffer[2];
				Buffer.Position = 10;
			}

			if (bSType == 0x41) {  //夜盤代號 0x41 (時間格式不同)
				bType = 0;
				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);
				}
			}

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

				b類型 = bType;  //類型  0=即時  1=盤後

				//判斷是否是單量(1110B)
				if (BitConvert.GetValue(bFlag, 0, 4) == 0xe) {
					//買賣型態(0=無法區分買賣盤量  1=買量  2=賣量)
					bVType = BitConvert.GetValue(bFlag, 6, 2);
					b買賣盤 = bVType;

					bMode = BitConvert.GetValue(bFlag, 4, 2);
					dSingle = Volumn.GetVolumn(bMode, Buffer);
				} else {
					//買賣型態(0=無法確定 1=買盤 2=賣盤 3=委託買賣)
					bVType = BitConvert.GetValue(bFlag, 2, 2);

					//價位型態(0=一般成交價 1=開 2=高 3=低)
					//如果買賣型態為委託買賣(0=委買 1=委賣)
					bPType = BitConvert.GetValue(bFlag, 0, 2);

					//取得成交價或委託價模式
					bMode = BitConvert.GetValue(bFlag, 6, 2);

					switch (bVType) {
						case 3: //委買委賣格式
							if (bPType == 0) {
								dBidP = Price.GetPrice(bMode, Buffer, ref fReferPrice);

								//取得委買量模式
								bMode = BitConvert.GetValue(bFlag, 4, 2);
								dBidV = Volumn.GetVolumn(bMode, Buffer);
							} else {
								dAskP = Price.GetPrice(bMode, Buffer, ref fReferPrice);

								//取得委賣量模式
								bMode = BitConvert.GetValue(bFlag, 4, 2);
								dAskV = Volumn.GetVolumn(bMode, Buffer);
							}
							break;
						default: //一般成交格式
							b價格類型 = bPType;
							dPrice = Price.GetPrice(bMode, Buffer, ref fReferPrice);

							CalculatePrice(stock, iSerial, dPrice);

							bMode = BitConvert.GetValue(bFlag, 4, 2);
							dVolume = Volumn.GetVolumn(bMode, Buffer);
							break;
					}
				}
			} while (Buffer.Position < iSize); //End While

			MitakeQuoteTick cTick = null;
			bool bHave = stock.GetMitakeTick(iSerial, ref cTick);
			MitakeQuoteTick cPrevTick = stock.GetPreviousTick(iSerial);
			if (bHave) {
				cTick.Time = cTime;
				cTick.Ask = new DOMPrice(dAskP, dAskV);
				cTick.Bid = new DOMPrice(dBidP, dBidV);
			} else {
				cTick.類型 = b類型;
				cTick.買賣盤 = b買賣盤;
				cTick.價格類型 = b價格類型;
				cTick.Time = cTime;
				cTick.Single = dSingle;
				cTick.Price = (dPrice == 0 && cPrevTick != null) ? cPrevTick.Price : dPrice;
				cTick.Volume = (dVolume == 0 && cPrevTick != null) ? cPrevTick.Volume : dVolume;
				cTick.Ask = (dAskP == 0 && dAskV == 0 && cPrevTick != null) ? cPrevTick.Ask : new DOMPrice(dAskP, dAskV);
				cTick.Bid = (dBidP == 0 && dBidV == 0 && cPrevTick != null) ? cPrevTick.Bid : new DOMPrice(dBidP, dBidV);

				if (dPrice > 0 && dVolume > 0) {  //如果有價量才計算成交金額與更換最新的即時資訊訊息
					stock.今日總成交額 += cTick.Price * (cTick.Volume - ((cPrevTick == null) ? 0d : cPrevTick.Volume));
					if (iSerial > stock.即時資訊.Serial) {
						stock.今日總成交量 = dVolume;
						stock.即時資訊 = cTick;
					}
				}
			}

			//填入委託價格第一檔
			CalculateEntrust(stock, cTick);

			//計算委託價格買賣盤
			MitakeEntrust.ComparePrice(cTick, cPrevTick);
			++stock.UpdateCount;
		}