Beispiel #1
0
        public StockReportStream GetReport()
        {
            StockReportStream report = new StockReportStream();

            using (ExcelPackage xlPackage = new ExcelPackage(new FileInfo(_documentPath)))
            {
                var myWorksheet  = xlPackage.Workbook.Worksheets.First();
                var totalRows    = myWorksheet.Dimension.End.Row;
                var totalColumns = myWorksheet.Dimension.End.Column;

                for (int rowNum = 2; rowNum <= totalRows; rowNum++)
                {
                    var row = myWorksheet.Cells[rowNum, 1, rowNum, totalColumns]
                              .Select(c => c.Value == null ? string.Empty : c.Value.ToString()).ToArray();

                    string rawDateTime = row[2] + " " + row[3];

                    DateTime dateTime = DateTime.ParseExact(rawDateTime, "yyyyMMdd HHmmss", null);

                    Candle candle = new Candle()
                    {
                        High      = int.Parse(row[5]),
                        Low       = int.Parse(row[6]),
                        Open      = int.Parse(row[4]),
                        Close     = int.Parse(row[7]),
                        Time      = dateTime,
                        TimeStamp = ((DateTimeOffset)dateTime).ToUnixTimeMilliseconds(),
                    };
                    report.PushCandle(candle);
                }
            }

            return(report);
        }
Beispiel #2
0
        public StockReportStream GetReport()
        {
            StockReportStream report = new StockReportStream();

            dynamic jsonObject = JsonConvert.DeserializeObject(File.ReadAllText(_documentPath));

            var high = (JArray)jsonObject.h;
            var low  = (JArray)jsonObject.l;

            var open       = (JArray)jsonObject.o;
            var close      = (JArray)jsonObject.c;
            var timestamps = (JArray)jsonObject.t;

            for (int i = 0; i < timestamps.Count; i++)
            {
                Candle candle = new Candle()
                {
                    High      = (decimal)high[i],
                    Low       = (decimal)low[i],
                    Open      = (decimal)open[i],
                    Close     = (decimal)close[i],
                    Time      = DateTimeOffset.FromUnixTimeSeconds((long)timestamps[i]).UtcDateTime,
                    TimeStamp = (long)timestamps[i],
                };

                report.PushCandle(candle);
            }
            return(report);
        }