//大盤指數計算與補價資訊(StockId = 9999) private static void Decoder_Index_9999(MitakeIndex index, byte Module, uint value) { switch (Module) { case 0: //大盤綜合買氣(上市股票最近1000筆) index.大盤綜合買氣 = value; break; case 30: //大盤買賣比 (委買張/委賣張) index.大盤買賣比 = (float)(value * 0.01); break; default: //新編各類股買氣(該類股最近500筆,紡織、電子則為1000筆) //判斷是否為null 如果是則創建一個Dictionary if (index.類股綜合買氣 == null) { index.類股綜合買氣 = new Dictionary <int, uint>(); } if (index.類股綜合買氣.ContainsKey(Module)) { index.類股綜合買氣[Module] = value; } else { index.類股綜合買氣.Add(Module, value); } break; } }
internal static void Decode(MitakeIndex index, Mitake.Sockets.Data.PacketBuffer Buffer) { int iSize = 0; byte bMode = 0, bType = 0, bFlag = 0; iSize = Buffer.Length - 2; //移動至資料結構(時間欄位) Buffer.Position = 7; do { //取得Format旗標 bFlag = Buffer[0]; ++Buffer.Position; //取得家數大小(1~4 Byte 不固定) bMode = BitConvert.GetValue(bFlag, 6, 2); //取得家數代號(有持平家數,上漲家數,下跌家數 等......) bType = BitConvert.GetValue(bFlag, 0, 6); switch (bType) { case 0: //持平家數 index.持平家數 = Volumn.GetVolumn(bMode, Buffer); break; case 1: //未成交家數 index.未成交家數 = Volumn.GetVolumn(bMode, Buffer); break; case 2: //上漲家數 index.漲家數 = Volumn.GetVolumn(bMode, Buffer); break; case 3: //下跌家數 index.跌家數 = Volumn.GetVolumn(bMode, Buffer); break; case 4: //漲停家數 index.漲停家數 = Volumn.GetVolumn(bMode, Buffer); break; case 5: //跌停家數 index.跌停家數 = Volumn.GetVolumn(bMode, Buffer); break; } } while (Buffer.Position < iSize); //End While ++index.UpdateCount; }
/* * 指數計算及補價資訊:(<stockid:2>=999x...) * <data:N> = {<subId:1> <值:n1>}重覆直到封包結尾... */ /// <summary> /// 大盤指數計算及補價資訊 /// </summary> private static void Decoder(int StockId, MitakeIndex index, Mitake.Sockets.Data.PacketBuffer Buffer) { uint uValue = 0; bool bNegative = false; byte bMode = 0, bFlag = 0, bModule = 0; int iSize = Buffer.Length - 2; Buffer.Position = 7; do { //取得subId旗標 bFlag = Buffer[0]; ++Buffer.Position; //取得量價格式 bMode = BitConvert.GetValue(bFlag, 6, 2); bModule = BitConvert.GetValue(bFlag, 0, 6); switch (StockId) { case 9999: uValue = Volumn.GetVolumn(bMode, Buffer); Decoder_Index_9999(index, bModule, uValue); break; case 10000: if ((Buffer[0] & 0x80) == 0) { bNegative = false; //正號 } else { bNegative = true; //負號 Buffer.Data[Buffer.Position] &= 0x7f; //取消負號旗標 } uValue = Volumn.GetVolumn(bMode, Buffer); Decoder_Index_10000(index, bModule, uValue, bNegative); break; default: Volumn.GetVolumn(bMode, Buffer); break; } } while (Buffer.Position < iSize); //end while ++index.UpdateCount; }
internal static void Decode(MitakeIndex index, PacketBuffer Buffer) { byte bMode = 0, bFlag = 0; MitakeIndexTick cTick = null; //移動至資料結構 Buffer.Position = 7; DateTime cTime = Time.GetTime(Buffer); //取得時間 bool bHave = index.GetMitakeTick(cTime, ref cTick); cTick.SetFlag(2); MitakeIndexTick cPrevTick = null; if (index.ComplementStatus != ComplementStatus.NotComplement) { cPrevTick = index.GetPreviousTick(cTime, 2); if (cPrevTick != null) { cTick.Clone(cPrevTick); } } //取得format bFlag = Buffer[0]; ++Buffer.Position; //取得成交總額 bMode = BitConvert.GetValue(bFlag, 6, 2); uint uVolume = Volumn.GetVolumn(bMode, Buffer); cTick.Volume = uVolume; if (uVolume > index.成交總額) { index.成交總額 = uVolume; } //取得成交張數 bMode = BitConvert.GetValue(bFlag, 4, 2); cTick.成交張數 = Volumn.GetVolumn(bMode, Buffer); //取得成交筆數 bMode = BitConvert.GetValue(bFlag, 2, 2); cTick.成交筆數 = Volumn.GetVolumn(bMode, Buffer); CalculateSingle(cTick, cPrevTick); ++index.UpdateCount; }
internal static void Decode(MitakeIndex index, Mitake.Sockets.Data.PacketBuffer Buffer) { int iSize = 0; uint uValue = 0; byte bMode = 0, bIType = 0, bFlag = 0; MitakeIndexTick cTick = null; iSize = Buffer.Length - 2; Buffer.Position = 7; //移動至資料結構(時間欄位) DateTime cTime = Time.GetTime(Buffer); //取得時間 bool bHave = index.GetMitakeTick(cTime, ref cTick); cTick.SetFlag(8); if (index.ComplementStatus != ComplementStatus.NotComplement) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 8); if (cPrevTick != null) { cTick.Clone(cPrevTick); } } do { //取得價量旗標 bFlag = Buffer[0]; ++Buffer.Position; //取得指數代號(有加權指數,不含金融 等......) bIType = Buffer[0]; ++Buffer.Position; //取得類股成交金額 bMode = BitConvert.GetValue(bFlag, 6, 2); uValue = Volumn.GetVolumn(bMode, Buffer); cTick.Classifys[bIType].Amount = uValue; //取得類股成交量 bMode = BitConvert.GetValue(bFlag, 4, 2); uValue = Volumn.GetVolumn(bMode, Buffer); cTick.Classifys[bIType].Totals = uValue; } while (Buffer.Position < iSize); //End While ++index.UpdateCount; }
//計算個股(開盤價 最高價 最低價) private static void CalculatePrice(MitakeIndex index, DateTime time, double price) { if (price > 0) { if (index.Open == 0) { if (Time.ConvertForTotalSeconds(time) == 32405) //9:00:05 才是真的開盤價格 { index.Open = price; } } index.High = ((index.High == 0) ? price : ((price > index.High) ? price : index.High)); index.Low = ((index.Low == 0) ? price : ((price < index.Low) ? price : index.Low)); } }
/// <summary> /// 回補即時報價今天的所有歷史Tick /// </summary> /// <param name="symbolId">商品代號</param> public override void Complement(string symbolId) { int iSerial = MitakeSymbolManager.ConvertToSerial(symbolId); if (iSerial > 0) { switch (iSerial) { case 9998: //OTC上櫃指數 case 9999: //TWI加權指數 MitakeIndex cIndex = MitakeStorage.Storage.GetIndex(iSerial); cIndex.ComplementStatus = ComplementStatus.Complementing; break; default: MitakeQuote cQuote = MitakeStorage.Storage.GetQuote(iSerial); cQuote.ComplementStatus = ComplementStatus.Complementing; break; } Complement cComplement = new Complement(); cComplement.Serial = iSerial; this.Send(cComplement); } }
//大盤指數計算與補價資訊(StockId = 10000) private static void Decoder_Index_10000(MitakeIndex index, byte Module, uint value, bool Negative) { float fValue = (float)(value * 0.01); if (Negative) { fValue *= -1; //如果是負數 } switch (Module) { case 1: index.加權指數漲跌幅 = fValue; break; case 3: index.含金融漲跌幅 = fValue; break; case 5: index.OTC指數漲跌幅 = fValue; break; } }
internal static void Decode(MitakeIndex index, Mitake.Sockets.Data.PacketBuffer Buffer) { float fIndex = 0; byte bMode = 0, bIType = 0, bFlag = 0; MitakeIndexTick cTick = null; int iSize = Buffer.Length - 2; Buffer.Position = 7; //移動至資料結構(時間欄位) DateTime cTime = Time.GetTime(Buffer); //取得時間 bool bHave = index.GetMitakeTick(cTime, ref cTick); cTick.SetFlag(1); if (index.ComplementStatus != ComplementStatus.NotComplement) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 1); if (cPrevTick != null) { cTick.Clone(cPrevTick); } } do { //取得價量旗標 bFlag = Buffer[0]; ++Buffer.Position; //取得指數大小(1~4 Byte 不固定) bMode = BitConvert.GetValue(bFlag, 6, 2); //取得指數代號(有加權指數,不含金融 等......) bIType = BitConvert.GetValue(bFlag, 0, 6); fIndex = (float)(Volumn.GetVolumn(bMode, Buffer) * 0.01); if (Time.ConvertForTotalSeconds(cTime) == 32400) //09:00 開盤會送出昨日收盤價 { index.ReferPrices[bIType] = fIndex; //昨天收盤指數 } else { if (fIndex > 0) { cTick.Classifys[bIType].IndexValue = fIndex; switch (bIType) { case 0: //加權指數 cTick.Ask = new DOMPrice(fIndex, cTick.Ask.Size); cTick.Bid = new DOMPrice(fIndex, cTick.Bid.Size); CalculatePrice(index, cTime, fIndex); if (cTime >= index.即時資訊.Time) { index.Close = fIndex; if (index.Serial == 9999) { index.加權指數價差 = fIndex - index.ReferPrices[0]; } else if (index.Serial == 9998) { index.OTC指數價差 = fIndex - index.ReferPrices[0]; } } break; case 9: //不含金融 if (index.Serial == 9999) { if (cTime >= index.即時資訊.Time) { index.含金融價差 = fIndex - index.ReferPrices[9]; } } break; default: break; } } } } while (Buffer.Position < iSize); //End While if (cTime > index.即時資訊.Time) { index.即時資訊 = cTick; } ++index.UpdateCount; }
internal static void Decode(MitakeIndex index, Mitake.Sockets.Data.PacketBuffer Buffer) { int iSize = 0; byte bMode = 0, bType = 0, bFlag = 0; MitakeIndexTick cTick = null; iSize = Buffer.Length - 2; Buffer.Position = 7; //移動至資料結構(時間欄位) DateTime cTime = Time.GetTime(Buffer); //取得時間 if (cTime.TimeOfDay == __c忽略報價時間) //這個時間點可以直接忽略 { return; } bool bHave = index.GetMitakeTick(cTime, ref cTick); cTick.SetFlag(4); if (index.ComplementStatus != ComplementStatus.NotComplement) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 4); if (cPrevTick != null) { cTick.Clone(cPrevTick); } } do { //取得Format旗標 bFlag = Buffer[0]; ++Buffer.Position; //取得委託張數大小(1~4 Byte 不固定) bMode = BitConvert.GetValue(bFlag, 6, 2); //取得委託代號(有委賣合計張數,委買合計張數 等......) bType = BitConvert.GetValue(bFlag, 0, 6); switch (bType) { case 0: //委買合計張數 cTick.Bid = new DOMPrice(cTick.Price, Volumn.GetVolumn(bMode, Buffer)); break; case 1: //委賣合計張數 cTick.Ask = new DOMPrice(cTick.Price, Volumn.GetVolumn(bMode, Buffer)); break; case 2: //委買合計筆數 cTick.委買合計筆數 = Volumn.GetVolumn(bMode, Buffer); break; case 3: //委賣合計筆數 cTick.委賣合計筆數 = Volumn.GetVolumn(bMode, Buffer); break; case 4: //委買總漲停張數 cTick.委買總漲停張數 = Volumn.GetVolumn(bMode, Buffer); break; case 5: //委賣總漲停張數 cTick.委賣總漲停張數 = Volumn.GetVolumn(bMode, Buffer); break; case 6: //委買總漲停筆數 cTick.委買總漲停筆數 = Volumn.GetVolumn(bMode, Buffer); break; case 7: //委賣總漲停筆數 cTick.委賣總漲停筆數 = Volumn.GetVolumn(bMode, Buffer); break; case 8: //委買總跌停張數 cTick.委買總跌停張數 = Volumn.GetVolumn(bMode, Buffer); break; case 9: //委賣總跌停張數 cTick.委賣總跌停張數 = Volumn.GetVolumn(bMode, Buffer); break; case 10: //委買總跌停筆數 cTick.委買總跌停筆數 = Volumn.GetVolumn(bMode, Buffer); break; case 11: //委賣總跌停筆數 cTick.委賣總跌停筆數 = Volumn.GetVolumn(bMode, Buffer); break; default: Buffer.Position += (bMode + 1); break; } //End Switch } while (Buffer.Position < iSize); //End While ++index.UpdateCount; }