private void StockDecoder_onStock(object sender, Mitake.Events.StockEvent e)
 {
     if (e.Header == 0x53)
     {
         if (e.Type == 0x38)
         {
             EncodeUtil.EncodeSymbol(e.Source);
             __cSymbolBuffer.Add(e.Source.Data, 0, e.Source.Length);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///   插入資訊
        /// </summary>
        /// <param name="series">SeriesSymbolData 類別</param>
        /// <param name="date">欲插入的日期(資料會被插入至該指定的日期前)</param>
        internal void Insert(SeriesSymbolData series, DateTime date)
        {
            try {
                string sFile = string.Format("{0}\\{1}\\{2}", __sPath, (series.DataRequest.Resolution.TotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? "mins" : "days", series.DataRequest.Symbol);
                using (FileStream cStream = new FileStream(sFile, (__bCreate) ? FileMode.Create : FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    bool bFind = false;
                    if (!__bCreate)
                    {
                        long lCount = cStream.Length / MAX_BLOCK_SIZE;
                        bFind = FileSearchUtil.BinaryNearSearch(cStream, lCount, MAX_BLOCK_SIZE, date);
                    }

                    if (bFind)
                    {
                        long lCurrentP = cStream.Position;

                        //先保留後面的資料以便插入時不會被覆蓋
                        long    lRevSize = cStream.Length - lCurrentP;
                        ZBuffer cTemp    = new ZBuffer((int)lRevSize);
                        cStream.Read(cTemp.Data, 0, (int)lRevSize);
                        cTemp.Length = (int)lRevSize;

                        cStream.SetLength(lCurrentP + 1);
                        cStream.Position = lCurrentP;                         //移動置固定位置

                        ZBuffer cBuffer = new ZBuffer(64);

                        int iHistoryIndex = series.Indexer.HistoryIndex;
                        int iCount        = series.Count;
                        for (int i = 0; i < iCount; i++)
                        {
                            int iIndex = iHistoryIndex + i;
                            cBuffer.Length = 0;
                            cBuffer.Add(series.Time[iIndex]);
                            cBuffer.Add(series.Open[iIndex]);
                            cBuffer.Add(series.High[iIndex]);
                            cBuffer.Add(series.Low[iIndex]);
                            cBuffer.Add(series.Close[iIndex]);
                            cBuffer.Add(series.Volume[iIndex]);

                            cStream.Write(cBuffer.Data, 0, cBuffer.Length);
                        }
                        cStream.Write(cTemp.Data, 0, cTemp.Length);                          //再將後面的資料合併
                    }
                }
                if (logger.IsInfoEnabled)
                {
                    logger.InfoFormat("[FileWrite] {0} insert completed...  count={1}", sFile, series.Count);
                }
            } catch (Exception __errExcep) {
                if (logger.IsErrorEnabled)
                {
                    logger.ErrorFormat("[FileWrite] '{0}' insert error...", series.DataRequest.Symbol, series.Count);
                }
                if (logger.IsErrorEnabled)
                {
                    logger.ErrorFormat("{0}/r/n{1}", __errExcep.Message, __errExcep.StackTrace);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///    讀取Response資料
        /// </summary>
        /// <returns>返回值:ZBuffer類別(null=讀取失敗)</returns>
        internal ZBuffer Read()
        {
            if (__cResponse == null)
            {
                return(null);
            }

            try {
                int    iLength = 0;
                Stream cStream = __cResponse.GetResponseStream();
                if (__cResponse.ContentEncoding.Equals("gzip"))
                {
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("ZReader.Read: 封包資料有使用gzip壓縮編碼,建立GZip解碼物件...");
                    }
                    cStream = new GZipStream(cStream, CompressionMode.Decompress);
                }

                //建立緩衝區
                byte[]  cTemps  = new byte[8192];
                ZBuffer cBuffer = new ZBuffer(__iDataSize + 2);

                do
                {
                    iLength = cStream.Read(cTemps, 0, 8192);
                    if (iLength > 0)
                    {
                        cBuffer.Add(cTemps, 0, iLength);
                    }
                } while (iLength != 0);

                cStream.Close();                  //關閉資料流
                cStream.Dispose();                //釋放資源

                __cResponse = null;               //釋放資源

                if (logger.IsDebugEnabled)
                {
                    logger.DebugFormat("ZReader.Read: dataLength={0}", cBuffer.Length);
                }
                return(cBuffer);
            } catch (System.Exception __errExcep) {
                logger.ErrorFormat("{0}\r\n{1}", __errExcep.StackTrace, __errExcep.Message);
                return(null);
            }
        }
Ejemplo n.º 4
0
        internal void Write(SeriesSymbolData series)
        {
            try {
                string sFile = string.Format("{0}\\{1}\\{2}", __sPath, (series.DataRequest.Resolution.TotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? "mins" : "days", series.DataRequest.Symbol);
                using (FileStream cStream = new FileStream(sFile, (__bCreate) ? FileMode.Create : FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    if (!__bCreate)
                    {
                        long lCount = cStream.Length / MAX_BLOCK_SIZE;
                        if (lCount > 0)
                        {
                            FileSearchUtil.BinarySearch(cStream, lCount, MAX_BLOCK_SIZE, series.Time[0]);
                        }
                    }

                    ZBuffer cBuffer = new ZBuffer(64);

                    int iHistoryIndex = series.Indexer.HistoryIndex;
                    int iCount        = series.Count;
                    for (int i = 0; i < iCount; i++)
                    {
                        int iIndex = iHistoryIndex + i;
                        cBuffer.Length = 0;
                        cBuffer.Add(series.Time[iIndex]);
                        cBuffer.Add(series.Open[iIndex]);
                        cBuffer.Add(series.High[iIndex]);
                        cBuffer.Add(series.Low[iIndex]);
                        cBuffer.Add(series.Close[iIndex]);
                        cBuffer.Add(series.Volume[iIndex]);

                        cStream.Write(cBuffer.Data, 0, cBuffer.Length);
                    }
                }
                if (logger.IsInfoEnabled)
                {
                    logger.InfoFormat("[FileWrite] {0} write completed...  count={1}", sFile, series.Count);
                }
            } catch (Exception __errExcep) {
                if (logger.IsErrorEnabled)
                {
                    logger.ErrorFormat("[FileWrite] '{0}' write error...", series.DataRequest.Symbol, series.Count);
                }
                if (logger.IsErrorEnabled)
                {
                    logger.ErrorFormat("{0}/r/n{1}", __errExcep.Message, __errExcep.StackTrace);
                }
            }
        }
Ejemplo n.º 5
0
                /// <summary>
                ///    讀取Response資料
                /// </summary>
                /// <returns>返回值:ZBuffer類別(null=讀取失敗)</returns>
		internal ZBuffer Read() {
			if (__cResponse == null) {
				return null;
			}

                        try {
                                int iLength = 0;
                                Stream cStream = __cResponse.GetResponseStream();
                                if (__cResponse.ContentEncoding.Equals("gzip")) {
					if (logger.IsDebugEnabled) logger.Debug("ZReader.Read: 封包資料有使用gzip壓縮編碼,建立GZip解碼物件...");
                                        cStream = new GZipStream(cStream, CompressionMode.Decompress);
                                }

                                //建立緩衝區
				byte[] cTemps = new byte[8192];
				ZBuffer cBuffer = new ZBuffer(__iDataSize + 2);
                                
                                do {
                                        iLength = cStream.Read(cTemps, 0, 8192);
					if (iLength > 0) {
						cBuffer.Add(cTemps, 0, iLength);
					}
                                } while (iLength != 0);

				cStream.Close();  //關閉資料流
				cStream.Dispose(); //釋放資源

				__cResponse = null;  //釋放資源

				if (logger.IsDebugEnabled) logger.DebugFormat("ZReader.Read: dataLength={0}", cBuffer.Length);
                                return cBuffer;
                        } catch (System.Exception __errExcep) {
                                logger.ErrorFormat("{0}\r\n{1}", __errExcep.StackTrace, __errExcep.Message);
                                return null;
                        }
                }