예제 #1
0
        /// <summary>
        ///   取得陣列內的MitakeQuote類別資料
        /// </summary>
        /// <param name="serial">股票流水號</param>
        /// <returns>返回值: MitakeQuote類別</returns>
        internal MitakeQuote GetQuote(int serial)
        {
            MitakeQuote cMitakeQuote = null;
            int         iIndex       = 0;

            lock (__cKeys) {
                if (__cKeys.TryGetValue(serial, out iIndex))
                {
                    cMitakeQuote = __cQuotes[iIndex];

                    if (cMitakeQuote.SymbolId.Length == 0)
                    {
                        SetSymbolInformation(cMitakeQuote, MitakeSymbolManager.GetQuoteSymbolInformation(serial));
                    }
                }
                else
                {
                    MitakeSymbolInformation cSymbolInfo = MitakeSymbolManager.GetQuoteSymbolInformation(serial);

                    int iMarketType = ((cSymbolInfo == null) ? 0 : cSymbolInfo.市場別);
                    int iCapacity   = ((iMarketType == 2) ? 16384 : 1024);
                    cMitakeQuote        = new MitakeQuote(iCapacity);
                    cMitakeQuote.Serial = serial;

                    SetSymbolInformation(cMitakeQuote, cSymbolInfo);

                    iIndex = __cQuotes.Count;
                    __cKeys.Add(serial, iIndex);
                    __cQuotes.Add(cMitakeQuote);
                }
            }
            return(cMitakeQuote);
        }
예제 #2
0
		internal static void AddQuoteSymbolInformation(int serial, MitakeSymbolInformation symbolInformation) {
			string sLSymbolId = symbolInformation.SymbolId.ToLower();
			if (__cSymbolList.ContainsKey(sLSymbolId)) {
				__cSymbolList[sLSymbolId] = serial;
			} else {
				__cSymbolList.Add(sLSymbolId, serial);
			}

			if (__cMitakeQuoteInformations.ContainsKey(serial)) {
				__cMitakeQuoteInformations[serial] = symbolInformation;
			} else {
				__cMitakeQuoteInformations.Add(serial, symbolInformation);
			}
		}
예제 #3
0
		internal static void AddQuoteSymbolInformation(int serial, MitakeSymbolInformation symbolInformation) {
			string sLSymbolId = symbolInformation.SymbolId.ToLower();
			if (__cSymbolList.ContainsKey(sLSymbolId)) {
				__cSymbolList[sLSymbolId] = serial;
			} else {
				__cSymbolList.Add(sLSymbolId, serial);
			}

			if (__cMitakeQuoteInformations.ContainsKey(serial)) {
				__cMitakeQuoteInformations[serial] = symbolInformation;
			} else {
				__cMitakeQuoteInformations.Add(serial, symbolInformation);
			}
		}
예제 #4
0
		internal static void Deserialize(string[] settings) {
			__cMitakeIndexOptions = JsonConvert.DeserializeObject<HashSet<string>>(settings[1]);
			__cMitakeOptionDecimalPoints = JsonConvert.DeserializeObject<Dictionary<string, double>>(settings[2]);
			__cMitakeQuoteInformations = JsonConvert.DeserializeObject<Dictionary<int, MitakeSymbolInformation>>(settings[3]);

			foreach (int iSerial in __cMitakeQuoteInformations.Keys) {
				MitakeSymbolInformation cInformation = __cMitakeQuoteInformations[iSerial];

				string sLSymbolId = cInformation.SymbolId.ToLower();
				if (!__cSymbolList.ContainsKey(sLSymbolId)) {
					__cSymbolList.Add(sLSymbolId, iSerial);
				}
			}
		}
예제 #5
0
 private void SetSymbolInformation(MitakeQuote quote, MitakeSymbolInformation info)
 {
     if (info != null)
     {
         quote.FutureMark = info.FutureMark;
         quote.SymbolId   = info.SymbolId;
         quote.SymbolName = info.SymbolName;
         quote.市場別        = info.市場別;
         quote.警示         = info.警示;
         quote.市          = info.市;
         quote.市場分類       = info.市場分類;
         quote.產業別        = info.產業別;
         quote.證券別        = info.證券別;
     }
 }
예제 #6
0
		private static void AddProductToExchange(MitakeSymbolInformation symbolInformation) {
			string sCommodityId = "UNKNOWN";
			ESymbolCategory cCategory = ESymbolCategory.Stock;
			switch (symbolInformation.市場別) {
				case 0:  //集中市場
				case 1:  //上櫃市場
					string sType = ((symbolInformation.市場別 == 0) ? "TSE" : "OTC");
					sCommodityId = string.Format("{0}_STOCK", sType);

					switch (symbolInformation.市場分類) {
						case 3:  //基金
							cCategory = ESymbolCategory.Spread;
							sCommodityId = string.Format("{0}_{1}", sType, "SPREAD");
							break;
						case 4:  //認股權證
							cCategory = ESymbolCategory.Warrant;
							sCommodityId = string.Format("{0}_{1}", sType, "WARRANT");
							break;
						case 9:  //中央政府公債
							cCategory = ESymbolCategory.Bond;
							sCommodityId = string.Format("{0}_{1}", sType, "BOND");
							break;
						case 10:  //富時指數(TW50)
							cCategory = ESymbolCategory.Index;
							sCommodityId = "INDEX";
							break;
					}
					break;
				case 2:  //期貨市場
					sCommodityId = symbolInformation.SymbolId.Substring(0, 3);

					switch (symbolInformation.市場分類) {
						case 1: //一般
							cCategory = ESymbolCategory.Future;
							break;
						case 2:  //選擇權
							if (MitakeSymbolManager.IsIndexOption(sCommodityId)) {
								cCategory = ESymbolCategory.IndexOption;
							} else {
								cCategory = ESymbolCategory.StockOption;
							}
							break;
					}
					break;
			}

			string sExchangeName = MitakeSymbolManager.ExchangeName;
			AbstractExchange cExchange = ProductManager.Manager.GetExchange(sExchangeName);
			cExchange.AddProduct(new Product() {
				CommodityId = sCommodityId,
				Category = cCategory,
				SymbolId = symbolInformation.SymbolId,
				SymbolName = symbolInformation.SymbolName
			});
		}
예제 #7
0
                internal static void Decode(int serial, PacketBuffer buffer) {
                        byte bSize = 0, bMark = 0, bFlag = 0, bTemp = 0;
			MitakeSymbolInformation cSymbolInfo = new MitakeSymbolInformation();

                        bSize = buffer.Data[3];
                        buffer.Position = 7; //移動至資料結構

                        //判斷股票別(如果為0 表示無此資料)
                        bFlag = buffer[0];

                        //取得市場別(0=集中市場 1=上櫃 2=期貨 3=興櫃)
                        cSymbolInfo.市場別 = BitConvert.GetValue(bFlag, 6, 2);
  
                        //取得是否為警示股
                        bTemp = BitConvert.GetValue(bFlag, 5, 1);
                        cSymbolInfo.警示 = ((bTemp == 1) ? true : false);

                        //取得是否為下市股票(五個交易日後移除)
                        bTemp = BitConvert.GetValue(bFlag, 4, 1);
                        cSymbolInfo.下市 = ((bTemp == 1) ? true : false);

                        //取得市場分類(參閱解碼表代號)
                        cSymbolInfo.市場分類 = BitConvert.GetValue(bFlag, 0, 4);
                        ++buffer.Position;

                        //取得股票代號(舊格式股票代號)
			cSymbolInfo.SymbolId = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 5).Trim();
			buffer.Position += 5;

                        //取得股票名稱
                        cSymbolInfo.SymbolName = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 9).Replace("\0", string.Empty);
                        buffer.Position += 9;

                        //期貨擴充(1:一般, 2:現月, 3:次月  PS:股票無使用)
                        bMark = buffer[0];
                        cSymbolInfo.FutureMark = bMark;
                        ++buffer.Position;

			string sSymbolId = string.Empty;
			if (cSymbolInfo.市場別 == 2) { //判斷是否為期貨
				if (cSymbolInfo.市場分類 == 2) {
					//如果市場分類 == 2,則可能是選擇權(SID2 = 10Bytes)
					sSymbolId = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 10).Trim();
					buffer.Position += 10;
				} else {
					sSymbolId = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 10).Trim();
					buffer.Position += 13;
				}
			} else {
				//取得SID2
				sSymbolId = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 6).Trim();
				buffer.Position += 6;

				//取得個股產業類別
				cSymbolInfo.產業別 = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 2);
				buffer.Position += 2;

				//取得個股證券類別
				cSymbolInfo.證券別 = Encoding.UTF8.GetString(buffer.Data, buffer.Position, 2);
				buffer.Position += 2;
			}

			if (sSymbolId.Length > 0) {
				cSymbolInfo.SymbolId = sSymbolId;

				//轉換為標準台股商品代號格式
				string sProductId = MitakeSymbolManager.Convert(cSymbolInfo.SymbolId, (cSymbolInfo.市場別 == 2) ? cSymbolInfo.市場分類 : 0);
				if (sProductId != null) {
					cSymbolInfo.SymbolId = sProductId;

					if (!MitakeSymbolManager.IsExist(sProductId)) {
						AddProductToExchange(cSymbolInfo);  //將股票代號更新至交易所內
					}
					MitakeSymbolManager.AddQuoteSymbolInformation(serial, cSymbolInfo);  //將基本資訊加入代號管理員內
				}
			}
                }
예제 #8
0
		private void SetSymbolInformation(MitakeQuote quote, MitakeSymbolInformation info) {
			if (info != null) {
				quote.FutureMark = info.FutureMark;
				quote.SymbolId = info.SymbolId;
				quote.SymbolName = info.SymbolName;
				quote.市場別 = info.市場別;
				quote.警示 = info.警示;
				quote.下市 = info.下市;
				quote.市場分類 = info.市場分類;
				quote.產業別 = info.產業別;
				quote.證券別 = info.證券別;
			}
		}
예제 #9
0
		internal static MitakeSymbolInformation GetQuoteSymbolInformation(int serial) {
			MitakeSymbolInformation cSymbolInfo = null;
			__cMitakeQuoteInformations.TryGetValue(serial, out cSymbolInfo);
			return cSymbolInfo;
		}