public async Task GetCandlesHistory() { var ticker = "YNDX"; var interval = TimeInterval.Minutes30; var dateFrom = new DateTime(2020, 2, 20, 0, 0, 0); var dateTo = new DateTime(2020, 2, 21, 0, 0, 0); var responseString = "20200220,000000,232.5500000,235.7500000,232.0000000,234.6000000,33547100"; var parsedCandle = new Candle(0, 0, 0, 0, 0, DateTime.Now); var cancellationToken = new CancellationToken(); candlesParserMock.Setup(x => x.ParseCandle(responseString)) .Returns(parsedCandle); quotesHistoryClientMock.Setup(x => x.GetCandlesHistory(ticker, interval, dateFrom, dateTo, cancellationToken)) .ReturnsAsync(responseString); var history = await quotesHistoryProvider.GetCandlesHistory(ticker, interval, dateFrom, dateTo, cancellationToken); history.Should().NotBeNull(); history.Candles.Should().HaveCount(1); history.Candles.First().Should().Be(parsedCandle); quotesHistoryClientMock.Verify(x => x.GetCandlesHistory(ticker, interval, dateFrom, dateTo, cancellationToken), Times.Once); quotesHistoryClientMock.VerifyNoOtherCalls(); candlesParserMock.Verify(x => x.ParseCandle(responseString)); candlesParserMock.VerifyNoOtherCalls(); ticksParserMock.VerifyNoOtherCalls(); }
static async Task Main(string[] args) { var historyProvider = new FinamQuotesHistoryProvider( new FinamTicksParser(), new FinamCandlesParser(), new FinamQuotesHistoryClient( new HistoryConfiguration())); var ticksHistory = await historyProvider.GetTicksHistory( "GAZP", new DateTime(2020, 2, 20, 0, 0, 0), new DateTime(2020, 2, 21, 0, 0, 0), CancellationToken.None); var candlesHistory = await historyProvider.GetCandlesHistory( "GAZP", TimeInterval.Minutes15, new DateTime(2020, 2, 20, 0, 0, 0), new DateTime(2020, 2, 21, 0, 0, 0), CancellationToken.None); var sandBoxRunner = new SandBoxRunner(); var report = sandBoxRunner.RunStrategy( new List <Candle>(), new RandomStrategy(2), candlesHistory.Candles.Select(x => new Tick(value: x.CloseValue, x.Volume, x.CloseDateTime))); }
public async Task <LiveChartModel> Visualize(DateTime date) { var historyProvider = new FinamQuotesHistoryProvider( new FinamTicksParser(), new FinamCandlesParser(), new FinamQuotesHistoryClient( new HistoryConfiguration())); var candlesHistory = await historyProvider.GetCandlesHistory( "GAZP", TimeInterval.Minutes10, date.Date, date.Date.AddDays(1).AddSeconds(-1), CancellationToken.None); var candles = candlesHistory.Candles.ToList(); var sandBoxRunner = new SandBoxRunner(); var report = sandBoxRunner.RunStrategy( new List <Candle>(), new RandomStrategy(3), candles.Select(x => new Tick(value: x.CloseValue, x.Volume, x.CloseDateTime))); var candlesToShow = new ChartValues <OhlcPoint>(); candlesToShow.AddRange(candles.Select(x => new OhlcPoint((double)x.OpenValue, (double)x.HighValue, (double)x.LowValue, (double)x.CloseValue))); var lots = report.CloseLots.Select(lot => { var openPosition = candles.FindIndex(c => c.CloseDateTime == lot.OpenTime); var closePosition = candles.FindIndex(c => c.CloseDateTime == lot.CloseTime); var brush = lot is LongLot ? Brushes.Green : Brushes.Red; var pointGeometry = lot is LongLot ? Geometry.Parse("M 0 0 L 4 -4 L 8 0 Z") : Geometry.Parse("M 0 0 L 4 4 L 8 0 Z"); return(new LineSeries { Values = new ChartValues <ObservablePoint> { new ObservablePoint(openPosition, (double)lot.Open), new ObservablePoint(closePosition, (double)lot.Close), }, Fill = Brushes.Transparent, Stroke = brush, PointForeground = brush, PointGeometry = pointGeometry, PointGeometrySize = 10, }); }); var candlesDates = candlesHistory.Candles.Select(x => x.CloseDateTime.ToString("HH:mm:ss")); var seriesCollection = new SeriesCollection { new OhlcSeries() { Values = candlesToShow, LabelPoint = x => x.Close.ToString("HH:mm:ss"), IncreaseBrush = Brushes.Black, DecreaseBrush = Brushes.Black, }, }; seriesCollection.AddRange(lots); return(new LiveChartModel { SeriesCollection = seriesCollection, Labels = candlesDates, MinY = candlesHistory.Candles.Min(x => x.CloseValue), MaxY = candlesHistory.Candles.Max(x => x.CloseValue), }); }