コード例 #1
0
ファイル: MarketSeries.cs プロジェクト: Mendelone/Trading
        public static MarketSeries ImportFromFile(string symbolCode, TimeFrame timeFrame, string path, DateTime?startDate = null, DateTime?endDate = null)
        {
            var series = new MarketSeries(null, symbolCode, timeFrame);

            series.ImportFromFile(path, startDate, endDate);
            GC.Collect();

            if (series != null && series.OpenTime.Count > 0)
            {
                Console.WriteLine($"Imported {timeFrame} {symbolCode} ({series.OpenTime.Count} data points from {series.OpenTime[0]} to {series.OpenTime.LastValue})");
            }
            else
            {
                Console.WriteLine($"Could not import {timeFrame} {symbolCode}");
            }
            return(series);
        }
コード例 #2
0
        public MarketSeries GetMarketSeries(string symbolCode, TimeFrame timeFrame, DateTime?startDate = null, DateTime?endDate = null)
        {
            string file = null;

            if (!Directory.Exists(RootDir))
            {
                throw new ArgumentException($"Historical data source directory missing: {RootDir}");
            }

            file = Path.Combine(RootDir, symbolCode + "_" + timeFrame.Name.ToUpper() + "_UTC+0_00.csv");

            if (!File.Exists(file))
            {
                file = null;

                var dir = SymbolTimeFrameDir(symbolCode, timeFrame);
                if (!Directory.Exists(dir))
                {
                    return(null);
                }

                long   longestLength = -1;
                string longestPath   = null;
                foreach (var path in Directory.GetFiles(dir, "*.csv"))
                {
                    var length = new FileInfo(path).Length;
                    if (length > longestLength)
                    {
                        longestLength = length;
                        longestPath   = path;
                    }
                }

                if (longestPath == null)
                {
                    return(null);
                }

                file = longestPath;
            }

            return(MarketSeries.ImportFromFile(symbolCode, timeFrame, file, startDate, endDate));
        }