예제 #1
0
 public void AddCandles(ChartEntryEntity entry, DateTime from, DateTime to, Candle[] candles)
 {
     FetchHistories.RemoveRange(FetchHistories
                                .Where(
                                    history => history.ChartEntry.Id == entry.Id &&
                                    history.From >= from &&
                                    history.To <= to));
     FetchHistories.Add(new CandleFetchHistory()
     {
         ChartEntry = entry,
         From       = from,
         To         = to,
         FetchCount = candles.Length
     });
     Candles.RemoveRange(Candles
                         .Where(
                             candle => candle.ChartEntry.Id == entry.Id &&
                             candle.Time >= from &&
                             candle.Time <= to));
     Candles.AddRangeAsync(
         candles.Select(candle => new CandleEntity()
     {
         ChartEntry = entry,
         Time       = candle.Time,
         Open       = candle.Open,
         High       = candle.High,
         Low        = candle.Low,
         Close      = candle.Close,
         Volume     = candle.Volume
     }));
     SaveChangesAsync();
 }
예제 #2
0
        public void キャンドルを追加できること()
        {
            var entry = new ChartEntryEntity()
            {
                Symbol = "USD_JPY",
                Range  = ChartRange.Hourly
            };

            entry.Candles.Add(new CandleEntity()
            {
                Time   = DateTime.Now,
                Open   = 2,
                High   = 4,
                Low    = 1,
                Close  = 3,
                Volume = 5,
            });

            using (var context = new CandleChartStore())
            {
                context.ChartEntries.Add(entry);
                context.SaveChanges();
            }

            using (var context = new CandleChartStore())
            {
                var chart = context.ChartEntries.Find(entry.Id);
                context.Entry(chart).Collection(ce => ce.Candles).Load();
                Assert.IsNotNull(chart.Candles.FirstOrDefault());
            }
        }
예제 #3
0
 public Candle[] GetCandles(ChartEntryEntity entry, DateTime from, DateTime to)
 {
     return(Candles
            .Where(c => c.ChartEntry.Id == entry.Id && c.Time >= from && c.Time <= to)
            .OrderBy(c => c.Time)
            .Select(c => new Candle(c.Time, c.Open, c.High, c.Low, c.Close, c.Volume))
            .ToArray());
 }
예제 #4
0
 public Candle[] GetCandles(ChartEntryEntity entry, DateTime to, int takeCount)
 {
     return(Candles
            .Where(c => c.ChartEntry.Id == entry.Id && c.Time <= to)
            .OrderByDescending(c => c.Time)
            .Take(takeCount)
            .OrderBy(c => c.Time)
            .Select(c => new Candle(c.Time, c.Open, c.High, c.Low, c.Close, c.Volume))
            .ToArray());
 }
예제 #5
0
        public ChartEntryEntity FindOrCreateEntry(TradingSymbol symbol, ChartRange range)
        {
            var entry = ChartEntries.Where(ce => ce.Symbol == symbol.Symbol && ce.Range == range).FirstOrDefault();

            if (entry == null)
            {
                entry = new ChartEntryEntity()
                {
                    Symbol = symbol.Symbol,
                    Range  = range,
                };
                ChartEntries.AddAsync(entry);
                SaveChangesAsync();
            }
            return(entry);
        }
예제 #6
0
        public void チャートエントリを追加できること()
        {
            var entry = new ChartEntryEntity()
            {
                Symbol = "USD_JPY",
                Range  = ChartRange.Hourly
            };

            using (var context = new CandleChartStore())
            {
                context.ChartEntries.Add(entry);
                context.SaveChanges();
            }

            using (var context = new CandleChartStore())
            {
                Assert.IsNotNull(context.ChartEntries.Find(entry.Id));
            }
        }
예제 #7
0
 public bool IsCacheAvailable(ChartEntryEntity entry, DateTime to, int takeCount)
 {
     return(FetchHistories.Where(fh => fh.ChartEntry.Id == entry.Id && fh.From <= to && fh.To >= to).Sum(fh => fh.FetchCount) >= takeCount);
 }
예제 #8
0
 public bool IsCacheAvailable(ChartEntryEntity entry, DateTime from, DateTime to)
 {
     return(FetchHistories.Where(fh => fh.ChartEntry.Id == entry.Id && fh.From <= from && fh.To >= to).Any());
 }
예제 #9
0
 public void AddCandles(ChartEntryEntity entry, DateTime to, Candle[] candles)
 {
     AddCandles(entry, candles.OrderBy(c => c.Time).First().Time, to, candles);
 }