public async Task GetTicksHistory() { var ticker = "YNDX"; 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,33547100"; var parsedTick = new Tick(0, 0, DateTime.Now); var cancellationToken = new CancellationToken(); ticksParserMock.Setup(x => x.ParseTick(responseString)) .Returns(parsedTick); quotesHistoryClientMock.Setup(x => x.GetTicksHistory(ticker, dateFrom, dateTo, cancellationToken)) .ReturnsAsync(responseString); var history = await quotesHistoryProvider.GetTicksHistory(ticker, dateFrom, dateTo, cancellationToken); history.Should().NotBeNull(); history.Ticks.Should().HaveCount(1); history.Ticks.First().Should().Be(parsedTick); quotesHistoryClientMock.Verify(x => x.GetTicksHistory(ticker, dateFrom, dateTo, cancellationToken), Times.Once); quotesHistoryClientMock.VerifyNoOtherCalls(); ticksParserMock.Verify(x => x.ParseTick(responseString)); ticksParserMock.VerifyNoOtherCalls(); candlesParserMock.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 ticksToShow = new ChartValues <decimal>(); seriesCollection = new SeriesCollection { new LineSeries { Values = ticksToShow, PointGeometrySize = 1, PointForeground = Brushes.Black, Foreground = Brushes.Black, }, }; var historyProvider = new FinamQuotesHistoryProvider( new FinamTicksParser(), new FinamCandlesParser(), new FinamQuotesHistoryClient( new HistoryConfiguration())); Log("Load ticks"); ticks = (await historyProvider.GetTicksHistory( "GAZP", date.Date, date.Date.AddDays(1), CancellationToken.None)).Ticks.ToList(); Log($"{ticks.Count} ticks loaded"); textBlock.Dispatcher.InvokeAsync(async() => { using var strategy = new RandomStrategy(10); strategy.Subscribe(this); for (var i = 0; i < ticks.Count; i++) { Log($"Tick {i} of {ticks.Count}"); var tick = ticks[i]; strategy.OnTick(tick); ticksToShow.Add(tick.Value); await Task.Delay(20); } var report = new Report(strategy); Log(report.ToString()); }); var ticksDates = ticks.Select(x => x.DateTime.ToString("HH:mm:ss")).ToList(); return(new LiveChartModel { SeriesCollection = seriesCollection, Labels = ticksDates, MinY = ticks.Min(x => x.Value), MaxY = ticks.Max(x => x.Value), }); }