Esempio n. 1
0
        public SequenceKeyedCaching LoadSequenceKeyedCache(string identityCode, BarItemType barType, Guid cacheId, CacheTypeOption cacheType)
        {
            CacheHeaderInfo header = cacheReader.RequestHeader(identityCode, barType, cacheId, cacheType);

            cacheReader.RegisterHeader(header);
            return(new SequenceKeyedCaching(header, cacheWriter, cacheReader));
        }
Esempio n. 2
0
        protected SignalFrameReader(DateTime startDate, DateTime endDate, int frameSize, SignalCache cache, BarItemType barType, Guid cacheId)
        {
            this.startDate = startDate;
            this.endDate   = endDate;
            this.frameSize = frameSize;
            dataFrameItems = cache.SelectSignals(startDate, endDate, frameSize);

            int      index = 0;
            DateTime lastClosingBarDate = DateTime.MinValue;

            foreach (SignalDataItem item in dataFrameItems)
            {
                if (lastClosingBarDate != item.ClosingBarTime)
                {
                    signalIndex.Add(item.ClosingBarTime, index);
                    lastClosingBarDate = item.ClosingBarTime;
                }

                index++;
            }

            CacheHeaderInfo headerInfo = cache.Header;

            foreach (KeyValuePair <string, string> extendedProperty in headerInfo.ExtendedProperties)
            {
                switch (extendedProperty.Key)
                {
                case "Indicators":
                    indicatorCacheList = CacheHelper.LoadIndicatorCacheList(extendedProperty.Value, barType, cacheId);
                    break;
                }
            }
        }
Esempio n. 3
0
        public void Initialize()
        {
            header = GetHeader();

            cacheWriter = SharedCacheFactory.Instance.CacheWriter;
            cacheWriter.RegisterHeader(header);

            cacheReader = SharedCacheFactory.Instance.CacheReader;
            cacheReader.RegisterHeader(header);
        }
Esempio n. 4
0
        public CacheHeaderInfo RequestHeader(string identityCode, BarItemType barType, Guid cacheId, CacheTypeOption cacheType)
        {
            string       fileName = FileHelper.CreateCacheFileName(cacheFolder, identityCode, barType.Code, cacheId, cacheType);
            BinaryReader reader   = new BinaryReader(File.Open(fileName, FileMode.Open));

            int             dataPosition = 0;
            CacheHeaderInfo headerInfo   = FileHelper.ReadBinaryFileHeader(reader, ref dataPosition);

            reader.Close();
            return(headerInfo);
        }
Esempio n. 5
0
        private void InitializeSignalDataFrame()
        {
            CacheHeaderInfo[] indicatorCacheHeaders = new CacheHeaderInfo[indicatorCacheList.Count];
            int index = 0;

            foreach (IndicatorCache indicatorCache in indicatorCacheList.Values)
            {
                indicatorCacheHeaders[index] = indicatorCache.Header;
                index++;
            }

            this.signalDataFrame = new SignalDataFrame(signalCache.Header, indicatorCacheHeaders);
            timeKeyedSignals     = this.signalCache.SelectAllSignals();
        }
Esempio n. 6
0
        public static byte[] EncodeCacheHeader(CacheHeaderInfo headerInfo)
        {
            List <byte[]> headerByteList = new List <byte[]>();

            headerByteList.Add(EncodeString(headerInfo.IdentityCode));
            headerByteList.Add(headerInfo.CacheId.ToByteArray());
            headerByteList.Add(BitConverter.GetBytes((int)headerInfo.CacheType));
            headerByteList.Add(EncodeString(headerInfo.SubSection));
            headerByteList.Add(BitConverter.GetBytes(headerInfo.Columns.Count));
            foreach (CacheColumn column in headerInfo.Columns.Values)
            {
                List <byte[]> columnByteList = new List <byte[]>();

                columnByteList.Add(EncodeString(column.Name));
                columnByteList.Add(BitConverter.GetBytes(column.Size));
                columnByteList.Add(BitConverter.GetBytes(column.Index));
                columnByteList.Add(BitConverter.GetBytes((int)column.DataType));

                if (column.ExtendedProperties != null && column.ExtendedProperties.Count > 0)
                {
                    columnByteList.Add(EncodeExtendedProperties(column.ExtendedProperties));
                }
                else
                {
                    columnByteList.Add(BitConverter.GetBytes((int)0));
                }

                headerByteList.Add(MergeByteList(columnByteList));
            }


            if (headerInfo.ExtendedProperties != null && headerInfo.ExtendedProperties.Count > 0)
            {
                headerByteList.Add(EncodeExtendedProperties(headerInfo.ExtendedProperties));
            }
            else
            {
                headerByteList.Add(BitConverter.GetBytes((int)0));
            }

            byte[] headerInfoByteList = MergeByteList(headerByteList);
            byte[] headerSize         = BitConverter.GetBytes(headerInfoByteList.Length);
            byte[] complete           = new byte[headerInfoByteList.Length + headerSize.Length];
            headerSize.CopyTo(complete, 0);
            headerInfoByteList.CopyTo(complete, headerSize.Length);

            return(complete);
        }
Esempio n. 7
0
        public StrategyCacheProfile(string strategyIdentity, BarItemType barType, Guid cacheId)
        {
            this.strategyCache = new StrategyCache(strategyIdentity, barType, cacheId);

            CacheHeaderInfo headerInfo = this.strategyCache.Header;

            foreach (KeyValuePair <string, string> extendedProperty in headerInfo.ExtendedProperties)
            {
                switch (extendedProperty.Key)
                {
                case "Indicators":
                    indicators = CacheHelper.LoadIndicatorCacheList(extendedProperty.Value, barType, cacheId);
                    break;

                case "Alerts":
                    break;

                case "Signals":
                    foreach (KeyValuePair <string, string> keyValuePair in strategyCache.Header.ExtendedProperties)
                    {
                        switch (keyValuePair.Key)
                        {
                        case "Indicators":
                            indicators = CacheHelper.LoadIndicatorCacheList(keyValuePair.Value, barType, cacheId);
                            break;

                        case "Alerts":
                            break;

                        case "Signals":
                            string[] signalValues = keyValuePair.Value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                            signalCacheProfiles = new Dictionary <string, SignalCacheProfile>();
                            foreach (string signalIdentity in signalValues)
                            {
                                signalCacheProfiles.Add(signalIdentity, new SignalCacheProfile(signalIdentity, barType, cacheId));
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 8
0
        public SignalCacheProfile(string signalIdentity, BarItemType barType, Guid cacheId)
        {
            this.signalCache = new SignalCache(signalIdentity, barType, cacheId);

            CacheHeaderInfo headerInfo = this.signalCache.Header;

            foreach (KeyValuePair <string, string> extendedProperty in headerInfo.ExtendedProperties)
            {
                switch (extendedProperty.Key)
                {
                case "Indicators":
                    indicators = CacheHelper.LoadIndicatorCacheList(extendedProperty.Value, barType, cacheId);
                    break;

                case "Alerts":
                    break;
                }
            }
        }
Esempio n. 9
0
        public void RegisterHeader(CacheHeaderInfo header)
        {
            string fileName = FileHelper.CreateCacheFileName(cacheFolder, header.IdentityCode, header.SubSection, header.CacheId, header.CacheType);

            BinaryField[] fields = new BinaryField[header.Columns.Count];
            int           index  = 0;

            foreach (CacheColumn column in header.Columns.Values)
            {
                BinaryColumnTypeOption binaryColumnType = BinaryColumnTypeOption.String;
                switch (column.DataType)
                {
                case CacheDataTypeOption.Double:
                    binaryColumnType = BinaryColumnTypeOption.Double;
                    break;

                case CacheDataTypeOption.Long:
                    binaryColumnType = BinaryColumnTypeOption.Long;
                    break;

                case CacheDataTypeOption.String:
                    binaryColumnType = BinaryColumnTypeOption.String;
                    break;

                case CacheDataTypeOption.Integer:
                    binaryColumnType = BinaryColumnTypeOption.Integer;
                    break;

                case CacheDataTypeOption.Guid:
                    binaryColumnType = BinaryColumnTypeOption.Guid;
                    break;
                }

                fields[index] = new BinaryField(column.Name, binaryColumnType, column.Size);

                index++;
            }

            if (!binaryFiles.ContainsKey(header.IdentityCode))
            {
                binaryFiles.Add(header.IdentityCode, new FileCacheItem(fileName, header, fields));
            }
        }
Esempio n. 10
0
        public SignalDataFrame(CacheHeaderInfo signalHeaderInfo, CacheHeaderInfo[] indicatorHeaderInfo)
        {
            this.signalHeaderInfo    = signalHeaderInfo;
            this.indicatorHeaderInfo = indicatorHeaderInfo;

            indicatorChartingInfo = new Dictionary <int, IndicatorChartingInfo>();
            int index = 0;

            foreach (CacheHeaderInfo headerInfo in indicatorHeaderInfo)
            {
                foreach (CacheColumn columnInfo in headerInfo.Columns.Values)
                {
                    if (columnInfo.ExtendedProperties != null)
                    {
                        indicatorChartingInfo.Add(index, new IndicatorChartingInfo(index, headerInfo.IdentityCode, columnInfo.Name
                                                                                   , (ChartRangeOption)Enum.Parse(typeof(ChartRangeOption), columnInfo.ExtendedProperties["ChartRange"])
                                                                                   , (ChartTypeOption)Enum.Parse(typeof(ChartTypeOption), columnInfo.ExtendedProperties["ChartType"]), headerInfo.Columns.Count > 2));
                        index++;
                    }
                }
            }
        }
Esempio n. 11
0
        public SignalCacheNavigator(string cacheFolder, BarItemType barType, Guid cacheId, string signalIdentityCode)
        {
            this.signalCache   = new SignalCache(signalIdentityCode, barType, cacheId);
            this.pricebarCache = new PricebarCache(barType, cacheId, CacheModeOption.Read);

            this.barType = barType;
            this.cacheId = cacheId;

            CacheHeaderInfo headerInfo = this.signalCache.Header;

            foreach (KeyValuePair <string, string> extendedProperty in headerInfo.ExtendedProperties)
            {
                switch (extendedProperty.Key)
                {
                case "Indicators":
                    indicatorCacheList = CacheHelper.LoadIndicatorCacheList(extendedProperty.Value, barType, cacheId);
                    break;
                }
            }

            InitializeSignalDataFrame();
        }
Esempio n. 12
0
        public static CacheHeaderInfo ReadBinaryFileHeader(BinaryReader reader, ref int dataPosition)
        {
            CacheHeaderInfo headerInfo = null;

            byte[] headerBytes = new byte[4];
            int    result      = reader.Read(headerBytes, 0, 4);

            if (result > 0)
            {
                int headerOffset = 0;
                int headerSize   = FileHelper.ReadInt32(headerBytes, ref headerOffset);
                if (headerSize > 0)
                {
                    dataPosition = headerSize + headerOffset;
                    byte[] header = new byte[headerSize];
                    reader.Read(header, 0, headerSize);
                    headerInfo = FileHelper.DecodeCacheHeader(header);
                }
            }

            return(headerInfo);
        }
Esempio n. 13
0
        internal BinaryNavigator(string binaryFileName, BinaryField[] fields)
        {
            this.binaryFileName = binaryFileName;

            this.fields = new Dictionary<string, BinaryField>();
            this.columnOrders = new Dictionary<int, string>();
            this.columnIndex = new Dictionary<string, int>();
            int order = 0;
            foreach (BinaryField field in fields)
            {
                this.fields.Add(field.Name, field);
                columnOrders.Add(order, field.Name);
                columnIndex.Add(field.Name, order);
                rowSize += field.Size;
                order++;
            }

            FileHelper.CheckMissingFolders(binaryFileName);
             
            reader = new BinaryReader(File.Open(binaryFileName, FileMode.OpenOrCreate));

            this.headerInfo = FileHelper.ReadBinaryFileHeader(reader, ref this.dataPosition);
        }
Esempio n. 14
0
        internal StrategyFrameReader(DateTime startDate, DateTime endDate, int frameSize, BarItem[] priceBars, StrategyCache cache, BarItemType barType, Guid cacheId)
        {
            this.startDate = startDate;
            this.endDate   = endDate;
            this.frameSize = frameSize;
            this.priceBars = priceBars;
            dataFrameItems = cache.SelectStrategies(startDate, endDate, frameSize);

            if (dataFrameItems != null)
            {
                strategyIndex = new Dictionary <DateTime, int>();
                int      index = 0;
                DateTime lastClosingBarDate = DateTime.MinValue;
                foreach (StrategyDataItem item in dataFrameItems)
                {
                    if (lastClosingBarDate != item.ClosingBarTime)
                    {
                        strategyIndex.Add(item.ClosingBarTime, index);
                        lastClosingBarDate = item.ClosingBarTime;
                    }

                    index++;
                }
            }

            CacheHeaderInfo headerInfo = cache.Header;

            foreach (KeyValuePair <string, string> extendedProperty in headerInfo.ExtendedProperties)
            {
                switch (extendedProperty.Key)
                {
                case "Indicators":
                    indicatorCacheList = CacheHelper.LoadIndicatorCacheList(extendedProperty.Value, barType, cacheId);
                    break;
                }
            }
        }
Esempio n. 15
0
 public SequenceKeyedCaching(CacheHeaderInfo header, ICacheWriter cacheWriter, ICacheReader cacheReader)
 {
     this.header      = header;
     this.cacheWriter = cacheWriter;
     this.cacheReader = cacheReader;
 }
Esempio n. 16
0
 public SequenceKeyedCaching CreateSequenceKeyedCache(CacheHeaderInfo header)
 {
     cacheWriter.RegisterHeader(header);
     return(new SequenceKeyedCaching(header, cacheWriter, cacheReader));
 }
Esempio n. 17
0
 public TimeKeyedCaching CreateTimeKeyedCache(CacheHeaderInfo header)
 {
     cacheWriter.RegisterHeader(header);
     return(new TimeKeyedCaching(header, cacheWriter, cacheReader));
 }
Esempio n. 18
0
 public FileCacheItem(string fileName, CacheHeaderInfo header, BinaryField[] fields)
 {
     this.fileName = fileName;
     this.header   = header;
     this.fields   = fields;
 }
Esempio n. 19
0
        public static Dictionary <int, IndicatorChartingInfo> LoadIndicatorChartingInfo(CacheHeaderInfo headerInfo)
        {
            Dictionary <int, IndicatorChartingInfo> indicatorChartingInfo = new Dictionary <int, IndicatorChartingInfo>();
            int index = 0;

            foreach (CacheColumn columnInfo in headerInfo.Columns.Values)
            {
                if (columnInfo.ExtendedProperties != null)
                {
                    indicatorChartingInfo.Add(index, new IndicatorChartingInfo(index, headerInfo.IdentityCode, columnInfo.Name
                                                                               , (ChartRangeOption)Enum.Parse(typeof(ChartRangeOption), columnInfo.ExtendedProperties["ChartRange"])
                                                                               , (ChartTypeOption)Enum.Parse(typeof(ChartTypeOption), columnInfo.ExtendedProperties["ChartType"]), headerInfo.Columns.Count > 2));
                    index++;
                }
            }

            return(indicatorChartingInfo.Count > 0 ? indicatorChartingInfo : null);
        }