示例#1
0
		/// <summary>
		///   新增報價資訊訂閱
		/// </summary>
		/// <param name="symbolId">商品代號</param>
		public override void AddSubscribe(string symbolId) {
			int iSerial = MitakeSymbolManager.ConvertToSerial(symbolId);
			if (iSerial > 0) {
				__cSubscribe.Add(iSerial);
				__cSymbolIds.Add(symbolId);
				
				this.SendSubscribe();
			}
		}
示例#2
0
		/// <summary>
                ///   建構子
                /// </summary>
		public QuoteService() {
                        this.IsDecode = true;  //預設開啟解碼功能

			__cSubscribe = new Subscribe();
			__cSubscribe.Add(0);  //清盤狀態(如果不訂閱不會清盤)
			__cSymbolIds = new HashSet<string>();

                        __cTimer = new Timer(10000);
                        __cTimer.AutoReset = false;
                        __cTimer.Elapsed += Timer_onElapsed;

			__cReLoginTimer = new Timer(30000);  //建立斷線重連的計時器
			__cReLoginTimer.AutoReset = false;
			__cReLoginTimer.Elapsed += ReLoginTimer_onElapsed;
                }
示例#3
0
                private void StockClient_onStock(object sender, StockEvent e) {
			switch (e.Header) {
				case 0x4d:  //Mcp命令封包回應解碼
					switch (e.Type) {
						case 0xf0:  //訂閱完成通知回應
						case 0xf1:  //回補完成通知回應
							int iSerial = e.Serial;
							if (iSerial > 0) {  //有股票流水號
								IQuote cQuote = null;
								switch(iSerial) {
									case 9998:  //OTC上櫃指數
									case 9999:  //TWI加權指數
										cQuote = MitakeStorage.Storage.GetIndex(iSerial);
										if (e.Type == 0xf1) {
											(cQuote as MitakeIndex).ComplementStatus = ComplementStatus.Complemented;
										}
										break;
									default:
										cQuote = MitakeStorage.Storage.GetQuote(iSerial);
										if (e.Type == 0xf1) {
											(cQuote as MitakeQuote).ComplementStatus = ComplementStatus.Complemented;
										}
										break;
								}
								
								if (cQuote != null) {
									if (e.Type == 0xf0) {
										OnSubscribeCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId));
									} else {
										OnComplementCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId));
									}
								}
							}
							break;
						case 0xf8:  //股票代號回補完畢通知回應
							this.IsLogin = true;  //設定登入完成的旗標
							if (this.IsUpdate) {  //是否要更新
								this.Save();  //更新報價服務器的設定值
							}
							
							string sName = this.ExchangeName;
							AbstractExchange cExchange = ProductManager.Manager.GetExchange(sName);
							if (cExchange.IsUpdate) {  //檢查是否需要更新交易所商品代號表
								cExchange.Save();  //如果要更新則儲存更新後的結果
							}
							
							//重新訂閱股票(因為有回補新的股票代號, 所以要全部重新訂閱)
							__cSubscribe = new Subscribe();  //重新建立新的訂閱陣列(登入的時候會重新傳入訂閱的股票代號, 避免期貨或選擇權換月後訂閱到舊的資訊而沒有報價)
							__cSubscribe.Add(0);  //先訂閱清盤資訊
							AddSubscribe(new List<string>(__cSymbolIds));
							
							if (logger.IsInfoEnabled) logger.Info("[QuoteService.Login] Login service success...");
							OnLoginCompleted();
							break;
					}
					break;
				case 0x53:  //股票資訊封包
					switch (e.Type) {
						case 0x00:  //收到清盤資訊
							__bReset = true;     //如果收到清盤指令, 設定旗標
							__bReseted = false;  //將已經清盤完畢的旗標清除

							ReLogin(); //重新登入伺服器
							break;
						case 0x31:  //即時成交資訊
						case 0xb1:  //即時成交資訊
						case 0x3e:  //即時成交資訊
						case 0xbe:  //即時成交資訊
						case 0x41:  //即時成交資訊
							if (sender == __cSocket) { //比較是否為即時Socket送來的資訊
								IQuote cQuote = MitakeStorage.Storage.GetQuote(e.Serial);
								if (cQuote != null) {
									OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cQuote));
								}
							}
							break;
						case 0x32:  //大盤指數資訊
						case 0x33:  //大盤成交金額資訊
						case 0x34:  //大盤委買委賣資訊
							if (sender == __cSocket) { //比較是否為即時Socket送來的資訊
								IQuote cIndex = MitakeStorage.Storage.GetIndex(e.Serial);
								if (cIndex != null) {
									OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cIndex));
								}
							}
							break;
						case 0x35:  //即時公告資訊(三竹傳來的新聞或是公告)
							MitakeNotice cNotice = Decode_S35.Decode(e.Serial, e.Source);
							if (cNotice != null) {
								OnNotice(new QuoteNoticeEvent(this.DataSource, cNotice));
							}
							break;
					}
					break;
			}
		}