//計算個股(開盤價 最高價 最低價) internal static void CalculatePrice(MitakeIndex index, DateTime time, double price) { if (price > 0) { if (index.Open == 0) { 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)); index.Close = price; } }
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; }
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 (!bHave) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 8); if (cPrevTick != null) { cTick.Clone(cPrevTick, 8); } } 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; }
/// <summary> /// 取得陣列內的MitakeIndex類別資料 /// </summary> /// <param name="serial">股票流水號</param> /// <returns>返回值: MitakeIndex類別</returns> internal MitakeIndex GetIndex(int serial) { MitakeIndex cMitakeIndex = null; if (!__cIndexs.TryGetValue(serial, out cMitakeIndex)) { Product cProduct = MitakeSymbolManager.GetIndexSymbolInformation(serial); cMitakeIndex = new MitakeIndex(); cMitakeIndex.Serial = serial; if (cProduct != null) { cMitakeIndex.SymbolId = cProduct.SymbolId; cMitakeIndex.SymbolName = cProduct.SymbolName; } lock (__cIndexs) { __cIndexs.Add(serial, cMitakeIndex); } } return cMitakeIndex; }
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 = index.GetPreviousTick(cTime, 2); if (!bHave) { if (cPrevTick != null) { cTick.Clone(cPrevTick, 2); } } //取得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; }
/// <summary> /// 取得陣列內的MitakeIndex類別資料 /// </summary> /// <param name="serial">股票流水號</param> /// <returns>返回值: MitakeIndex類別</returns> internal MitakeIndex GetIndex(int serial) { MitakeIndex cMitakeIndex = null; if (!__cIndexs.TryGetValue(serial, out cMitakeIndex)) { Product cProduct = MitakeSymbolManager.GetIndexSymbolInformation(serial); cMitakeIndex = new MitakeIndex(); cMitakeIndex.Serial = serial; if (cProduct != null) { cMitakeIndex.SymbolId = cProduct.SymbolId; cMitakeIndex.SymbolName = cProduct.SymbolName; } lock (__cIndexs) { __cIndexs.Add(serial, cMitakeIndex); } } return(cMitakeIndex); }
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); //取得時間 bool bHave = index.GetMitakeTick(cTime, ref cTick); cTick.SetFlag(4); if (!bHave) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 4); if (cPrevTick != null) { cTick.Clone(cPrevTick, 4); } } 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; }
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 (!bHave) { MitakeIndexTick cPrevTick = index.GetPreviousTick(cTime, 1); if (cPrevTick != null) { cTick.Clone(cPrevTick, 1); } } 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; //昨天收盤指數 } cTick.Classifys[bIType].IndexValue = fIndex; if (index.Serial == 9999) { switch (bIType) { case 0: //加權指數 if (fIndex > 0) { cTick.Ask = new DOMPrice(fIndex, cTick.Ask.Size); cTick.Bid = new DOMPrice(fIndex, cTick.Bid.Size); if (cTime >= index.即時資訊.Time) { index.加權指數價差 = fIndex - index.ReferPrices[0]; CalculatePrice(index, cTime, fIndex); } } break; case 9: //不含金融 if (fIndex > 0) { 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; }
//大盤指數計算與補價資訊(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 0: break; case 1: index.加權指數漲跌幅 = fValue; break; case 2: break; case 3: index.不含金融漲跌幅 = fValue; break; case 4: index.OTC指數價差 = fValue; break; case 5: index.OTC指數漲跌幅 = fValue; break; } }
//大盤指數計算與補價資訊(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; } }
/* * 指數計算及補價資訊:(<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; }